0

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.

Ruddy
  • 9,795
  • 5
  • 45
  • 66

1 Answers1

2

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.

  • I just tried it as a JPEG and still the same results. How do I go about your second option? If you could expand on it that would be great. – Ruddy Nov 14 '13 at 08:04
  • Ignore my last, you are correct. I just had the wrong image linked when I tested. A JPEG does solve the problem. Thank you! – Ruddy Nov 14 '13 at 08:07
  • I tested that theory with a 2 page document containing nothing but a small image in the page header and a few plain text paragraphs all in one font, and it took 5 seconds to render regardless of the image format, even though JPG version was 3x smaller than PNG. Still too slow. – ajeh Jul 26 '16 at 14:23
  • @ajeh The original question was about large images, you tested with a small image. Does not prove the theory wrong - especially since it helped Ruddy. Maybe you should start a new question and include an MCVE. – I liked the old Stack Overflow Jul 26 '16 at 14:43