PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Nov 25, 2020 2:58 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Oct 17, 2020 8:54 am 
Offline

Joined: Sat Oct 17, 2020 8:41 am
Posts: 2
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 19, 2020 8:58 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 592
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 19, 2020 10:08 am 
Offline

Joined: Sat Oct 17, 2020 8:41 am
Posts: 2
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group