This is a migrated thread and some comments may be shown as answers.

PdfFormatProvider with RadFixedDocument remove page increases file size

2 Answers 598 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 01 Jun 2018, 09:16 PM

Hello,

I am creating a RadFixedDocument from a byte array, and removing a single page.If I save the original byte array to a PDF document the file size is 214 KB, but the files size of the document after removing the first page is 563 KP. Any recommendations on how I can reduce the file size?

Utility.RemovePages(polDocResponse);

public static void RemovePages(PolicyDocument polDocResponse, int numPages = 1)
{
            PdfFormatProvider provider = new PdfFormatProvider();
            RadFixedDocument srcDocument = provider.Import(new MemoryStream(polDocResponse.DocumentValue));

            if (numPages >= srcDocument.Pages.Count)
                throw new ArgumentException(
                    string.Format("Utility.RemovePages: Number of pages to remove {0} is greater than or equal to the number of pages in the document {1}.",
                    numPages.ToString(), srcDocument.Pages.Count.ToString()));

            for (int i = 0; i < numPages; i++)
            {
                srcDocument.Pages.RemoveAt(i);
            }

            polDocResponse.DocumentValue = provider.Export(srcDocument);
}

2 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 02 Jun 2018, 11:49 AM

Note, that this can be simplified to just importing and exporting the document without any modifications and the file size increases from 214 KB to 574 KB.

Utility.RemovePages(polDocResponse);

public static void RemovePages(PolicyDocument polDocResponse, int numPages = 1)
{
            PdfFormatProvider provider = new PdfFormatProvider();
            RadFixedDocument srcDocument = provider.Import(new MemoryStream(polDocResponse.DocumentValue));
            polDocResponse.DocumentValue = provider.Export(srcDocument);
}

0
Tanya
Telerik team
answered on 06 Jun 2018, 03:20 PM
Hello Michael,

I replied in the support ticket but would like to update this topic as well in case someone else has the same question.

After investigating sample documents, it turned out that the original file doesn't have embedded the fonts that are used inside. After import/export with PdfProcessing, the library reads the fonts from the operating system and embeds them in the exported document, causing the bigger file size. This behavior is defined by the PDF format specification so the PDF documents can be properly rendered on any device or operating system.

We have logged a task to provide a setting allowing to skip the embedding of the fonts if the user doesn't need them. The request can be found on our public portal: Implement a setting that allows to choose if the fonts should be embedded in the document.

Regards,
Tanya
Progress Telerik

Tags
WordsProcessing
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or