Quantcast
Channel: Aspose.Pdf Product Family
Viewing all articles
Browse latest Browse all 3131

Optimize Fonts when concatenating pdfs

$
0
0
Dear ladies and gentlemen,

In our application we have to combine several (eg 100) PDF files.
To optimize the resulting file we use this code:

pdfFileEditor.Concatenate(pdfStreams.ToArray(), packPdf);

packPdf.Seek(0, SeekOrigin.Begin);
var pdfDocument = new Document(packPdf);
foreach (Page page in pdfDocument.Pages)
{
var idx = 1;
foreach (XImage image in page.Resources.Images)
{
using (var imageStream = new MemoryStream())
{
image.Save(imageStream, ImageFormat.Jpeg);
imageStream.Seek(0, SeekOrigin.Begin);
page.Resources.Images.Replace(idx, imageStream);
}
idx = idx + 1;
}
}

// optimize the file size
pdfDocument.Optimize();
pdfDocument.OptimizeSize = true;
pdfDocument.OptimizeResources(new Document.OptimizationOptions
{
RemoveUnusedStreams = true,
RemoveUnusedObjects = true,
LinkDuplcateStreams = true
});
// save updated File
pdfDocument.Save(newPdfFileName);


After this optimization the size of the created pdf file is still too large. The cause of this is due to the fonts used in the source files.
The font definitions (/font-Dictionary and dependent objects) were taken for each original document into the target file.
If the /FileFonts2 streams are identical, only one stream was saved. If the streams are not identical, no union set of all required characters was formed.
The difference in file size, with an average size of the streams of 18.5 KB, is about 3 MB.

Is there a way to summarize the fonts efficiently?
Is such an implementation planed?

Best regards

Kind Regards,
Oliver

Viewing all articles
Browse latest Browse all 3131

Trending Articles