with this source:
procedure TForm17.mergepdf(fname: string; lf:tlistapdf);
var f : string;
i, k: integer;
begin
with PDFlib1 do
begin
k := 0;
BeginDocument(dirdoc + fname);
for f in lf do
begin
OpenDocument(dirdoc + f);
for i := 1 to GetPageCount do
begin
GetPageInfo(i + k);
Footer := 'Page 1 / 2';
NewPage;
DrawPage(i);
end;
inc(k);
end;
NewPage;
EndDocument;
CloseDocument;
end;
end;
the new pdf content only the first pdf.
how merge more pdf?
Pieter
(Pieter)
February 24, 2014, 2:49am
2
Hi,
We have tested this here with the following code, input of three PDF files added from the deployment window and output in the documents folder in a "Merged.pdf" file and all three PDF files are added.
var
input: TStringList;
output: String;
I, J: Integer;
begin
input := TStringList.Create;
input.Add(ExtractFilePath(ParamStr(0)) + 'Egypt.pdf');
input.Add(ExtractFilePath(ParamStr(0)) + 'BoraBora.pdf');
input.Add(ExtractFilePath(ParamStr(0)) + 'London.pdf');
output := TPath.GetDocumentsPath + '/Merged.pdf';
TMSFMXNativePDFLib1.BeginDocument(output);
for I := 0 to input.Count - 1 do
begin
TMSFMXNativePDFLib1.OpenDocument(input);
for J := 1 to TMSFMXNativePDFLib1.GetPageCount do
begin
TMSFMXNativePDFLib1.GetPageInfo(J);
TMSFMXNativePDFLib1.NewPage;
TMSFMXNativePDFLib1.DrawPage(J);
end;
TMSFMXNativePDFLib1.CloseDocument;
end;
TMSFMXNativePDFLib1.EndDocument;
input.Free;
I see GetPageInfo(i+K) is incorrect and should be GetPageInfo(I); CloseDocument should happen for each OpenDocument. EndDocument is paired with BeginDocument.
Kind Regards,
Pieter