consolidate the fonts between merges pdfs itextsharp C#

北战南征 提交于 2019-12-02 11:43:04

问题


I need to merge multiple pdfs together. I am using itextsharp to create all the pdfs. I need to reduce the size of the pdfs to the lowest possible size. I know the fonts are being duplicated for each pdf. Is there to use only one set of fonts throughout the merged pdf? For example, pdf1 is 2.8mb and pdf2 is 2.8 mb I merge them together and its about 5.7mb. I know for a fact that both of those pdfs are using the same font but the data for the font is being duclpicated even though its in the same pdf.

I tried using setting the compression properties to best compression and set full compression and that barely reduced the size.

Though when i ran the pdf through Acrobat X pro and optimize its reduce almost 90%+ from like 160 mb to 5 mb. The usage audit says its 90% of the pdf is fonts before optimizing.

Now is there a way to consolidate the fonts between merges pdfs ?


回答1:


My answer consists of two parts:

  1. You're not telling us how you're merging the PDFs. Let's hope you've read the official documentation and that you're using PdfSmartCopy. If not, you're doing it wrong. PdfSmartCopy examines the content of the different PDFs and reuses possibly redundant objects (such as reused images, XObjects, fonts). Note that there were some bugs in earlier versions of PdfSmartCopy so please make sure you're using the latest version.
  2. If the different PDFs use different subsets of the same font, you're out of luck. iText doesn't merge font subsets. Merging different font subsets would involve rewriting content streams, creating new fonts if we're talking about simple font sets that require more than 256 characters if the subsets are merged, etc...



回答2:


You could rename subsets.

As if you had

Helvetica (subset)

and

Helvetica (subset)

you would create

Helvetica-1 (subset)

and

Helvetiva-2 (subset)

once they were different implementations (binary stream compare)



来源:https://stackoverflow.com/questions/20690049/consolidate-the-fonts-between-merges-pdfs-itextsharp-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!