[SOLVED] add an image in an existing pdf lazarus / 39-Graphics ---------------------------------------------------------------------- scons · 2018-07-16 15:36 Hi all, I want to add an image (bmp) into an existing pdf. Simple approach, add the image to the pdf with x and y coördinates. Some searching gave the impression that it can be done with imagemagick. But the imagemagick version in the fpc folder seems to be kinda outdated (?). Is this still the way to go or are there other alternatives which are more up-to-date ? Any thoughts on this ? Thanks ---------------------------------------------------------------------- scons · 2018-07-19 11:26 okay, I found a way (quick and dirty !) for my W10 installation. ImageMagick should be installed, and add BGRABitmapPack as a requirement. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program imagemagickaddimage; {$mode objfpc}{$H+} uses {$IFDEF UNIX} {$IFDEF UseCThreads}  cthreads, {$ENDIF} {$ENDIF}  Classes,  SysUtils,  Process,  BGRABitmap,  BGRABitmapTypes { you can add units after this }; var  AProcess: TProcess;  AStringList, Temp: TStrings;  x1, xval, yval: integer;  result1, result2: string;  bmp1, bmp2: TBGRABitmap; begin  AProcess := TProcess.Create(nil);  try    AProcess.Executable := 'magick';    AProcess.Parameters.Add('convert');    AProcess.Parameters.Add('-density');    AProcess.Parameters.Add('300');    AProcess.Parameters.Add('D20.pdf');    AProcess.Parameters.Add('-page');    AProcess.Parameters.Add('A4');  AProcess.Parameters.Add('D20.png');    AProcess.Options := AProcess.Options + [poWaitOnExit];    AProcess.Execute;  finally    AProcess.Free;  end;   AProcess := TProcess.Create(nil);  try    AProcess.Executable := 'magick';    AProcess.Parameters.Add('identify');    AProcess.Parameters.Add('D20.png');    AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];    AProcess.Execute;   Temp := TStringList.Create;    AStringList := TStringList.Create;    AStringList.Delimiter := ' ';    AStringList.StrictDelimiter:= True;  AStringList.LoadFromStream(AProcess.Output);     //AStringList.SaveToFile('output.txt');    Temp.CommaText:= AStringList[0];    x1      := Pos('x', Temp[2]);    result1 := Copy(Temp[2], 0, x1 - 1);    result2 := Copy(Temp[2], x1 + 1, length(AStringList[0]));     //writeln(Temp[2]);    //writeln(result1);    //writeln(result2);  finally    Temp.Free;    AStringList.Free;    AProcess.Free;  end;   xval := StrToInt(result1);  yval := StrToInt(result2);   xval := trunc(xval - xval+(50/0.264583)); // needs optimisation for shift X/Y in mm + DPI  yval := trunc(yval -  250-(50/0.264583)); // needs optimisation for shift X/Y in mm + DPI   bmp1 := TBGRABitmap.Create;  bmp2 := TBGRABitmap.Create;  try    bmp1.LoadFromFile('D:\imagemagick2\D20.png');    bmp2.LoadFromFile('D:\imagemagick2\1002.bmp');  // this image will be added    bmp1.PutImage(xval, yval, bmp2, dmSet);    bmp1.SaveToFile('test.png');  finally    bmp1.Free;    bmp2.Free;  end;   AProcess := TProcess.Create(nil);  try    AProcess.Executable := 'magick';    AProcess.Parameters.Add('convert');    AProcess.Parameters.Add('-density');    AProcess.Parameters.Add('300');    AProcess.Parameters.Add('test.png');    AProcess.Parameters.Add('test.pdf');    AProcess.Options := AProcess.Options + [poWaitOnExit];    AProcess.Execute;  finally    AProcess.Free;  end;end.  Of course this is not the best and most elegant way (and badly coded), but I needed to move forward. If I find some time in the near future I will try to optimize this. Cheers