PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

help with high memory consumption
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4190
Page 1 of 1

Author:  Jupklass2 [ Sat Oct 17, 2020 8:54 am ]
Post subject:  help with high memory consumption

HI
I had develop this free tool for help people to easy layout boardgame cards

I works great but "the problem" is that it can be very high memory consuming when working with a lot of images and, for example, it can goes up to 2.5Gb or RAM
there is a easy way to fix that is that each time a page is done save it as one pdf file and when all pdf files are done marge it. doing that it goes up to 200Mb of RAM

right now the way i put the images on to the pdf file is
Code:
 gfx.DrawImage(XImagen,x_position, y_position,x_size,y_size);


I´m trying to solve this and i have been reading that, for example, with one image that is multiple times on the PDF you can insert it only and then refer it over the document but i can not find any post here on how to do it

I have see that DrawImage creates the reference on the Page Dictionary but I can´t get to create instead on de Document Dictionary instead so i can call it form other pages and using
Code:
Document.Internals.AddObject(xObject);

gaves me the error that the xobject is already ther (true)

Any suggention where i can read help about this or documentation?

thank you so much

Author:  TH-Soft [ Mon Oct 19, 2020 8:58 am ]
Post subject:  Re: help with high memory consumption

Hi!

When you create an XImage object and draw it on multiple pages then the image data will be included only once in the PDF.
When creating the PDF page by page, images used on multiple pages will be included multiple times.

Maybe you can shrink the images before creating XImage object to reduce the memory impact. You do not need 20 megapixel for images that only show in thumbnail size.

A possible approach: Create all pages at first, then add one image on all pages and save. Open again, add the next image on all pages and save. And so on...
It should be OK to save after a few images (5 or 10 or maybe even more). The code will be a bit more complicated.

Author:  Jupklass2 [ Mon Oct 19, 2020 10:08 am ]
Post subject:  Re: help with high memory consumption

TH-Soft wrote:
Hi!

When you create an XImage object and draw it on multiple pages then the image data will be included only once in the PDF.
When creating the PDF page by page, images used on multiple pages will be included multiple times.

Maybe you can shrink the images before creating XImage object to reduce the memory impact. You do not need 20 megapixel for images that only show in thumbnail size.

A possible approach: Create all pages at first, then add one image on all pages and save. Open again, add the next image on all pages and save. And so on...
It should be OK to save after a few images (5 or 10 or maybe even more). The code will be a bit more complicated.


Thanks i will check it...
the problem is that an averge project has arround 600 images... so add 600 images on all pages...
i will try to include all images at the start, save, and somehow later add them on the pages...
I will let you know

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/