I´m trying to replace Images in existing Pdf-documents.
I´ve tried using the PDFium Component Suite for FireMonkey.
With the following code i´ve managed to insert an image via the AddPicture-function. Unfortunately i can´t find a way to get the position of the existing image. Unfortunately the record TPdfImage only has the properties Width, Height and Data. Does someone have experience with those Components or done anything like this already?
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
lImage: TPdfImage;
begin
FPdf1.FileName := 'C:\Path_To_Pdf.pdf';
FPdf1.PageNumber := 1;
FPdf1.Active := True;
for I := 0 to FPdf1.ImageCount - 1 do
begin
lImage := FPdf1.Image[I];
end;
FPdf1.AddPicture(ImageControl1.Bitmap, 20, 20, 100, 100);
FPdf1.SaveAs('C:\Path_To_Pdf_Images.pdf');
end;
I´ve found a solution for the problem. With PDFium you can iterate over the Objects in the Pdf and just check if the
ObjectTypeisotImage.With this sample i´m overriding all images in the pdf with the
BitmapinImageControl1. I hope this might help someone else in the future.