diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index 6e2e7f8..db2387a 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1110,14 +1110,18 @@ poppler_page_render_to_ps (PopplerPage *page, g_return_if_fail (POPPLER_IS_PAGE (page)); g_return_if_fail (ps_file != NULL); - if (!ps_file->out) + if (!ps_file->out) { + std::vector pages; + for (int i = ps_file->first_page; i <= ps_file->last_page; ++i) { + pages.push_back(i); + } ps_file->out = new PSOutputDev (ps_file->filename, ps_file->document->doc, - NULL, - ps_file->first_page, ps_file->last_page, + NULL, pages, psModePS, (int)ps_file->paper_width, (int)ps_file->paper_height, ps_file->duplex, 0, 0, 0, 0, gFalse, gFalse); + } ps_file->document->doc->displayPage (ps_file->out, page->index + 1, 72.0, 72.0, diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 149bb62..fa99ddf 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -1074,7 +1074,7 @@ static void outputToFile(void *stream, const char *data, int len) { PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc, char *psTitle, - int firstPage, int lastPage, PSOutMode modeA, + const std::vector &pages, PSOutMode modeA, int paperWidthA, int paperHeightA, GBool noCropA, GBool duplexA, int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, @@ -1136,7 +1136,7 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc, } init(outputToFile, f, fileTypeA, psTitle, - doc, firstPage, lastPage, modeA, + doc, pages, modeA, imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA, paperWidthA, paperHeightA, noCropA, duplexA); } @@ -1144,7 +1144,7 @@ PSOutputDev::PSOutputDev(const char *fileName, PDFDoc *doc, PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA, char *psTitle, PDFDoc *doc, - int firstPage, int lastPage, PSOutMode modeA, + const std::vector &pages, PSOutMode modeA, int paperWidthA, int paperHeightA, GBool noCropA, GBool duplexA, int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, @@ -1174,7 +1174,7 @@ PSOutputDev::PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA, forceRasterize = forceRasterizeA; init(outputFuncA, outputStreamA, psGeneric, psTitle, - doc, firstPage, lastPage, modeA, + doc, pages, modeA, imgLLXA, imgLLYA, imgURXA, imgURYA, manualCtrlA, paperWidthA, paperHeightA, noCropA, duplexA); } @@ -1214,7 +1214,7 @@ static bool pageDimensionEqual(int a, int b) { void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, PSFileType fileTypeA, char *pstitle, PDFDoc *docA, - int firstPage, int lastPage, PSOutMode modeA, + const std::vector &pagesA, PSOutMode modeA, int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, GBool manualCtrlA, int paperWidthA, int paperHeightA, GBool noCropA, GBool duplexA) { @@ -1222,7 +1222,12 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, PDFRectangle *box; PSOutPaperSize *size; GooList *names; - int pg, w, h, i; + int w, h, i; + + if (pagesA.empty()) { + ok = gFalse; + return; + } // initialize displayText = gTrue; @@ -1249,9 +1254,8 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, } Page *page; paperSizes = new GooList(); - for (pg = (firstPage >= 1) ? firstPage : 1; - pg <= lastPage && pg <= catalog->getNumPages(); - ++pg) { + for (int pgi = 0; pgi < static_cast(pagesA.size()); ++pgi) { + const int pg = pagesA[pgi]; page = catalog->getPage(pg); if (page == NULL) paperMatch = gFalse; @@ -1313,8 +1317,11 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, imgURY = paperHeight; } manualCtrl = manualCtrlA; + std::vector pages; if (mode == psModeForm) { - lastPage = firstPage; + pages.push_back(pagesA[0]); + } else { + pages = pagesA; } processColors = 0; inType3Char = gFalse; @@ -1367,16 +1374,16 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, if (!manualCtrl) { Page *page; // this check is needed in case the document has zero pages - if ((page = doc->getPage(firstPage))) { - writeHeader(firstPage, lastPage, + if ((page = doc->getPage(pages[0]))) { + writeHeader(pages, page->getMediaBox(), page->getCropBox(), page->getRotate(), pstitle); } else { - error(errSyntaxError, -1, "Invalid page {0:d}", firstPage); + error(errSyntaxError, -1, "Invalid page {0:d}", pages[0]); box = new PDFRectangle(0, 0, 1, 1); - writeHeader(firstPage, lastPage, box, box, 0, pstitle); + writeHeader(pages, box, box, 0, pstitle); delete box; } if (mode != psModeForm) { @@ -1387,7 +1394,7 @@ void PSOutputDev::init(PSOutputFunc outputFuncA, void *outputStreamA, writePS("%%EndProlog\n"); writePS("%%BeginSetup\n"); } - writeDocSetup(doc, catalog, firstPage, lastPage, duplexA); + writeDocSetup(doc, catalog, pages, duplexA); if (mode != psModeForm) { writePS("%%EndSetup\n"); } @@ -1463,7 +1470,7 @@ PSOutputDev::~PSOutputDev() { } } -void PSOutputDev::writeHeader(int firstPage, int lastPage, +void PSOutputDev::writeHeader(const std::vector &pages, PDFRectangle *mediaBox, PDFRectangle *cropBox, int pageRotate, char *psTitle) { Object info, obj1; @@ -1520,7 +1527,7 @@ void PSOutputDev::writeHeader(int firstPage, int lastPage, i==0 ? "DocumentMedia:" : "+", size->name, size->w, size->h); } writePSFmt("%%BoundingBox: 0 0 {0:d} {1:d}\n", paperWidth, paperHeight); - writePSFmt("%%Pages: {0:d}\n", lastPage - firstPage + 1); + writePSFmt("%%Pages: {0:d}\n", static_cast(pages.size())); writePS("%%EndComments\n"); if (!paperMatch) { size = (PSOutPaperSize *)paperSizes->get(0); @@ -1603,7 +1610,7 @@ void PSOutputDev::writeXpdfProcset() { } void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog *catalog, - int firstPage, int lastPage, + const std::vector &pages, GBool duplexA) { Page *page; Dict *resDict; @@ -1619,8 +1626,8 @@ void PSOutputDev::writeDocSetup(PDFDoc *doc, Catalog *catalog, } else { writePS("xpdf begin\n"); } - for (pg = firstPage; pg <= lastPage; ++pg) { - page = doc->getPage(pg); + for (pg = 0; pg < static_cast(pages.size()); ++pg) { + page = doc->getPage(pages[pg]); if (!page) { error(errSyntaxError, -1, "Failed writing resources for page {0:d}", pg); continue; diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h index f30204d..3493fe3 100644 --- a/poppler/PSOutputDev.h +++ b/poppler/PSOutputDev.h @@ -93,9 +93,10 @@ class PSOutputDev: public OutputDev { public: // Open a PostScript output file, and write the prolog. + // pages has to be sorted in increasing order PSOutputDev(const char *fileName, PDFDoc *docA, char *psTitle, - int firstPage, int lastPage, PSOutMode modeA, + const std::vector &pages, PSOutMode modeA, int paperWidthA = -1, int paperHeightA = -1, GBool noCrop = gFalse, GBool duplexA = gTrue, @@ -107,10 +108,11 @@ public: void *customCodeCbkDataA = NULL); // Open a PSOutputDev that will write to a generic stream. + // pages has to be sorted in increasing order PSOutputDev(PSOutputFunc outputFuncA, void *outputStreamA, char *psTitle, PDFDoc *docA, - int firstPage, int lastPage, PSOutMode modeA, + const std::vector &pages, PSOutMode modeA, int paperWidthA = -1, int paperHeightA = -1, GBool noCrop = gFalse, GBool duplexA = gTrue, @@ -160,7 +162,7 @@ public: //----- header/trailer (used only if manualCtrl is true) // Write the document-level header. - void writeHeader(int firstPage, int lastPage, + void writeHeader(const std::vector &pages, PDFRectangle *mediaBox, PDFRectangle *cropBox, int pageRotate, char *pstitle); @@ -310,7 +312,7 @@ private: void init(PSOutputFunc outputFuncA, void *outputStreamA, PSFileType fileTypeA, char *pstitle, PDFDoc *doc, - int firstPage, int lastPage, PSOutMode modeA, + const std::vector &pages, PSOutMode modeA, int imgLLXA, int imgLLYA, int imgURXA, int imgURYA, GBool manualCtrlA, int paperWidthA, int paperHeightA, GBool noCropA, GBool duplexA); @@ -386,7 +388,7 @@ private: GooString *filterPSName(GooString *name); // Write the document-level setup. - void writeDocSetup(PDFDoc *doc, Catalog *catalog, int firstPage, int lastPage, GBool duplexA); + void writeDocSetup(PDFDoc *doc, Catalog *catalog, const std::vector &pages, GBool duplexA); void writePSChar(char c); void writePS(const char *s); diff --git a/qt4/src/poppler-ps-converter.cc b/qt4/src/poppler-ps-converter.cc index d69b345..f9d8538 100644 --- a/qt4/src/poppler-ps-converter.cc +++ b/qt4/src/poppler-ps-converter.cc @@ -216,11 +216,16 @@ bool PSConverter::convert() if (!d->title.isEmpty()) pstitlechar = pstitle8Bit.data(); else pstitlechar = 0; + std::vector pages; + foreach(int page, d->pageList) + { + pages.push_back(page); + } + PSOutputDev *psOut = new PSOutputDev(outputToQIODevice, dev, pstitlechar, d->document->doc, - 1, - d->document->doc->getNumPages(), + pages, (d->opts & PrintToEPS) ? psModeEPS : psModePS, d->paperWidth, d->paperHeight, diff --git a/qt5/src/poppler-ps-converter.cc b/qt5/src/poppler-ps-converter.cc index 0e81b70..41f85a1 100644 --- a/qt5/src/poppler-ps-converter.cc +++ b/qt5/src/poppler-ps-converter.cc @@ -216,11 +216,16 @@ bool PSConverter::convert() if (!d->title.isEmpty()) pstitlechar = pstitle8Bit.data(); else pstitlechar = 0; + std::vector pages; + foreach(int page, d->pageList) + { + pages.push_back(page); + } + PSOutputDev *psOut = new PSOutputDev(outputToQIODevice, dev, pstitlechar, d->document->doc, - 1, - d->document->doc->getNumPages(), + pages, (d->opts & PrintToEPS) ? psModeEPS : psModePS, d->paperWidth, d->paperHeight, diff --git a/utils/pdftops.cc b/utils/pdftops.cc index babebed..5104c31 100644 --- a/utils/pdftops.cc +++ b/utils/pdftops.cc @@ -206,6 +206,7 @@ int main(int argc, char *argv[]) { GBool ok; char *p; int exitCode; + std::vector pages; exitCode = 99; @@ -400,16 +401,22 @@ int main(int argc, char *argv[]) { goto err2; } + for (int i = firstPage; i <= lastPage; ++i) { + pages.push_back(i); + } + // write PostScript file psOut = new PSOutputDev(psFileName->getCString(), doc, - NULL, firstPage, lastPage, mode, + NULL, pages, mode, paperWidth, paperHeight, noCrop, duplex); if (psOut->isOk()) { - doc->displayPages(psOut, firstPage, lastPage, 72, 72, - 0, noCrop, !noCrop, gTrue); + for (int i = firstPage; i <= lastPage; ++i) { + doc->displayPage(psOut, i, 72, 72, + 0, noCrop, !noCrop, gTrue); + } } else { delete psOut; exitCode = 2;