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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PDF to large (9 mb / page grayscale or color)

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
pcmueller77 Posted - Mar 19 2024 : 05:56:42
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
3   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Mar 20 2024 : 22:01:04
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
pcmueller77 Posted - Mar 20 2024 : 04:04:46
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();
            }
        }
xequte Posted - Mar 19 2024 : 22:35:50
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