2015-02-09 63 views
0

什么库(Debenu,Gnostic,其他?)允许我从数据库nad中读取文本,然后将其插入到pdf文件中,但是使用分页?例如,我在数据库中有1000行,但只有一个A4页面只适合250行,所以我需要4页,而不是一个小字体...Delphi pdf生成 - 分页

是否可以在发送文本之前确定文本的高度?

回答

0

如果您使用的是Gnostice eDocEngine,那么您可以使用PDF引擎的AutoPaginate属性自动创建额外的页面。您可以使用常规的Delphi类从数据库中读取记录,然后开始写入PDFEngine中的页面,当页面中的空间不足时,PDFEngine将自动生成一个新页面并容纳您的文本输出。您可以选择任何页面大小。

enter image description here

这个例子已经直接取自帮助文件。

{ 
    This example illustrates autopagination and the use of 
    built-in and custom placeholders. 

    Drag a button component and a PDF engine component 
    on a form. Double-click the button and use the 
    following code for the click-event procedure. 
} 

procedure TForm3.Button1Click(Sender: TObject); 
var 
i: Integer; 
begin 

    with gtPDFEngine1 do begin 
    FileName := 'autopagination_placeholders_demo.pdf'; 
    Font.Size := 16; 
    Font.Name := 'Times New Roman'; 
    TextFormatting.LineSpacing := 2; 

    // Enable autopagination 
    AutoPaginate := true; 

    // Ensure all text placeholders are replaced at run-time 
    Preferences.CalculateVariables := true; 

    // Render pages after processing all instructions 
    Preferences.ProcessAfterEachPage // Required for generating values 
     := false;     // for built-in placeholders 

    // Specify event handler for placeholder substitution events 
    OnCalcVariables := gtPDFEngine1CalcVariablesEventHandler; 

    BeginDoc; 
    for i := 1 to 50 do begin 
     // Render paragraph containing built-in and custom placeholders 
     BeginPara; 
     Textout('Hello, world! - on page #' + 
       CphPageNo + ' of ' + CphTotalPages + 
       ' - Random #<%my_random_number_placeholder%>'); 
     EndPara; 
    end; 
    EndDoc; 
    end; 
    Close; 

end; 

// Event handler that gets called whenever a placeholder is substituted. 
procedure TForm3.gtPDFEngine1CalcVariablesEventHandler(
         Sender: TgtCustomDocumentEngine; 
         Variable: String; 
         var Value: String); 
begin 
    // Provide a value for the custom placeholder 
    if Variable = 'my_random_number_placeholder' then begin 
    Value := FloatToStr(Random); 
    end; 
end;