2011-08-19 169 views
4

我正在编写一个所见即所得的页面设计器应用程序,它允许用户将图像和文本拖放到设计器面板上,然后将面板打印到PDF。如何获取所有纸张尺寸名称和相应的像素尺寸?

在我的应用程序的页面设置选项中,用户需要选择一个页面尺寸,然后根据选定的页面尺寸,它将在屏幕上显示一个根据尺寸确定尺寸的面板(例如,A4选择= 8.5 x 11英寸和面板的尺寸将根据这些像素尺寸而定)。

然后,当用户单击“打印”时,面板的内容将被绘制为具有所选尺寸的PDF文件。

我正在使用wPDF组件集,特别是TWPPDFPrinter组件来创建PDF。

我的问题:

  1. 如何获取所有纸张大小的列表名称,然后如何让自己的相应尺寸wPDFPrinter?

在此先感谢。

+0

请准确定义“所有纸张大小” –

回答

2

要获得在系统中定义的所有打印机表单列表:

uses 
    winspool, printers; 

... 


procedure TForm1.Button1Click(Sender: TObject); 
var 
    HPrinter: THandle; 
    Forms: array of TFormInfo1; 
    Count, Needed, Returned: DWORD; 
    i: Integer; 
begin 
    Memo1.Clear; 
    if OpenPrinter(nil, HPrinter, nil) then begin 
    try 
     if not EnumForms(HPrinter, 1, nil, 0, Needed, Returned) then begin 

     // we should fail here since we didn't pass a buffer 
     if GetLastError <> ERROR_INSUFFICIENT_BUFFER then 
      RaiseLastOSError; 

     Count := (Needed div SizeOf(TFormInfo1)) + 1; 
     SetLength(Forms, Count); 
     if EnumForms(HPrinter, 1, @Forms[0], SizeOf(TFormInfo1) * Count, Needed, 
      Returned) then begin 
      if Returned < Count then 
      SetLength(Forms, Returned); 
      for i := 0 to Returned - 1 do begin 
      Memo1.Lines.Add(Format('Paper name: %s, Paper size: %dmm x %dmm', 
          [Forms[i].pName, 
          Forms[i].Size.cx div 1000, 
          Forms[i].Size.cy div 1000])) 
      end; 
     end else 
      RaiseLastOSError; 
     end; 
    finally 
     ClosePrinter(HPrinter); 
    end; 
    end else 
    RaiseLastOSError; 
end; 
+0

Thx的意思。但首先是TWPPDFPrinter是一个组件,那么如何选择这个作为打印机索引? –

+0

@Steve - 我认为这是一台打印机...无论如何,您要么获得假脱机程序中定义的所有表单的列表,要么获取特定打印机支持的表单列表。对于前者的'nil'作为'OpenPrinter'的第一个参数,对于后者,你应该传递一个打印机名称作为'OpenPrinter'的第一个参数。 (当然,实际上并不是完全必要选择打印机,只需将“零”或有效的“打印机名称”传递给OpenPrinter)。 –

+0

OTOH它似乎没有区别。请参阅[在此页面上]的注释(http://www.berezniker.com/content/pages/visual-foxpro/enumerating-printer-forms),我可以在这里验证并且网络上有线程数量相同。简而言之,如果您想获得特定打印机支持的列表,请勿使用'EnumForms',请使用'DeviceCapabilities'。 –

2

您可以使用EnumForms和查询本地打印服务器来获取纸张大小列表。看this question

1

你为什么不使用默认的打印机设置对话框?

链接如下处理到OnAccept事件TFilePrintSetup行动:

procedure TForm1.FilePrintSetup1Accept(Sender: TObject); 
var 
    Scale: Single; 
begin 
    Scale := Printer.PageHeight/Printer.PageWidth; 
    DesignerPanel.Height := Round(DesignerPanel.Width * Scale); 
end; 

等瞧。