diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx index a309173da96f..138bb8495a55 100644 --- a/vcl/source/filter/ipdf/pdfread.cxx +++ b/vcl/source/filter/ipdf/pdfread.cxx @@ -425,37 +425,47 @@ ImportPDFUnloaded(SvStream& rStream, std::vector& rGraphics, if (nPageCount <= 0) return 0; + // A page pdfium cannot read still gets an entry, so the result keeps one page per page the + // pdf declares and every entry knows its own page number. Such a page takes the size of the + // last page that did come through, starting at A4 in 1/100 mm. + Size aLastGoodSize(21000, 29700); + for (int nPageIndex = 0; nPageIndex < nPageCount; ++nPageIndex) { - basegfx::B2DSize aPageSize = pPdfDocument->getPageSize(nPageIndex); - if (aPageSize.getWidth() <= 0.0 || aPageSize.getHeight() <= 0.0) - continue; - // Returned unit is points + basegfx::B2DSize aPageSize = pPdfDocument->getPageSize(nPageIndex); + + std::unique_ptr pPage; + if (aPageSize.getWidth() > 0.0 && aPageSize.getHeight() > 0.0) + pPage = pPdfDocument->openPage(nPageIndex); + + if (!pPage) + { + SAL_WARN("vcl.filter", + "ImportPDF: page " << nPageIndex << " is unreadable, importing it blank"); + rGraphics.emplace_back(Graphic(pGfxLink, nPageIndex), aLastGoodSize, + std::vector(), + std::vector>()); + continue; + } tools::Long nPageWidth = std::round(convertPointToMm100(aPageSize.getWidth())); tools::Long nPageHeight = std::round(convertPointToMm100(aPageSize.getHeight())); + aLastGoodSize = Size(nPageWidth, nPageHeight); // Create the Graphic with the VectorGraphicDataPtr and link the original PDF stream. // We swap out this Graphic as soon as possible, and a later swap in // actually renders the correct Bitmap on demand. Graphic aGraphic(pGfxLink, nPageIndex); - auto pPage = pPdfDocument->openPage(nPageIndex); - if (!pPage) - { - SAL_WARN("vcl.filter", "ImportPDF: unable to open page: " << nPageIndex); - continue; - } - std::vector aPDFGraphicAnnotations = findAnnotations(pPage, aPageSize); std::vector> aPDFLinksInfo = findLinks(pPage, pPdfDocument, aPageSize); - rGraphics.emplace_back(std::move(aGraphic), Size(nPageWidth, nPageHeight), - aPDFGraphicAnnotations, aPDFLinksInfo); + rGraphics.emplace_back(std::move(aGraphic), aLastGoodSize, aPDFGraphicAnnotations, + aPDFLinksInfo); } return rGraphics.size();