When I call fz_run_page() MuPDF only draws the actual PDF objects onto the pixmap

(e.g. text, images, vector graphics, etc.).

It does not draw the page bounding box and fill it with a static color (e.g. white). Is there a way to have MuPDF draw the page background as well?

I know that I could use fz_clear_pixmap_with_value() to manually set the background to a static color before I call fz_run_page(). But this solution gets problematic as soon as rotation comes into play because then there will be empty unused spaces at the borders of the rotated PDF page. So it would be very helpful if there was a possibility to have MuPDF draw the page's bounding box first, fill its background to a static color, and then draw the PDF objects like text etc. on it.

Is this possible somehow?

Thanks!

有帮助吗?

解决方案

Just in case somebody has the same problem. The solution is to simply to clear the pixmap and then draw the white background yourself before calling fz_run_page(). E.g. like this:

dev = fz_new_draw_device(ctx, pixmap);
path = fz_new_path(ctx);
fz_moveto(ctx, path, 0, 0);
fz_lineto(ctx, path, 0, height);
fz_lineto(ctx, path, width, height);
fz_lineto(ctx, path, width, 0);
fz_closepath(ctx, path);
fz_fill_path(dev, path, 0, ctm, fz_device_gray, &constant_0, 1.0f);
fz_free_path(ctx, path);
fz_run_page(doc, page, dev, ctm, &cookie);
fz_free_device(dev);

It is important to use the results from fz_bound_page() for "width" and "height" because they contain the real, unrounded dimensions of the page.

If you do not use a transformation matrix, you can also just prefill the pixmap with 0xff.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top