PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Merge PDFs sharing common image resource to reduce file size
http://forum.pdfsharp.com/viewtopic.php?f=2&t=4446
Page 1 of 1

Author:  zarberry27 [ Mon May 29, 2023 4:41 am ]
Post subject:  Merge PDFs sharing common image resource to reduce file size

Hi guys,

I'm using PDFSharp (in a C# .NET4.8 program) to merge several invoice PDFs into one, however the merged file size is largely proportional to the number of PDFs.

The reason is because each page on a PDF has the same company logo (JPEG), which is referenced for each PDF being merged in.

e.g. if image is 60KB, then merging:
2 PDFs will be around 125KB (2x 60KB company logos + 5KB other data)
3 PDFs will be around 190KB (3x 60KB company logos + 10KB other data)
..etc.

My question is how would I go about reusing one of the referenced company logos (e.g. within first PDF), and then removing/replacing the referenced image in subsequent PDFs being merged in?

I've played around with creating a 'shared resource' dictionary; Looping through pdf->pages->"/Resources"->"/XObject", and then trying to use .SetReference on the DictionaryElements, but is not working as expected.

Looking forward to hearing back.

Regards

Attachments:
File comment: PDF structure. One /XObject image per page.
Screenshot 2023-05-29 170530.png
Screenshot 2023-05-29 170530.png [ 112.91 KiB | Viewed 23405 times ]

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