Welcome Guest Search | Active Topics | Sign In | Register

Setting background image on every page Options
vlado
Posted: Friday, March 20, 2015 11:03:36 AM
Rank: Newbie
Groups: Member

Joined: 3/20/2015
Posts: 4
Hi,

I am converting big HTML files into PDF. On every page I am rendering an image:

Code: C#
....
EO.Pdf.HtmlToPdf.Options.PreserveHighResImages = false;
EO.Pdf.HtmlToPdf.Options.SaveImageAsJpeg = true;
EO.Pdf.HtmlToPdf.Options.JpegQualityLevel = 1;
EO.Pdf.HtmlToPdf.Options.BeforeRenderPage = new EO.Pdf.PdfPageEventHandler(On_BeforeRenderPage);
private void On_BeforeRenderPage_cover(object sender, EO.Pdf.PdfPageEventArgs e){
...
                MemoryStream ms = new MemoryStream(info.cover_image);            
                Image i = Image.FromStream(ms);
                EO.Pdf.Acm.AcmImage image = new EO.Pdf.Acm.AcmImage(i);
                render.Render(image);
...
}


The image its around 60KB. Rendering the image on every page makes the document big, and also the conversion slow.

Is it possible to set somehow the picture to be reused among the pages, instead of rendering the image on every page?

Thank you
Vlado


eo_support
Posted: Saturday, March 21, 2015 11:24:58 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

Unfortunately there is no way to do that in the current version. This is an interesting idea so we will look into it and see if we can do the optimization automatically on our end.

Thanks!
vlado
Posted: Monday, March 23, 2015 5:39:10 AM
Rank: Newbie
Groups: Member

Joined: 3/20/2015
Posts: 4
Thank you for the response.

But at least how can we reduce the size of the image. I need to render the image on the entire page (A4 format), and the only way
to do this is to use an image with 32bit depth and size of 817x1056 pixels.
Because of this we can not reduce the size of the image and the documents are big.

I wonder what will happen if I first create the pdf without image background, and then using the Adcrobat, I add an background image on all the pages.
The size of the PDF documents will increase for NUM_PAGES x SIZE_OF_IMAGE, or just SIZE_OF_IMAGE?

Thanks
eo_support
Posted: Monday, March 23, 2015 10:47:02 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

Technically it is perfectly doable to only include one copy of the image in the file and then reference to that image on every page. So yes, Acrobat might be able to do that for you without increasing the file size significantly. However you might want to consider adding the image to the pages BEFORE using our library to render the "normal" output. The reason is a PDF page is like a canvas, you can easily paint over existing contents, but it is much more complicated, and sometimes it is even impossible to paint below the existing contents.

In order to add the image before rendering content, you can follow these steps:

1. Use other tools to create a blank PDF file with sufficient number of pages (for example, if your main content can be up to 10 pages, you can create a blank PDF file with 20 pages);
2. Add the background image to each page with other tools/APIs. Ensure that they only create one copy of the image data in the file;
3. Use PdfDocument to load this file;
4. Use AcmRender to render your output to the PdfDocument object;
5. Use the last AcmContent's CreateDestination method to get a PdfDestination object corresponding to the last AcmContent object;
6. Use the PdfDestination.Page.Index to find out the last page index (zero based);
7. Use PdfDocument.Split method to trim off the extra blank pages;

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
vlado
Posted: Wednesday, March 25, 2015 6:57:22 AM
Rank: Newbie
Groups: Member

Joined: 3/20/2015
Posts: 4
Hi, thank you for the suggestion. I managed to decrease the size of the document.

However, the generation time its still big.
The conversion from HTMl to PDF takes:
- 60 seconds only the first time
- 15 seconds for the following conversions

The document is 250 pages. I dont use external styles and resources.
And I don't use delegate methods (like BeforeRenderPage ) to render images on the document.

Can you give me some suggestions to speed up the conversion?

Thank you
eo_support
Posted: Wednesday, March 25, 2015 9:43:10 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

It's normal that it takes 10 to 15 minutes for a PDF file as big as 250 pages. You can try to set HtmlToPdf.Options.RetrieveNodeText to false and see if it helps:

http://www.essentialobjects.com/doc/4/eo.pdf.htmltopdfoptions.retrievenodetext.aspx

The first run is always much slower than following conversions because the engine has to initialize.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.