摘要 pdf 使用 Delphi 更改纸张大小

use*_*254 2 pdf delphi

我正在尝试使用 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;
Run Code Online (Sandbox Code Playgroud)

Arn*_*hez 5

在 PDF 中,所有位置和大小都存储在称为 PDF 单元的逻辑值中。1 PDF 单位相当于 1/72 英寸。

DefaultPageHeightDefaultPageWidth是 PDF 单位的值,即 1/72 英寸。

因此,对于 50' * 8' 的页面,您可以编写:

 lPdf.DefaultPageHeight := 72 * 50; 
 lPdf.DefaultPageWidth := 72 * 8;     
Run Code Online (Sandbox Code Playgroud)

那么可用的 VCL 画布lPdf.VCLCanvas将具有不同的坐标系,具体取决于 的事实lPdf.ScreenLogPixels

因此,当您在 中绘制某些内容时lPdf.VCLCanvas,请确保使用正确的坐标尺寸,即通过lPdf.VCLCanvasSize值。