26size_t RenderPDFBitmaps(
const void* pBuffer,
int nSize, std::vector<BitmapEx>& rBitmaps,
36 std::unique_ptr<vcl::pdf::PDFiumDocument> pPdfDocument
37 = pPdfium->openDocument(pBuffer, nSize, OString());
43 const int nPageCount = pPdfDocument->getPageCount();
46 const size_t nLastPage = std::min<int>(nPageCount, nFirstPage + nPages) - 1;
47 for (
size_t nPageIndex = nFirstPage; nPageIndex <= nLastPage; ++nPageIndex)
50 std::unique_ptr<vcl::pdf::PDFiumPage> pPdfPage = pPdfDocument->openPage(nPageIndex);
55 double nPageWidthPoints = pPdfPage->getWidth();
56 double nPageHeightPoints = pPdfPage->getHeight();
57 if (pSizeHint && pSizeHint->
getX() && pSizeHint->
getY())
72 std::unique_ptr<vcl::pdf::PDFiumBitmap> pPdfBitmap
73 = pPdfium->createBitmap(nPageWidth, nPageHeight, 1);
77 bool bTransparent = pPdfPage->hasTransparency();
84 const sal_uInt32 nColor = bTransparent ? 0x00000000 : 0xFFFFFFFF;
85 pPdfBitmap->fillRect(0, 0, nPageWidth, nPageHeight, nColor);
86 pPdfBitmap->renderPageBitmap(pPdfDocument.get(), pPdfPage.get(), 0,
87 0, nPageWidth, nPageHeight);
96 const int nStride = pPdfBitmap->getStride();
97 std::vector<sal_uInt8> aScanlineAlpha(nPageWidth);
98 for (
int nRow = 0; nRow < nPageHeight; ++nRow)
103 for (
int nCol = 0; nCol < nPageWidth; ++nCol)
105 aScanlineAlpha[nCol] = pPdfLine[3];
115 rBitmaps.emplace_back(aBitmap, aMask);
119 rBitmaps.emplace_back(std::move(aBitmap));
123 return rBitmaps.size();
127 std::shared_ptr<VectorGraphicData>& rVectorGraphicData)
132 SAL_WARN(
"vcl.filter",
"ImportPDF: empty PDF data array");
144 std::shared_ptr<VectorGraphicData> pVectorGraphicData;
147 rGraphic =
Graphic(pVectorGraphicData);
161std::vector<PDFGraphicAnnotation>
162findAnnotations(
const std::unique_ptr<vcl::pdf::PDFiumPage>& pPage,
basegfx::B2DSize aPageSize)
164 std::vector<PDFGraphicAnnotation> aPDFGraphicAnnotations;
167 return aPDFGraphicAnnotations;
170 for (
int nAnnotation = 0; nAnnotation < pPage->getAnnotationCount(); nAnnotation++)
172 auto pAnnotation = pPage->getAnnotation(nAnnotation);
175 auto eSubtype = pAnnotation->getSubType();
196 OUString sDateTimeString
200 css::util::DateTime aDateTime;
201 if (!sISO8601String.isEmpty())
206 Color aColor = pAnnotation->getColor();
208 aPDFGraphicAnnotations.emplace_back();
210 auto& rPDFGraphicAnnotation = aPDFGraphicAnnotations.back();
211 rPDFGraphicAnnotation.maRectangle = rRectangleHMM;
212 rPDFGraphicAnnotation.maAuthor = sAuthor;
213 rPDFGraphicAnnotation.maText = sText;
214 rPDFGraphicAnnotation.maDateTime = aDateTime;
215 rPDFGraphicAnnotation.meSubType = eSubtype;
216 rPDFGraphicAnnotation.maColor = aColor;
220 auto const& rVertices = pAnnotation->getVertices();
221 if (!rVertices.empty())
223 auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerPolygon>();
224 rPDFGraphicAnnotation.mpMarker = pMarker;
225 for (
auto const& rVertex : rVertices)
227 auto aPoint = convertFromPDFInternalToHMM(rVertex, aPageSize);
228 pMarker->maPolygon.append(aPoint);
230 pMarker->maPolygon.setClosed(
true);
233 pMarker->maFillColor = pAnnotation->getInteriorColor();
238 auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerSquare>();
239 rPDFGraphicAnnotation.mpMarker = pMarker;
242 pMarker->maFillColor = pAnnotation->getInteriorColor();
246 auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerCircle>();
247 rPDFGraphicAnnotation.mpMarker = pMarker;
250 pMarker->maFillColor = pAnnotation->getInteriorColor();
254 auto const& rStrokesList = pAnnotation->getInkStrokes();
255 if (!rStrokesList.empty())
257 auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerInk>();
258 rPDFGraphicAnnotation.mpMarker = pMarker;
259 for (
auto const& rStrokes : rStrokesList)
262 for (
auto const& rVertex : rStrokes)
264 auto aPoint = convertFromPDFInternalToHMM(rVertex, aPageSize);
267 pMarker->maStrokes.push_back(aPolygon);
269 float fWidth = pAnnotation->getBorderWidth();
272 pMarker->maFillColor = pAnnotation->getInteriorColor();
277 size_t nCount = pAnnotation->getAttachmentPointsCount();
280 auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerHighlight>(
282 rPDFGraphicAnnotation.mpMarker = pMarker;
285 auto aAttachmentPoints = pAnnotation->getAttachmentPoints(i);
286 if (!aAttachmentPoints.empty())
292 = convertFromPDFInternalToHMM(aAttachmentPoints[0], aPageSize);
295 = convertFromPDFInternalToHMM(aAttachmentPoints[1], aPageSize);
298 = convertFromPDFInternalToHMM(aAttachmentPoints[3], aPageSize);
301 = convertFromPDFInternalToHMM(aAttachmentPoints[2], aPageSize);
304 pMarker->maQuads.push_back(aPolygon);
311 auto const& rLineGeometry = pAnnotation->getLineGeometry();
312 if (!rLineGeometry.empty())
314 auto pMarker = std::make_shared<vcl::pdf::PDFAnnotationMarkerLine>();
315 rPDFGraphicAnnotation.mpMarker = pMarker;
317 auto aPoint1 = convertFromPDFInternalToHMM(rLineGeometry[0], aPageSize);
318 pMarker->maLineStart = aPoint1;
320 auto aPoint2 = convertFromPDFInternalToHMM(rLineGeometry[1], aPageSize);
321 pMarker->maLineEnd = aPoint2;
323 float fWidth = pAnnotation->getBorderWidth();
330 return aPDFGraphicAnnotations;
337 std::unique_ptr<SvStream>
xStream(
356 = pPdfium->openDocument(pGfxLink->GetData(), pGfxLink->GetDataSize(), OString());
361 const int nPageCount = pPdfDocument->getPageCount();
365 for (
int nPageIndex = 0; nPageIndex < nPageCount; ++nPageIndex)
373 constexpr double pointToTwipconversionRatio = 20;
383 Graphic aGraphic(pGfxLink, nPageIndex);
385 auto pPage = pPdfDocument->openPage(nPageIndex);
387 std::vector<PDFGraphicAnnotation> aPDFGraphicAnnotations
388 = findAnnotations(pPage, aPageSize);
390 rGraphics.emplace_back(std::move(aGraphic),
Size(nPageWidth, nPageHeight),
391 aPDFGraphicAnnotations);
394 return rGraphics.size();
const sal_uInt8 * ConstScanline
constexpr auto convertPointToMm100(N n)
constexpr auto convertTwipToMm100(N n)
Container for the binary data, whose responsibility is to manage the make it as simple as possible to...
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
void setClosed(bool bNew)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
This template handles BitmapAccess the RAII way.
#define SAL_WARN(area, stream)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
bool ISO8601parseDateTime(std::u16string_view rString, css::util::DateTime &rDateTime)
double getDefaultPdfResolutionDpi()
Get the default PDF rendering resolution in DPI.
double pointToPixel(const double fPoint, const double fResolutionDPI)
Convert to inch, then assume 96 DPI.
BinaryDataContainer createBinaryDataContainer(SvStream &rStream)
constexpr OStringLiteral constDictionaryKeyInteriorColor
constexpr OStringLiteral constDictionaryKeyTitle
constexpr OStringLiteral constDictionaryKeyContents
constexpr OStringLiteral constDictionaryKeyModificationDate
OUString convertPdfDateToISO8601(std::u16string_view rInput)
size_t RenderPDFBitmaps(const void *pBuffer, int nSize, std::vector< BitmapEx > &rBitmaps, const size_t nFirstPage, int nPages, const basegfx::B2DTuple *pSizeHint)
Fills the rBitmaps vector with rendered pages.
bool ImportPDF(SvStream &rStream, Graphic &rGraphic)
Imports a PDF stream into rGraphic.
bool importPdfVectorGraphicData(SvStream &rStream, std::shared_ptr< VectorGraphicData > &rVectorGraphicData)
Imports a PDF stream as a VectorGraphicData.
constexpr int PDF_INSERT_MAGIC_SCALE_FACTOR
size_t ImportPDFUnloaded(const OUString &rURL, std::vector< PDFGraphicResult > &rGraphics)
Import PDF as Graphic images (1 per page), but not loaded yet.
static std::shared_ptr< PDFium > & get()