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

GrayScale and Compress PDF

9 Answers 343 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Cleidson
Top achievements
Rank 1
Cleidson asked on 08 Aug 2016, 07:15 PM

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.

 

 

9 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 10 Aug 2016, 02:34 PM
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

0
CSharpBR
Top achievements
Rank 1
answered on 18 Jun 2018, 08:33 PM

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

 

0
CSharpBR
Top achievements
Rank 1
answered on 19 Jun 2018, 02:49 PM

 

 

        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);
            }
        }

0
CSharpBR
Top achievements
Rank 1
answered on 19 Jun 2018, 02:51 PM

"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

0
Boby
Telerik team
answered on 21 Jun 2018, 11:27 AM
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

0
CSharpBR
Top achievements
Rank 1
answered on 21 Jun 2018, 02:27 PM
Excellent ! Thanks very much !
0
Ahmad
Top achievements
Rank 1
answered on 28 Aug 2018, 03:17 PM

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 ?

 

 

 

 

 

 

0
Ahmad
Top achievements
Rank 1
answered on 28 Aug 2018, 07:57 PM
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.
0
Tanya
Telerik team
answered on 31 Aug 2018, 07:05 AM
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

Tags
PdfProcessing
Asked by
Cleidson
Top achievements
Rank 1
Answers by
Deyan
Telerik team
CSharpBR
Top achievements
Rank 1
Boby
Telerik team
Ahmad
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or