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