#1 2012-02-28 12:43:42

Bulldog1100
Member
Registered: 2012-02-28
Posts: 1

Background Image

Hello,
I like to create a background imagefile for every page of the pdf.

I tried to use this code

PDF := TPDFDocument.Create;
Image := TPdfImage.CreateJpegDirect(pdf, 'BackgroundImage.jpg');
Pdf.AddXObject('BackgroundImage', Image);
for i := 0 to PageCount-1 do
begin
  page := PDF.AddPage;
  Pdf.Canvas.DrawXObject(0, 0, page.PageWidth, page.PageHeight, 'BackgroundImage');
end;

this generates an exception on the AddObject statement
how can i resolve this?

Offline

#2 2012-02-29 06:43:40

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

Re: Background Image

I just tried the following code:

program Project4;

{$APPTYPE CONSOLE}

uses
  SynPdf;

procedure Test;
var Image: TPdfImage;
    PDF: TPDFDocument;
    Page: TPdfPage;
    i: integer;
begin
  PDF := TPDFDocument.Create;
  Image := TPdfImage.CreateJpegDirect(pdf, 'Pingoo_s.jpg');
  Pdf.AddXObject('BackgroundImage', Image);
  for i := 0 to 10-1 do
  begin
    page := PDF.AddPage;
    Pdf.Canvas.DrawXObject(0, 0, page.PageWidth, page.PageHeight, 'BackgroundImage');
  end;
  PDF.SaveToFile('test.pdf');
  PDF.Free;
end;

begin
  Test;
end.

Which worked like a charm - at least with the current trunk version from http://synopse.info/fossil

Offline

Board footer

Powered by FluxBB