111
111
#include <fpdf_edit.h>
112
112
#include <fpdf_formfill.h>
113
113
114
+ #define TILE_SIZE (4000)
115
+
114
116
typedef struct _VipsForeignLoadPdf {
115
117
VipsForeignLoad parent_object ;
116
118
@@ -331,8 +333,7 @@ vips_foreign_load_pdf_build(VipsObject *object)
331
333
static VipsForeignFlags
332
334
vips_foreign_load_pdf_get_flags_filename (const char * filename )
333
335
{
334
- /* We can't render any part of the page on demand, but we can render
335
- * separate pages. Might as well call ourselves partial.
336
+ /* We can render any part of the page on demand.
336
337
*/
337
338
return VIPS_FOREIGN_PARTIAL ;
338
339
}
@@ -401,9 +402,9 @@ vips_foreign_load_pdf_set_image(VipsForeignLoadPdf *pdf, VipsImage *out)
401
402
printf ("vips_foreign_load_pdf_set_image: %p\n" , pdf );
402
403
#endif /*DEBUG*/
403
404
404
- /* We render to a linecache , so fat strips work well .
405
+ /* We render to a tilecache , so it has to be SMALLTILE .
405
406
*/
406
- if (vips_image_pipelinev (out , VIPS_DEMAND_STYLE_FATSTRIP , NULL ))
407
+ if (vips_image_pipelinev (out , VIPS_DEMAND_STYLE_SMALLTILE , NULL ))
407
408
return -1 ;
408
409
409
410
/* Extract and attach metadata. Set the old name too for compat.
@@ -579,6 +580,11 @@ vips_foreign_load_pdf_generate(VipsRegion *out_region,
579
580
if (VIPS_RECT_BOTTOM (& pdf -> pages [i ]) > r -> top )
580
581
break ;
581
582
583
+ /* Reset out region. Otherwise there might be parts of previous pages
584
+ * left.
585
+ */
586
+ vips_region_black (or );
587
+
582
588
top = r -> top ;
583
589
while (top < VIPS_RECT_BOTTOM (r )) {
584
590
VipsRect rect ;
@@ -607,7 +613,9 @@ vips_foreign_load_pdf_generate(VipsRegion *out_region,
607
613
}
608
614
609
615
FPDF_RenderPageBitmap (bitmap , pdf -> page ,
610
- 0 , 0 , rect .width , rect .height ,
616
+ pdf -> pages [i ].left - rect .left ,
617
+ pdf -> pages [i ].top - rect .top ,
618
+ pdf -> pages [i ].width , pdf -> pages [i ].height ,
611
619
0 , 0 );
612
620
613
621
FPDF_FFLDraw (pdf -> form , bitmap , pdf -> page ,
@@ -653,20 +661,15 @@ vips_foreign_load_pdf_load(VipsForeignLoad *load)
653
661
G_CALLBACK (vips_foreign_load_pdf_minimise ), pdf );
654
662
655
663
vips_foreign_load_pdf_set_image (pdf , t [0 ]);
656
- if (vips_image_generate (t [0 ],
657
- NULL , vips_foreign_load_pdf_generate , NULL , pdf , NULL ))
658
- return -1 ;
659
664
660
- /* PDFium does not like rendering parts of pages :-( always render
661
- * complete pages.
662
- */
663
- if (vips_tilecache (t [0 ], & t [1 ],
664
- "tile_width" , pdf -> pages [0 ].width ,
665
- "tile_height" , pdf -> pages [0 ].height ,
666
- "max_tiles" , 1 ,
667
- NULL ))
668
- return -1 ;
669
- if (vips_image_write (t [1 ], load -> real ))
665
+ if (vips_image_generate (t [0 ],
666
+ NULL , vips_foreign_load_pdf_generate , NULL , pdf , NULL ) ||
667
+ vips_tilecache (t [0 ], & t [1 ],
668
+ "tile_width" , TILE_SIZE ,
669
+ "tile_height" , TILE_SIZE ,
670
+ "max_tiles" , 2 * (1 + t [0 ]-> Xsize / TILE_SIZE ),
671
+ NULL ) ||
672
+ vips_image_write (t [1 ], load -> real ))
670
673
return -1 ;
671
674
672
675
return 0 ;
@@ -676,7 +679,7 @@ static void *
676
679
vips_foreign_load_pdf_once_init (void * client )
677
680
{
678
681
/* We must make the mutex on class init (not _build) since we
679
- * can lock ebven if build is not called.
682
+ * can lock even if build is not called.
680
683
*/
681
684
vips_pdfium_mutex = vips_g_mutex_new ();
682
685
0 commit comments