Drawing large PDF pages is slow, inefficient, and fails

75 views
Skip to first unread message

吴吴

unread,
Jul 23, 2025, 12:04:18 PMJul 23
to pdfium
I think an API is needed to solve the problem of rendering large PDF pages. That is, you can specify the rendering area within the PDF page and draw it to a DC or hbitmap of a specified size. This can solve the problem of slow drawing of large pages by Pdfium, and you can draw PDF pages of any magnification in the program without any lag.

geisserml

unread,
Jul 24, 2025, 3:15:24 PMJul 24
to pdfium
Rendering only a specific sub-area of a page is already possible with the existing APIs.
The idea is basically to shift start_x/start_y into negatives and use a smaller bitmap.[^1]
size_x/size_y stay the non-cropped, scaled size (if you change these, I believe the rendering would be squashed or stretched).

This way, you should be able to avoid the need to create an extremely large bitmap that you mentioned in https://groups.google.com/g/pdfium/c/Bq488Mht6l8
By the way, please don't create multiple mailing list threads for the same topic, as this causes confusion for future readers.

[^1]: For an example, see e.g. how pypdfium2's higher-level rendering helper implements the `crop` parameter: https://github.com/pypdfium2-team/pypdfium2/blob/a40e02019517eb03b30bf7774fa21bec4aee9e17/src/pypdfium2/_helpers/page.py#L447-L482

吴吴

unread,
Jul 25, 2025, 10:24:46 AMJul 25
to pdfium

This is not what I want. What I want is to crop the area of this page and display it in the hbitmap. For example, the left: 200, top: 400, right: 400, bottom: 200 in the cropped page is displayed in the area left: 0 right: 600, bottom: 0, top: 600.

geisserml

unread,
Jul 25, 2025, 2:32:16 PMJul 25
to pdfium
I'm not sure I understand correctly, but it sounds to me as though you don't just want to render a sub-section of the page, but also draw it only onto a specific sub-rectangle of the bitmap?
Indeed, I suppose that's not possible with FPDF_RenderPage() or FPDF_RenderPageBitmap() directly.
A workaround might be to temporarily change the page cropbox using FPDFPage_SetCropBox() from fpdf_transformpage.h, which is taken into account on rendering.
Then you can use a larger bitmap and shift start_x/start_y inward for left/top margins.
There's also FPDF_RenderPageBitmapWithMatrix() which takes a `clipping` rectangle, but it seems that you want to use Windows GDI, whereas this API is for FPDF_BITMAP.
(Though, I seem to remember reading that pdfium's GDI renderer might be deprecated eventually?)
Reply all
Reply to author
Forward
0 new messages