ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PDF to large (9 mb / page grayscale or color)
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

pcmueller77

12 Posts

Posted - Mar 19 2024 :  05:56:42  Show Profile  Reply
Hi, we need help to get grayscale or color pdfs smaller in size. Can you please help us to solve this with
~ 300 kb and not ~10 mb per page? Thanks a lot.

Attached the sample image from which we create a pdf.

C# .Net code:


        static void TestPDF2()
        {
            string sourceImage = @"C:\Laufwerk_d\Net\IEmagen_grayscaletiff_error\IEvolution gray_tif_fails\SourceFiles\For pdf grayscale.png";
            string targetPDF = @"C:\Temp\capture\export\page.pdf";
            using (IEViewer ieViewer = new IEViewer())
            {
                ieViewer.Image.CreatePDFFile(targetPDF);
                ieViewer.Image.LoadImage(sourceImage);
                ieViewer.Image.ConvertToGray();
                ieViewer.Image.IOParams.PDF_Compression =  PDFCompression.LZW;
                ieViewer.Image.IOParams.BitsPerSample = 8;
                ieViewer.Image.IOParams.SamplesPerPixel = 1;
                ieViewer.Image.SaveToPDF();
                ieViewer.Image.ClosePDFFile();
            }
        }



attach/pcmueller77/202431955614_For pdf grayscale.png

xequte

38608 Posts

Posted - Mar 19 2024 :  22:35:50  Show Profile  Reply
Hi

You might want to try resampling the image to a smaller size:

https://www.imageen.com/ievolutionhelp/html/e8f1293a-1291-607d-0ee7-4cff02ddc2b4.htm

Make sure you use None or one of the B/W filters to avoid upscaling the image to 24bit.


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

pcmueller77

12 Posts

Posted - Mar 20 2024 :  04:04:46  Show Profile  Reply
Hi Nigel. In one related post it was mention, that only the pdf, not the images are compressed. I think this has changed.
I now can prove 1 mb pdfs with grayscale and 2 pages.

is the code correct, or any ideas left? Resampling is not an option, we don't want to get the file worser if we save it again and again.

        static void TestPDF2()
        {
            string sourceImage1 = @"C:\Laufwerk_d\Net\IEmagen_grayscaletiff_error\IEvolution gray_tif_fails\SourceFiles\For pdf grayscale.png";
            string sourceImage2 = @"C:\Laufwerk_d\Net\IEmagen_grayscaletiff_error\IEvolution gray_tif_fails\SourceFiles\20220513152724.jpg";
            string targetPDF = @"C:\Temp\capture\export\page.pdf";
            List<string > sourceImages=new List<string>();
            sourceImages.Add(sourceImage1);
            sourceImages.Add(sourceImage2);
            using (IEImage ieImage = new IEImage())
            {
                ieImage.CreatePDFFile(targetPDF);

                foreach (string sourceImage in sourceImages)
                {
                    ieImage.LoadImage(sourceImage);
                    // resample
                    //ieImage.Resample(1500, -1, IEResampleFilter.FastLinear);
                    ieImage.ConvertToGray();
                    ieImage.IOParams.TIFF_ZIPCompression = TIFFZIPCompression.Max;
                    ieImage.IOParams.TIFF_Compression = TIFFCompression.ZIP;
                    //reload as tiff:
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        ieImage.SaveImage(memoryStream, IEFileFormats.TIFF);
                        ieImage.LoadImage(memoryStream);
                    }
                    ieImage.IOParams.PDF_Compression = PDFCompression.LZW;
                    ieImage.IOParams.BitsPerSample = 8;
                    ieImage.IOParams.SamplesPerPixel = 1;
                    ieImage.SaveToPDF();
                }

                ieImage.ClosePDFFile();
            }
        }
Go to Top of Page

xequte

38608 Posts

Posted - Mar 20 2024 :  22:01:04  Show Profile  Reply
Sorry, I forgot one important point (which will be resolved in the next update of IEvolution), if the image has an alpha channel it will blow out the size of the PDF.

So normally loading and saving would have no effect, except in this case, because you save to a TIFF format that does not support alpha, the alpha channel gets discarded.

Of course an easier way is simply to remove the alpha channel:

https://www.imageen.com/ievolutionhelp/html/93655d48-efaf-5b1a-0e8d-3d84567c124d.htm

Something like:

        static void TestPDF2()
        {
            string sourceImage1 = @"C:\Laufwerk_d\Net\IEmagen_grayscaletiff_error\IEvolution gray_tif_fails\SourceFiles\For pdf grayscale.png";
            string sourceImage2 = @"C:\Laufwerk_d\Net\IEmagen_grayscaletiff_error\IEvolution gray_tif_fails\SourceFiles\20220513152724.jpg";
            string targetPDF = @"C:\Temp\capture\export\page.pdf";
            List<string > sourceImages=new List<string>();
            sourceImages.Add(sourceImage1);
            sourceImages.Add(sourceImage2);
            using (IEImage ieImage = new IEImage())
            {
                ieImage.CreatePDFFile(targetPDF);

                foreach (string sourceImage in sourceImages)
                {
                    ieImage.LoadImage(sourceImage);
                    ieImage.RemoveAlphaChannel(True)
                    ieImage.ConvertToGray();
                    ieImage.IOParams.PDF_Compression = PDFCompression.LZW;
                    ieImage.IOParams.BitsPerSample = 8;
                    ieImage.IOParams.SamplesPerPixel = 1;
                    ieImage.SaveToPDF();
                }

                ieImage.ClosePDFFile();
            }
        }




Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: