2015-02-09 233 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;