Size of PDF document

7 posts, 0 answers
  1. Neven
    Neven avatar
    10 posts
    Member since:
    Jul 2013

    Posted 24 Feb Link to this post

    My company decided to move from Infragistics to Telerik .

    For PDF development I am using Telerik.Windows.Documents.Flow.FormatProviders.Pdf and Telerik.Windows.Documents.Flow.Model.RadFlowDocument to create PDF.PDF is complex with tables/images etc but I did not have any issue there.Everything was as in Telerik online spec.

    Now I have different issue that was almost stopover for me.PDF that I got with Telerik is 10 times bigger in size then with Infragistics.
    Example bellow will create the simplest PDF doc with only one line of text, and that document is 245 kb.Same example with Infragistic is 14 kb.
    Exact same relations is also when I add images in..I can see that Telerik document is much higher in quality [when I put images] but we prefer size/performance then quality of PDF.

    Can you point what I have to change? Is any FormatProviders.Pdf settings that I can use to create smaller size document ?Or ?

     

    class TEST
        {
            public void ExportToPdf(string PdfURL)
            {
                Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider provider =
                    new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
                using (Stream output = File.OpenWrite(PdfURL))
                {
                    Telerik.Windows.Documents.Flow.Model.RadFlowDocument document = CreateRadFlowDocument();
                    provider.Export(document, output);
                }
            }
            private Telerik.Windows.Documents.Flow.Model.RadFlowDocument CreateRadFlowDocument()
            {
                RadFlowDocument document = new RadFlowDocument();
                RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
                editor.ParagraphFormatting.TextAlignment.LocalValue = Alignment.Justified;
                Section section = editor.InsertSection();
                section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(4);
                section.PageOrientation = Telerik.Windows.Documents.Model.PageOrientation.Landscape;
               
                //test text
                editor.InsertText("TEST Telerik.Windows.Documents.Flow.Model.RadFlowDocument PDF ");

                return document;
            }
           
        }

     

     


  2. Neven
    Neven avatar
    10 posts
    Member since:
    Jul 2013

    Posted 25 Feb in reply to Neven Link to this post

       
     I  think that this is issue ?
    http://www.telerik.com/support/kb/reporting/details/the-size-of-the-exported-pdf-file-is-big
    Font was embeded inside PDF.
    TELERIK fixed it years ago in REPORTING.
    HoW to set those params in
    Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider .. or  ???
    Without solution we can not use TELERIK...
  3. Neven
    Neven avatar
    10 posts
    Member since:
    Jul 2013

    Posted 25 Feb Link to this post

    I also tried to set different PDF settings, but none of them help .. Size of file is 10 times of PDF that we generating now.

    If font is embedded I expect that it will be const size increase ,ex font embedded is 1 mb , and we can tolerate this, but with any image added PDF progressive increase in size ...

     

    PdfExportSettings settings = new PdfExportSettings();
    settings.ImageQuality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.Low;
    settings.ComplianceLevel = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfComplianceLevel.None;
    provider.ExportSettings = settings;

  4. Neven
    Neven avatar
    10 posts
    Member since:
    Jul 2013

    Posted 25 Feb Link to this post

    PDF from exactly same test ["hello world"] but using FIXED MODEL
    Telerik.Windows.Documents.Fixed.Model.RadFixedDocument
    Telerik.Windows.Documents.Fixed.FormatProviders.Pdf
    is only 2 kb !!!!

    We used Telerik.Windows.Documents.Flow.Model because of formatting .

    What cause that FIXED model PDF is 100 times smaller in size then FLOW model ?

     

     


    namespace TestTELERIK
    {
        class TELERIK_PDF_Fixed_Test
        {
            RadFixedDocument m_Document = null ;
            RadFixedDocumentEditor m_Editor = null;
            public void ExportToPdf(string PdfURL)
            {
                PdfFormatProvider provider =  new PdfFormatProvider();
                using (Stream output = File.OpenWrite(PdfURL))
                {
                    RadFixedDocument document = CreateRadFlowDocument();
                    provider.Export(document, output);
                }
            }
            private RadFixedDocument CreateRadFlowDocument()
            {
                m_Document = new RadFixedDocument();
                m_Editor = new RadFixedDocumentEditor(m_Document);
                m_Editor.InsertLine("TEST RadFixedDocument PDF ");
                m_Editor.Dispose();
                return m_Document;
            }
        }
    }


  5. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 26 Feb Link to this post

    Hello Neven,

    Thank you for contacting us.

    As mentioned in this fonts documentation section all fonts that are not one of the standard PDF fonts should be embedded. If the font is not embedded the result of opening the PDF on different devices is unpredictable and this not recommended due to PDF format specification. That is the reason why RadPdfProcessing embeds all non-standart fonts used in the document. 

    As RadPdfProcessing default font is Helvetica, which is one of the standard fonts, this font is not embedded which explains why exporting "hello world" document with RadPdfProcessing results in much smaller size. However, if you change the font in RadPdfProcessing to "Calibri", the size of the document will be the same as in RadWordsProcessing as RadWordsProcessing uses RadPdfProcessing for its PDF export. Although this difference in document size may seem huge for a "hello world" document, in real world scenario when the document has more text content the size of the embedded font is much smaller compared to the size of the PDF content. Additionally I would like to mention that as an optimization RadPdfProcessing does not embed the whole font but instead embeds only the font subset of the used characters which guarantees minimum font size.

    As for the images - RadPdfProcessing inserts the image in the PDF with the same resolution as the referenced image. Using the ImageQuality enumeration you can control the quality of the image and this way reduce the size using lower quality. You may try this SDK demo to see how the different image quality results in different document size. However, there is one additional suggestion I would like to mention when talking about reducing the PDF size. If an image is rendered with size 500x500 in the PDF page then you may consider adding the image with similar size to the document. This means that if your original image is for instance 2000x2000 then you may preprocess it to become 500x500 and then add it to the corresponding RadFlowDocument or RadFixedDocument instance. Even exporting to PDF with ImageQuality.High, this preprocessing will reduce the image size in the document about 4 times and still the image will be rendered with maximum quality. I am attaching a demo project showing how you can resize images using only .Net Framework. A few words about this demo:
    • It is a console application.
    • It opens BigImage.jpg file that is about 1.2 MB with resolution 2313x2311.
    • ResizeImage method resizes the original image to 35 KB with resolution 693x693 and image quality 75. If you choose lower image quality value you can get even more impressive image size difference.
    • After the image is resized the application opens it, so that you can see the result with your default jpeg viewer.

    When talking about performance - as mentioned in this "ImageQuality.High with JPEG and JPEG2000 images" documentation section, when using ImageQuality.High RadPdfProcessing reads only the image headers and when the image is JPEG it inserts it in the document without processing the whole image pixels. This not only guarantees best image quality but also guarantees maximum performace as processing big images may be a time consuming operation. So as a performance optimization I would suggest you to use ImageQuality.High when exporting to PDF. 

    I hope this information is helpful. If you have any other questions or concerns please do not hesitate to contact us again.

    Regards,
    Deyan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Neven
    Neven avatar
    10 posts
    Member since:
    Jul 2013

    Posted 26 Feb in reply to Deyan Link to this post


    I did read all of those articles before and did change font types.
    But in “FLOW model”, change of fonts, in “hello world” example, does not change size of file. You can try this. File size stay same for any font and it is ~ 250 kb !!!

    In “FIXED model” same example again with any font , PDF is only 2 kb .

    Question is why PDF file in FLOW model is 100 times bigger then in FIXED model?
    And it goes more when document is more complex ..


    It seems to me that it is bug. PDF file in both cases is valid . We did check them.
    Right now how I understand our only option is rewrite all code using FIXED model ?
  7. Deyan
    Admin
    Deyan avatar
    135 posts

    Posted 01 Mar Link to this post

    Hello Neven,

    Currently, the only way to use standard fonts in PDF export is by getting such font from a FontsRepository class static property. Unfortunately, this can only be achieved by using RadPdfProcessing API as RadWordsProcessing sets the fonts using FontFamily, FontWeight and FontStyle. We have logged a feature request related to implementing mechanism for setting standard font from the above mentioned properties. You can vote for this feature request and follow its implementation progress by following this feedback item. Meanwhile, the only workaround is to use RadPdfProcessing editing API in order to generate and export flow document content to PDF.

    If you have other questions please contact us again.

    Regards,
    Deyan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top