【问题标题】:synopse pdf changing paper size using Delphi使用 Delphi 更改纸张大小的概要 pdf
【发布时间】: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 英寸。

标签: delphi pdf


【解决方案1】:

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

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

所以对于一个 50' * 8' 的页面,你可以这样写:

 lPdf.DefaultPageHeight := 72 * 50; 
 lPdf.DefaultPageWidth := 72 * 8;     

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

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

【讨论】:

  • 阿诺,w.r.t.你最近的博文blog.synopse.info/post/2015/09/28/…Plz,不建议使用基于统计的谷歌和微软翻译,只需与专业的 www.translate.ru 比较,看看
  • @Arioch'我放了 translate.ru 直接在线翻译的链接。
猜你喜欢
  • 2018-04-20
  • 2014-11-10
  • 2017-02-21
  • 2012-07-26
  • 1970-01-01
  • 1970-01-01
  • 2020-07-06
  • 2014-03-16
  • 2017-08-28
相关资源
最近更新 更多