Forum > Graphics

Scale image to fit into pdf Page using Lazarus "fpPDF" Unit

(1/1)

Weitentaaal:
Hello,

i was trying to print a pdf with a Picture on it, result is attachet.

How do i scale the Picture Down so it will fit ?

Here is my Code:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure SimpleImage(Path: String; D: TPDFDocument; APage: integer);Var  P: TPDFPage;  FtTitle: integer;  IDX: Integer;  W, H: TPDFFloat;begin  P := D.Pages[APage];  // create the fonts to be used (use one of the 14 Adobe PDF standard fonts)  FtTitle := D.AddFont('Helvetica');   { Page title }  P.SetFont(FtTitle,23);  P.SetColor(clBlack, false);  P.WriteText(25, 20, 'Sample Image Support');   P.SetFont(FtTitle,10);  P.SetColor(clBlack, false);   IDX := D.Images.AddFromFile(Path, False);  W := PDFTomm(D.Images[IDX].Width);  H := PDFTomm(D.Images[IDX].Height);   P.DrawImage(20, 20, w, h, IDX);end; procedure SaveDocument(Path: String; D : TPDFDocument);begin  if FileExists('C:\Users\User1\Desktop\TEST.pdf') then DeleteFile('C:\Users\User1\Desktop\TEST.pdf');  D.SaveToFile('C:\Users\User1\Desktop\TEST.pdf');end; function SetUpDocument: TPDFDocument;var  P: TPDFPage;  S: TPDFSection;  i: integer;  lPageCount: integer;begin  Result := TPDFDocument.Create(Nil);  Result.Infos.Title := Application.Title;  Result.Infos.Author := 'Graeme Geldenhuys';  Result.Infos.Producer := 'fpGUI Toolkit 1.4.1';  Result.Infos.ApplicationName := ApplicationName;  Result.Infos.CreationDate := Now;  Result.Infos.KeyWords:='fcl-pdf demo PDF support Free Pascal';   Result.StartDocument;  S := Result.Sections.AddSection; // we always need at least one section  lPageCount := 1;  for i := 1 to lPageCount do  begin    P := Result.Pages.AddPage;    P.PaperType := ptA4;    P.UnitOfMeasure := uomMillimeters;    S.AddPage(P); // Add the Page to the Section  end;end; procedure TForm1.FormCreate(Sender: TObject);var   D: TPDFDocument;begin   D:= SetUpDocument;   SimpleImage('C:\Users\User1\Desktop\Unbenannt.PNG', D, 0);   SaveDocument(D);end;  

Weitentaaal:
Found it out by Myself.

The TPDFPage Class has a Property Paper so you can use Something like this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Margin = 20  P.DrawImage(Margin, Margin, PDFTomm(P.Paper.W) - Margin, PDFTomm(P.Paper.h) - Margin, IDX);  

Navigation

[0] Message Index

Go to full version