#1 2012-06-21 09:13:54

delphi_prog
Member
Registered: 2012-06-21
Posts: 4

How to add picture file to pdf

Hi!

I have created pdf with text, but i cannot find how to add picture (any format). I am looking for the easiest source code to do this. It would be nice if anyone could add all the implementation uses and etc too.

I am using the method with canvas and tried this: 

with TPdfDocument.Create do

  try

    AddPage;

    Canvas.DrawXObject(10,10,10,10, 'Picture.bmp');

    Canvas.SetFont('Times new roman',30,[{fsItalic,}{fsBold}]);

This is not working. Can someone help me?

Last edited by delphi_prog (2012-06-21 11:53:18)

Offline

#2 2012-06-21 12:45:24

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,253
Website

Re: How to add picture file to pdf

It won't work: you'll have to define the XObject before drawing it!
See TPDFDocument.CreateOrGetImage method.
Search for "TPDFDocument" in this forum, and you will find out some samples and discussion.
Not so easy.

So IMHO you would better use TPDFDocumentGDI class, and its standard Canvas parameter.
Then you'll be able to assign any picture to it, just as usual, without the internal PDF plumbing.

Or even easier use a TGDIPages report generator (which handles pictures easily).

Offline

#3 2012-06-21 21:20:27

delphi_prog
Member
Registered: 2012-06-21
Posts: 4

Re: How to add picture file to pdf

Tryed to follow your instructions (not sure if i found the right thing). But i found procedure in SQLite3Pages:

procedure TGDIPages.DrawBMP(rec: TRect; bmp: TBitmap);
begin
  if self=nil then exit; // avoid GPF
  if not fHeaderDone then
    DoHeader;
  PrintBitmap(fCanvas, MmToPrinter(rec), bmp);
end;

Cant understand what is Trec and how do i have do declare rec and bmp to use them in my program?

Offline

#4 2012-06-22 08:30:57

delphi_prog
Member
Registered: 2012-06-21
Posts: 4

Re: How to add picture file to pdf

Ive got it. Thanks for your help!

Offline

Board footer

Powered by FluxBB