You are not logged in.
Pages: 1
I got the sample PDF file working. However, I need to be able to change the height of the page based upon the document that I am creating. This page may be as long as 50 inches in length. When changing the height of the page in the example program all printing disappears from the page. Here is the code I am using:
lPdf.ScreenLogPixels:=600;
lPage := lPDF.AddPage;
lPage.PageHeight := lPdf.ScreenLogPixels * 50; // This is the added line. If I remove this everything is displayed on the page.
lPdf.VCLCanvas.Brush.Style:=bsClear;
MyY:=300;
for MyX := 1 to 40 do begin
MyXLoc:=(MyX*120) mod lPage.PageWidth;
MyString:=IntToStr(MyX);
lPDF.VCLCanvas.TextOut(MyXLoc, MyY, Mystring);
lPDF.VCLCanvas.Font.Size:= lPDF.VCLCanvas.Font.Size+4;
lPDF.VCLCanvas.Rectangle(MyXLoc, MyY, MyXLoc+lPDF.VCLCanvas.TextWidth(MyString), MyY+lPDF.VCLCanvas.TextHeight(MyString));
MyY := MyY + lPDF.VCLCanvas.TextHeight(MyString);
end;
lPdf.SaveToFile('c:\Syntest.pdf');
Offline
If I move the setting of page height/width before calling AddPage I get a run time error stating that lPage is not initialized. How do I create the page?
Offline
I want the document to have 600 DPI and to be 8 inches wide x 50 inches long. This is what I currently have. Nothing is printed on the page.
lPdf := TPdfDocumentGDI.Create;
try
lPdf.ScreenLogPixels:=600;
lPdf.DefaultPageHeight := lPdf.ScreenLogPixels * 50; // Since ScreenLogPixels holds the number of pixels per inch this should give me a 50 inch long page.
lPdf.DefaultPageWidth := lPdf.ScreenLogPixels * 8; // Same here with Page being 8 inches wide.
// When viewing the document in Adobe Reader the page height and width 66.67 x 200.00 with nothing displayed
// If I comment out the ScreenLogPixels line the page size becomes 10.67 x 66.67 with a pixel count of 768 x 4800 with the proper text on the document.
lPage := lPDF.AddPage;
lPdf.VCLCanvas.Brush.Style:=bsClear;
MyY:=300;
lPDF.VCLCanvas.TextOut(100, 100, 'Width = ' + IntToStr(lPage.PageWidth) +
' Height = ' + IntToStr(lPage.PageHeight));
for MyX := 1 to 400 do begin
MyXLoc:=(MyX*120) mod (lPage.PageWidth);
MyString:=IntToStr(MyX);
lPDF.VCLCanvas.TextOut(MyXLoc, MyY, Mystring);
lPDF.VCLCanvas.Font.Size:= lPDF.VCLCanvas.Font.Size+4;
lPDF.VCLCanvas.Rectangle(MyXLoc, MyY, MyXLoc+lPDF.VCLCanvas.TextWidth(MyString), MyY+lPDF.VCLCanvas.TextHeight(MyString));
MyY := MyY + lPDF.VCLCanvas.TextHeight(MyString);
end;
lPdf.SaveToFile('c:\Syntest.pdf');
finally
lPdf.Free;
end;
Last edited by Kent (2014-06-24 20:58:46)
Offline
Instead of DefaultPageHeight, which uses PDF size and not screenlogplixels, you could use DefaultPaperSize property instead.
Technically, PDF has no resolution. Images are made of samples and can be scaled to nearly any size.
For dimensions, see the setter method:
const PAPERSIZE: array[TPDFPaperSize] of array[0..1] of integer =
( (595,842), (419,595), (842,1190), (612,792), (612,1008), (0,0) );
begin // psA4, psA5, psA3, psLetter, psLegal, psUserDefined
The VCL TCanvas drawing uses diverse coordinates system:
fVCLCanvasSize.cx := MulDiv(PageWidth,FDoc.FScreenLogPixels,72);
fVCLCanvasSize.cy := MulDiv(PageHeight,FDoc.FScreenLogPixels,72);
as stated by TPdfPageGDI.SetVCLCurrentMetaFile.
Offline
I am sorry I don't understand what you are saying. Can you change the above code to work? Thanks for your help.
Offline
In raw PDF, all locations and sizes are stored in a logical value called a PDF unit. 1 PDF unit is equivalent to 1/72 of an inch.
DefaultPageHeight and DefaultPageWidth are values in PDF units, so 1/72th of a inch.
So for a 50' * 8' page, you can write:
lPdf.DefaultPageHeight := 72 * 50;
lPdf.DefaultPageWidth := 72 * 8;
Then the VCL canvas available in lPdf.VCLCanvas will have a diverse coordinate system, depending in fact of lPdf.ScreenLogPixels.
So when you draw something in the lPdf.VCLCanvas, ensure you use the right size for coordinates, i.e. via lPdf.VCLCanvasSize values.
Offline
Pages: 1