#1 2014-02-23 18:10:23

loris
Member
Registered: 2014-02-23
Posts: 5

PrinterCanvas to SynPdf

Salut Arnaud,Hello
Is there any possibility to set PrinterCanvas or printerobject to SynPdf?

var
p:TPrinter;
lPdf : TPdfDocumentGDI;
begin
lPdf   := TPdfDocumentGDI.Create;
p:=TPrinter.Create;
p.BeginDoc;
p.Canvas.TextOut(0,0,'Salut');
{--------------------------------}
lPdf.Canvas:=p.Canvas?
{--------------------------------}

OR

lPdf   := TPdfDocumentGDI.Create(p);
{-----------------------------------------------------}
lpdf.SaveToFile('c:\cafaitplaisir.pdf');
lpdf.Free;
p.EndDoc;
p.Free;
end;

Because I've thousand of lines with the printercanvas, and I'could not change it so easy.

Regards,

Loris

Offline

#2 2014-02-23 20:03:31

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

Re: PrinterCanvas to SynPdf

A TPrinterCanvas is just a thin layer over TCanvas, introducing printer-dependent work.

Please change in your code your variables or fields into a generic TCanvas.
Then it will work as expected with your legacy code.
And you will be able to change this TPrinterCanvas into a TPDfDocumentGDI canvas.

Offline

#3 2014-03-07 11:34:21

loris
Member
Registered: 2014-02-23
Posts: 5

Re: PrinterCanvas to SynPdf

Thanks for the answer,
I made I interface with TCanvas, but how can I set canv
to PDFCanvas? Its necessary that I use tcanvas.

var
lPdf : TPdfDocumentGDI;
canv:TCanvas;
begin
lPdf := TPdfDocumentGDI.Create;

dosome(canv);

this is not going: 
false
lPdf.Canvas:=canv; because property.

Could you help me witht a peace of code?

Thanks a lot

loris

Offline

#4 2014-03-07 13:29:04

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

Re: PrinterCanvas to SynPdf

Just do the contrary:

var
lPdf : TPdfDocumentGDI;
begin
lPdf := TPdfDocumentGDI.Create;
lPDf.AddPage;
dosome(lPdf.VCLCanvas);
....

Offline

#5 2014-03-07 14:00:32

loris
Member
Registered: 2014-02-23
Posts: 5

Re: PrinterCanvas to SynPdf

Thanks for fast answer

Now I reveive a pdf, empty unfortunately.

The parameter of dosome(...) is TCanvas -->procedure printPDF(destination: tcanvas;outputnr:Integer);
dosome(lPdf.VCLCanvas);

lPdf.SaveToFile('c:\hallo.pdf');
      lpdf.Free;

Do you thinks there must happen something in the code, or...

Regards, merci bc

Offline

#6 2014-03-07 14:38:02

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

Re: PrinterCanvas to SynPdf

Ensure your canvas size (in pixels) is known by the "dosome()" method.

Offline

Board footer

Powered by FluxBB