GrayScale and Compress PDF

10 posts, 0 answers
  1. Cleidson
    Cleidson avatar
    7 posts
    Member since:
    May 2016

    Posted 08 Aug 2016 Link to this post

    Hi Guys,

    I'm finding a solution for two questions using PdfProcessor:

    1 - There is a way to convert a pdf document to GrayScale ?

    2 - There is a way to compress a existing pdf document ?

     

    Regards,

    Cleidson.

     

     

  2. Deyan
    Admin
    Deyan avatar
    171 posts

    Posted 10 Aug 2016 Link to this post

    Hello Cleidson,

    About the grayscale conversion - you may import the PDF file and iterate its content by changing the colors to gray. I am attaching a sample project showing how to import PDF file with colors, change the colors of the Path, TextFragment and Image instances and finally view the modified file.

    As for the compression - when you import and then export some existing PDF file with RadPdfProcessing the exported file is always compressed the best way RadPdfProcessing can. So if the original file has uncompressed content RadPdfProcessing will compress it on export. The only property that allows you to change the default RadPdfProcessing compression is PdfExportSettings ImageQuality property. Using this property you may export images in the PDF file with better compression at the expense of image quality.

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

    Regards,
    Deyan
    Telerik by Progress

  3. CSharpBR
    CSharpBR avatar
    8 posts
    Member since:
    Mar 2018

    Posted 18 Jun 2018 in reply to Deyan Link to this post

    Hi

    Is there a way using pdf processing to list images inside a pdf document and get the type/size of each one ? Just to block certain pdfs that do not fit in our needs ( huge sizes ). I already coded (using another library) an utility that calculates the ratio Kb/page. We could use that to block if they are bigger than what we think is reasonable but it would be better if we could point an image that has an excessive size.

    Thanks

     

  4. CSharpBR
    CSharpBR avatar
    8 posts
    Member since:
    Mar 2018

    Posted 19 Jun 2018 in reply to Deyan Link to this post

     

     

            static void Main()
            {

                PdfFormatProvider provider = new PdfFormatProvider();
                PdfExportSettings settings = new PdfExportSettings();
                settings.ImageQuality = ImageQuality.Low;
                using (Stream stream = File.OpenRead("d:\\sample.pdf"))
                {
                    RadFixedDocument document = provider.Import(stream);
                    provider.ExportSettings = settings;
                    Stream saida = File.Create("d:\\output.pdf");
                    provider.Export(document,saida);
                }
            }

  5. CSharpBR
    CSharpBR avatar
    8 posts
    Member since:
    Mar 2018

    Posted 19 Jun 2018 in reply to CSharpBR Link to this post

    "As for the compression - when you import and then export some existing PDF file with RadPdfProcessing the exported file is always compressed the best way RadPdfProcessing can. So if the original file has uncompressed content RadPdfProcessing will compress it on export. The only property that allows you to change the default RadPdfProcessing compression is PdfExportSettings ImageQuality property. Using this property you may export images in the PDF file with better compression at the expense of image quality."

     

    I tried the code above but unfortunately the size remained the same

  6. Boby
    Admin
    Boby avatar
    692 posts

    Posted 21 Jun 2018 Link to this post

    Hello Sergio,

    You can iterate the content elements in the pages and check the properties of the ImageSource for the Images, for example:
    foreach (var page in this.pdfDocument.Pages)
    {
        foreach (ContentElementBase contentElement in page.Content)
        {
            var image = contentElement as Telerik.Windows.Documents.Fixed.Model.Objects.Image;
            if (image != null)
            {
                var width = image.ImageSource.Width;
                var byteSize = image.ImageSource.GetEncodedImageData().Data.Length;
                var filters = image.ImageSource.GetEncodedImageData().Filters;
            }
        }
    }

    To the ImageQuality property - it would only affect the quality of the newly created images, the images imported from the PDF document will be left intact. This was not so clear in the ImageQuality documentation article, but I'll make sure to fix this.


    Regards,
    Boby
    Progress Telerik

  7. CSharpBR
    CSharpBR avatar
    8 posts
    Member since:
    Mar 2018

    Posted 21 Jun 2018 in reply to Boby Link to this post

    Excellent ! Thanks very much !
  8. Ahmad
    Ahmad avatar
    2 posts
    Member since:
    Aug 2018

    Posted 28 Aug 2018 in reply to Deyan Link to this post

    Hey Deyan,

    I tried to run the sample project but its missing few ddl's like 

    Telerik.Windows.Documents.Core

    Telerik.Windows.Documents.Fixed

    Telerik.Windows.Zip

    Can you please guide from where i can get this dll's ?

     

     

     

     

     

     

  9. Ahmad
    Ahmad avatar
    2 posts
    Member since:
    Aug 2018

    Posted 28 Aug 2018 in reply to Deyan Link to this post

    I was able to run the demo you have provided. It is converting the file into gray but the only draw back is that it increases the size of the file to almost double.
  10. Tanya
    Admin
    Tanya avatar
    763 posts

    Posted 31 Aug 2018 Link to this post

    Hello Ahmad,

    The size of the exported file pretty much depends on the content that is inside the document. With that said, I am afraid that I cannot say what might be causing the increase of the file size without testing a particular document. If you would like, you could open a support ticket and share an example document so we can provide you with a more appropriate answer.

    Regards,
    Tanya
    Progress Telerik

Back to Top