【发布时间】:2014-06-25 16:09:40
【问题描述】:
我正在尝试使用 Delphi 的 Synopse SynPDF 库创建 PDF 文档。我需要能够动态更改纸张尺寸以适应我正在创建的文档。纸张尺寸的高度需要从 11 英寸到 100 英寸以上的任意位置进行更改。我还想将图像的分辨率设置为每英寸 300 像素到每英寸 600 像素。这是我的测试。
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;
【问题讨论】:
-
您的尝试如何未能达到预期。请不要说“它不起作用”。
-
使用 ScreenLogPixels := 600 行,文档中没有任何内容,文档大小为 66.67 英寸 x 200,这意味着它使用 72 dpi 分辨率。如果我用 600 dpi 注释掉该行,则文档为 10.67 x 66.67 英寸。