#1 2017-04-29 09:56:55

ifmihai
Member
Registered: 2017-04-29
Posts: 2

Newbie struggling with adding TImage content to pdf

Hi,

I have an TImage, and i fail to add its content to pdf.

this is my code up to now.
the first method with Printer, works.
but synPDF method gives an empty pdf file

Honestly, I am very confused about TImage, TPicture, TGraphic, TBitmap.
I never understood what's each of them's purpose.
And I'm just an amateur here and there programmer in pascal.

I would really love some help, i feel it's not something hard, but it's just my confusion mostly.
i followed this youtube tutorial:
https://www.youtube.com/watch?v=IJSVD-x9mpM

procedure TForm1.ButtonPrintClick(Sender: TObject);
var
  ScaleX, ScaleY: Integer;
  RR: TRect;
  pdf: TPDFDocumentGDI;
begin
  with Printer do
  begin
    BeginDoc;
    try
      ScaleX := GetDeviceCaps(Handle, logPixelsX) div PixelsPerInch;
      ScaleY := GetDeviceCaps(Handle, logPixelsY) div PixelsPerInch;
      RR := Rect(0, 0, Image1.picture.Width * scaleX, Image1.Picture.Height * ScaleY);
      Canvas.StretchDraw(RR, Image1.Picture.Graphic);
    finally
      EndDoc;   //Methode EndDoc beendet den aktuellen Druckauftrag und schließt die
    end;
  end;



   // ----  synPDF

   //Image1.Picture.Metafile
  pdf := TPDFDocumentGDI.Create();
  try
     pdf.AddPage;
     pdf.DefaultPaperSize := psA4;
     pdf.VCLCanvas.Draw(10,10,Image1.Picture.Graphic);
     pdf.SaveToFile('pdftest.pdf');

  finally pdf.Free;

  end;
end;

Last edited by ifmihai (2017-04-29 10:11:20)

Offline

#2 2017-05-01 12:18:13

ifmihai
Member
Registered: 2017-04-29
Posts: 2

Re: Newbie struggling with adding TImage content to pdf

I asked a friend to help

on his xe2, synpdf works no pb
i have xe7

and i copy pasted the event from him (that works)

procedure TForm1.ButtonPrintClick(Sender: TObject);
var
  lPdf : TPdfDocumentGDI;
begin
  lPdf := TPdfDocumentGDI.Create();
  try
    lPdf.AddPage;
    lPdf.DefaultPaperSize := psA4;

    Image1.Canvas.Rectangle(10,10,30,30);

    lPdf.VCLCanvas.Draw(10,10,Image1.Picture.Graphic);
    lPdf.SaveToFile('1.pdf');
    lPdf.SaveToFile('c:\1.pdf');

  finally
    lPdf.Free;
  end;
end;

It works ok in his case.
In my case, rectagle appears in Image1 on screen.
But blank pdf, same.
And, blank pdf appears only with first statement '1.pdf'
second statement doesnt work, 'c:\1.pdf'

did i find a bug, i dont understand what happens

Offline

Board footer

Powered by FluxBB