Print Page | Close Window

template

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1714
Printed Date: 25 Jan 26 at 7:19PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: template
Posted By: eborger
Subject: template
Date Posted: 19 Jan 11 at 8:50PM
Hi, 

I want to use a previously created pdf as a "template", but I don't know the number of pages the final pdf is going to be, I have an empty invoice that I want to use as template, so I want to create a new document, add a page, fill it with the template, and then add data, and do this for as many pages as I want. Is there an easy way of doing it ?
I am trying with capturepage/drawcapturedpage, but it is not working, any hints ?

this is basicaly what I am doing :

"SaveToFile", "tmpfile.pdf" 

"LoadFromFile",  "template.pdf" 
"CombineLayers"
"NewPage"
  capt := "CapturePage", 1 

"LoadFromFile", "tmpfile.pdf" 
"NewPage"
"DrawCapturedPage", capt

thank you,
Edgar



Replies:
Posted By: darkv
Date Posted: 19 Jan 11 at 10:56PM
Edgar,

I've done the same with a blank template file (where after treatment i add page numbering)

1) what i've done is :
 
loadfile blank template
fill in with data until page is full,
When  page is full call new page and fill it again

once no more data to write,  i use an internal page counter to add page numbering

and then Savetofile

it works perfectly to generate a logfile report for roughly 3000 lines

2) Other way should be to previously calculate the number of pages you will need, use clonepages and fill in

Hope this helps,

if you need i can post part of my code (vb.net)

Rgds
Eric



Posted By: Dimitry
Date Posted: 21 Jan 11 at 10:59PM
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
  PDFLibrary: TQuickPDF;
  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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk