|
Hi Edgar,
Let me share several helping functions that allow to manage such a template documents.
function CreateDocumentTemplate(QPL: TQuickPDF; PageRangeList: AnsiString): AnsiString; var tempdoc, olddoc: Integer; begin with QPL do begin olddoc := SelectedDocument; tempdoc := NewDocument; CopyPageRanges(olddoc, PageRangeList); DeletePages(1, 1); Result := SaveToString; RemoveDocument(tempdoc); SelectDocument(olddoc); end; end;
procedure MergeDocumentTemplate(QPL: TQuickPDF; DocumentTemplate: AnsiString); var tempdoc, olddoc: Integer; begin with QPL do begin olddoc := SelectedDocument; LoadFromString(DocumentTemplate); tempdoc := SelectedDocument; SelectDocument(olddoc); MergeDocument(tempdoc); end; end;
procedure SaveDocumentTemplate(DocumentTemplate: AnsiString; FileName: AnsiString); begin with TQuickPDF.Create do try LoadFromString(DocumentTemplate); SaveToFile(FileName); finally Free; end; end;
function LoadDocumentTemplate(FileName: AnsiString): AnsiString; begin with TQuickPDF.Create do try LoadFromFile(FileName); Result := SaveToString; finally Free; end; end;
// Some samples of how to use this helping functions
var
doctemplate: AnsiString;
// Create PDFLibrary instance and load some PDF
// Lets make some template from pages defined in PageRangeListEdit: TEdit;
doctemplate := CreateDocumentTemplate(PDFLibrary, PageRangeListEdit.Text);
// . . .
// Here template is merged to the currently selected document of PDFLibrary
MergeDocumentTemplate(PDFLibrary, doctemplate);
// . . .
// Save template as PDF file
with TSaveDialog.Create(nil) do try if not Execute then Exit; DefaultExt := '.pdf'; SaveDocumentTemplate(doctemplate, FileName); finally Free; end;
// . . .
// Load template from some PDF file
with TOpenDialog.Create(nil) do try if not Execute then Exit; DefaultExt := '.pdf'; doctemplate := LoadDocumentTemplate(FileName); finally Free; end;
------------- Regards,
Dmitry
|