概要pdf使用Delphi更改纸张尺寸 [英] synopse pdf changing paper size using Delphi

查看:100
本文介绍了概要pdf使用Delphi更改纸张尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Delphi使用Synopse SynPDF库创建PDF文档.我需要能够即时更改纸张尺寸以适应正在创建的文档.纸张尺寸的高度需要从11英寸更改为100英寸以上.我还想将图像的分辨率设置为每英寸300像素到每英寸600像素.这就是我的测试.

I am trying to create a PDF document using Synopse SynPDF library using Delphi. I need to be able to change the paper size on the fly to accommodate the document I am creating. The paper size's height needs to be changed anywhere from 11 inches to over 100 inches. I would also like to set the resolution of the image to be anywhere from 300 pixels per inch to 600 pixels per inch. This is what I have as a test.

   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;

推荐答案

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

In 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 DefaultPageWidth 是PDF单位的值,因此是1/72英寸.

DefaultPageHeight and DefaultPageWidth are values in PDF units, so 1/72th of a inch.

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

So for a 50' * 8' page, you can write:

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

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

Then the VCL canvas available in lPdf.VCLCanvas will have a diverse coordinate system, depending in fact of lPdf.ScreenLogPixels.

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

So when you draw something in the lPdf.VCLCanvas, ensure you use the right size for coordinates, i.e. via lPdf.VCLCanvasSize values.

这篇关于概要pdf使用Delphi更改纸张尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆