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 Quality
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndNit

Brazil
85 Posts

Posted - Sep 30 2025 :  09:04:11  Show Profile  Reply
I need to open a PDF, add a stamp to each page, and then save it.

I notice that this process has two problems.

1: The PDF loses considerable quality.

2: The PDF becomes much larger than the original.

I perform the following process:

Open the original PDF (52 MB)

imgMPDF.MIO.LoadFromFilePDF(edCaminhoPDF.Text)

After opening the PDF, perform the following procedure to stamp each page:

procedure TForm1.CarimbaImg;
var
   bmp : TBitmap;
   i   : Integer;
begin
    for i := StrToInt(edPgCarimbo.Text) to imgMPDF.ImageCount -1 do begin
       imgMPDF.SelectImage(i);
       bmp := imgMPDF.GetBitmap( i, true );
       imgCarimbo.Assign( bmp );
       imgMPDF.ReleaseBitmap(i, False);
       imgCarimbo.LayersAdd( ielkImage);                 // Append an image layer
       imgCarimbo.IO.LoadFromFile((ExtractFilePath(Application.ExeName) + 'LogoStamp.png'));  // Load imag
       imgCarimbo.CurrentLayer.PosX := IELayer_Pos_Right;
       imgCarimbo.CurrentLayer.PosX := imgCarimbo.CurrentLayer.PosX - 5;
       imgCarimbo.Update;
       //
       imgCarimbo.LayersMergeAll();
       imgMPDF.SetImage( imgMPDF.SelectedImage, imgCarimbo.IEBitmap );
       imgMPDF.Update;
    end;
     IEGlobalSettings().PDFEngine := ieenLegacy;
     imgMPDF.MIO.Params[0].PDF_Compression := ioPDF_JPEG ;
     imgMPDF.MIO.Params[0].JPEG_Quality := 40;
     imgMPDF.MIO.DuplicateCompressionInfo();
     imgMPDF.MIO.SaveToFilePDF(edDirSalva.Text);
     IEGlobalSettings().PDFEngine := ieenAuto;
     ShowMessage('Processo terminado');
end;



the result is a 193 MB PDF of MUCH lower quality

xequte

39279 Posts

Posted - Oct 02 2025 :  01:49:32  Show Profile  Reply
Hi

The issue here is that you are converting your PDF document (containing text, vectors, images, etc) into a single a bitmap.

If that is what you want to do (e.g. because each page of the PDF is already a single bitmap), then you just need to improve the import quality:

IEGlobalSettings().PdfViewerDefaults.DPI := 144; // PDF files are 72 DPI, so 144 is 200% size

http://www.imageen.com/help/TIEGlobalSettings.PdfViewerDefaults.html


However, it is more likely you want to keep the PDF file as a document and just add a stamp image.

For this you need to use the PDFViewer (PDFium):

https://www.imageen.com/help/TImageEnView.PdfViewer.html

You would load each page and then use:

https://www.imageen.com/help/TPdfObjectList.AddImage.html


Please see this shown in the demo:

Demos\PDF\PDFPageObjects\PDFPageObjects.dpr



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