2017-08-31 9 views
-1

Ich habe einen TRichEditView mit formatierten Text in der es, wie folgt aus:Export formatierten Text pdf

 
**Header** 

**paragraph 1 title** 
__________________ 
paragraph 1 line 1 
paragraph 1 line 2 
paragraph 1 line 3 

**paragraph 2 title** 
__________________ 
paragraph 2 line 1 
paragraph 2 line 2 
paragraph 2 line 3 

ich den Text in eine PDF-Datei exportiert werden soll.

Derzeit verwendet das Projekt PDFLibrary mit dem Zeichnen jeder Seite in der PDF-Datei, aber wenn die Anzahl der Zeilen etwa 9000 ist, dann dauert es lange, 15 Minuten zu exportieren.

Ich arbeite an der Erstellung der PDF-Datei Zeile für Zeile, aber ich frage mich, ob es eine schnellere Möglichkeit gibt, formatierten Text in PDF zu konvertieren?

Dies ist ein Teil des Codes, die ich zu exportieren versuchen:

var 
    pdfLibrary: TDebenuPDFLibrary; 
begin 
    ... 
    pdfLibrary.SetInformation(5, '---'); // Creator 
    pdfLibrary.SetMeasurementUnits(2);   // Inches 
    pdfLibrary.SetOrigin(1);      // Top left 
    pdfLibrary.CompressImages(1);    // Flate compression 
    pdfLibrary.CompressFonts(1);     // Compress all subsequently added fonts 
    pdfLibrary.SetPageSize('A4'); 

    // Set current page size. This will be inherited for new pages 
    pdfLibrary.SetPageDimensions(pageSetup.Size.Width, pageSetup.Size.Height); 

    marginRect.Create(0, 0, 
    trunc(pageSetup.Size.Width * TResolutionHelper.STANDARD_WINDOWS_DPI), 
    trunc(pageSetup.Size.Height * TResolutionHelper.STANDARD_WINDOWS_DPI)); 

    cntr := 0; 
    fontID := pdfLibrary.AddStandardFont(5); 
    while cntr < 1 do //for now just do for first line 
    begin 
    if cntr > 1 then 
     if pdfLibrary.NewPage = 0 then 
     raise Exception.Create(format('%d page cannot be added', [cntr])); 

     //pdfLibrary.SelectFont(fontID); 
     pdfLibrary.SetTextSize(RVStyle1.TextStyles[1].SizeDouble); 
     pdfLibrary.SelectPage(0); 

     x := (pdfLibrary.PageWidth/2) - pdfLibrary.GetTextWidth(tseHeader.GetItemText(0)); 
     pdfLibrary.DrawText(x, 0.5, tseHeader.GetItemText(0)); 

     inc(cntr); 
    end; 
    ... 
end; 

jetzt rechts wird die SetTextAlign() nicht ausgerichtet wird, und das dauert eine lange Zeit zu beenden. Ich suche nach etwas, das mehr Sinn macht.

+0

meine eigentliche Code ist in einem großen Projekt, wenn ich hier etwas zeigen wollen, dass Seance mache ich fast die Hälfte des Projekts zeigen –

+1

Bitte geben Sie einen [MCVE ] das das gleiche Problem reproduziert. Ohne Code kann Ihnen niemand sagen, ob Sie etwas falsch machen. –

+0

Ich bin auf der Suche nach einer anderen Lösung nicht Code-Korrektur, ich frage mich, ob jemand versucht, das gleiche zu tun –

Antwort

0

ist diese Art mein Problem zu lösen

procedure TfrmDemo.Button1Click(Sender: TObject); 
var 
    I: Integer; 
    QP: TDebenuPDFLibrary; 
    X: Integer; 
    footer: string; 
    footerHeight: double; 
    textHeight: double; 
begin 
    dlgSave.FileName := 'Rotated.pdf'; 
    if dlgSave.Execute then 
    begin 
    QP := TDebenuPDFLibrary.Create; 
    try 
     if QP.UnlockKey(edtLicenseKey.Text) = 1 then 
     begin 
     footer := 'footer is here!'; 
     QP.AddStandardFont(8); 
     footerHeight := QP.GetTextHeight; 

     // Set the paper size 
     QP.SetPageSize('A4'); 

     // Set the origin to the top-left corner 
     QP.SetOrigin(1); 

     // Set the measurement units to millimetres 
     QP.SetMeasurementUnits(1); 

     // Add a standard font 
     QP.AddStandardFont(11); // Times Roman Bold Italic 

     QP.SetTextSize(10); 

     QP.SetTextAlign(1); 

     I := 0; 
     textHeight := QP.GetTextHeight; 
     while 10 + (textHeight * I) < qp.PageHeight - footerHeight - textHeight do 
     begin 
      QP.DrawText((qp.PageWidth/2) , 10 + (textHeight * I), 
      '1 Quick PDF Library, Quick PDF Library, Quick PDF Library, Quick PDF Library, Quick PDF Library'); 
      inc(I); 
     end; 

     qp.DrawLine(10, 10 + (textHeight * I), qp.PageWidth - 10, 10 + (textHeight * I)); 
     inc(I); 

     QP.AddStandardFont(8); 
     QP.SetTextSize(8); 
     QP.DrawText((qp.PageWidth/2) , 10 + (textHeight * I), footer); 

     // Compress the contents of the file 
     QP.CompressContent; 

     // Save the file 
     QP.SaveToFile(dlgSave.FileName); 
     end else 
     MessageDlg('The license key is invalid or has expired.', mtError, [mbOK], 0); 
    finally 
     QP.Free; 
    end; 
    end; 
end;