Question

I am creating a PDF using MigraDoc and have now ran into a little problem. I am using a A4 size image (2480px x 3508px / 96KB in size) as a background for my PDF using the following code:

Dim frame = Section.Headers.FirstPage.AddTextFrame
frame.AddImage("background.png")
frame.WrapFormat.Style = WrapStyle.Through
frame.RelativeHorizontal = RelativeHorizontal.Page

Using this causes the PDF to render around 10 times longer (say 10 seconds) then without or a smaller sized file (say 1 second). Is there anyway to speed this up?

I have tried to not use a frame thinking this could be the problem displaying the image using:

Dim backing As Image = Section.Headers.FirstPage.AddImage("background.png")

But still the same results, the reason I want time cut down is I create up to 1000 of these and this can take a long time at the current speed.

I cant downsize the image any more but I don't see why it should be a problem with the size. If this is the problem and there is no way around it please do let me know.

Was it helpful?

Solution

Maybe it goes faster when you use a JPEG file (if that is an option).

JPEG files are copied into the PDF as they are. PNGs and other formats have to be converted into "PDF images".

You can use pages from PDF files just like images. This is another option you can try: once create a PDF with your background image, and create all other files with that PDF instead of the PNG (if JPEG is not appropriate for your image).

There are two builds of MigraDoc: one using GDI+, one using WPF. You could try both to see if that makes a difference.

BTW: Images can be positioned like TextFrames, so there is no need to put an Image into a TextFrame.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top