Print Page | Close Window

MERGING 2 or MORE PDF FIles into ONE PDF File

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=2391
Printed Date: 28 Sep 24 at 11:03PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: MERGING 2 or MORE PDF FIles into ONE PDF File
Posted By: isyscorp
Subject: MERGING 2 or MORE PDF FIles into ONE PDF File
Date Posted: 30 Aug 12 at 1:38AM
Hi Guys,

Been browsing all the forums and Delphi programmers discussions how to merge 2 or more PDF files into one PDF File. I finally found this Quick PDF Library, interesting BUT I can't really make it to work. Here's a code from Rowan, kindly help where's my mistake?

USES ***QuickPDF0816;

function MergeStreamsViaMergeDocument(FirstStream, SecondStream,
    OutputStream: TMemoryStream): Integer;
  var
    doc1, doc2: Integer;
  begin
    with TQuickPDF.Create do
    try
      FirstStream.Seek(0, soFromBeginning);
      LoadFromStream(FirstStream);
      doc1 := SelectedDocument;
      SecondStream.Seek(0, soFromBeginning);
      LoadFromStream(SecondStream);
      doc2 := SelectedDocument;
      SelectDocument(doc1);
      MergeDocument(doc2);
      OutputStream.Seek(0, soFromBeginning);
      SaveToStream(OutputStream);
    finally
      Free;
    end;
  end;


I got the error message "Not Enough Parameters" at line "LoadFromStream(FirstStream);"

Thank you for your help,
Vid



Replies:
Posted By: AndrewC
Date Posted: 30 Aug 12 at 7:31AM
A quick read of the "Quick PDF Library 8.16 Reference Guide.pdf" will reveal that LoadFromStream also requires a password parameter as of QPL 8.xx.  The PDF file can be found in the Quick PDF installation directory.

http://www.quickpdflibrary.com/help/quickpdf/LoadFromStream.php - http://www.quickpdflibrary.com/help/quickpdf/LoadFromStream.php

  LoadFromStream(FirstStream, Password);  // add the password parameter - can be blank ie. ""

The Demo code was originally written for QPL 7.xx.  The changes between 7.xx and 8.xx are documented in the "Quick PDF Library 8 Upgrade Warnings.pdf" which is also in the QuickPDF installation directory.

It would also be helpful to know what development system you are using.

Andrew.


Posted By: isyscorp
Date Posted: 31 Aug 12 at 12:14AM
Thanks much Andrew. Trying now... :)


Posted By: isyscorp
Date Posted: 31 Aug 12 at 12:20AM
Hi Andrew, what command should i put inside a BUTTON?

Example: MergeStreamsViaMergeDocument(<pdf1>, <pdf2>,<pdfresult>).

Thanks...
Vid


Posted By: AndrewC
Date Posted: 31 Aug 12 at 10:14AM

I would suggest you have a read of the 'Quick PDF Library 8 Developer Guide.pdf' file which is installed in the Quick PDF installation directory.

Page 26 shows some sample code using files and calling MergeDocument.  It would be much easier using files than memorystreams to start with.

You would add this code into a Delphi procedure 

   procedure MergePDFFiles(firstDoc, secondDoc, DestFileName: Ansistring);

and then in your button code you would add 

  MergePDFFiles("file1.pdf", "file2.pdf", "output.pdf");



Posted By: isyscorp
Date Posted: 02 Sep 12 at 5:06AM
Hi Andrew, got no luck.. :(

Do you have a sample program to merge two or more files? Really appreciate it... I got the Quick PDF Library installed to my GUI already. Thank you...

Vid


Posted By: Wheeley
Date Posted: 02 Sep 12 at 6:40AM
Have you bothered to read to function documentation? It's all there for you.So for > 2 files do this (no I am not going to give you actual code. We all struggled through this and nothing good n life comes free)

AddToFileList (myfiles,1.pdf)
AddToFileList (myfiles,2.pdf)
AddToFileList (myfiles,3.pdf)
mergefilelist(myfiles,combined.pdf)

Wheeley
Lamp



Posted By: AndrewC
Date Posted: 02 Sep 12 at 7:00AM
Vid,

Are you asking how to merge 2 or more files or are you asking help to create a Delphi program using Quick PDF Library ?

The QPL code to merge files is pretty simple

        QP.ClearFileList("test");
        QP.AddToFileList("test", "1-1805B663 data.pdf");
        QP.AddToFileList("test", "1805B results.pdf");
        QP.AddToFileList("test", "som0102a.pdf");
        QP.AddToFileList("test", "c3639-03DL.pdf");
        QP.AddToFileList("test", "c3639-04.pdf");
        QP.MergeFileList("test", "merged.pdf");

Here is some pretty basic delphi code that attaches the code the Delphi button. 

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ShellApi,
  Dialogs, QuickPDF0816, StdCtrls, ExtCtrls, RichEdit, ToolWin, ComCtrls, Printers;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  QP: TQuickPDF;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin

  QP := TQuickPDF.Create;
  QP.UnlockKey('<paste your license key here');   // <<<<<<<<<<<<<  Paste your key here before compiling

  SetCurrentDirectory('f:\downloads');
  QP.SetTempPath('F:\Downloads');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  DeleteFile('merged.pdf');
  QP.ClearFileList('test');

  QP.AddToFileList('test', 'f:\downloads\out.pdf');
  QP.AddToFileList('test', 'f:\downloads\out2.pdf');

  QP.MergeFileList('test', 'f:\downloads\merged.pdf');

  ShellExecute(hinstance,'open',PChar('merged.pdf'),nil,nil,SW_SHOWNORMAL);
end;

end.




Posted By: isyscorp
Date Posted: 02 Sep 12 at 9:30AM
Thank Andrew, the program seems running with no errors... I am just wondering it cannot generate an output file.
I changed the folder locations with two pdf files in it:
c:\Temp\pdf1.pdf
c:\Temp\pdf2.pdf

procedure TForm1.FormCreate(Sender: TObject);
begin

  QP := TQuickPDF.Create;
  QP.UnlockKey('<paste your license key here');   // <<<<<<<<<<<<<  Paste your key here before compiling

  SetCurrentDirectory('c:\Temp');
  QP.SetTempPath('c:\Temp');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin

  DeleteFile('merged.pdf');
  QP.ClearFileList('test');

  QP.AddToFileList('test', 'c:\Temp\pdf1.pdf');
  QP.AddToFileList('test', 'c:\Temp\pdf2.pdf');

  QP.MergeFileList('test', 'c:\Temp\merged.pdf');

  ShellExecute(hinstance,'open',PChar('merged.pdf'),nil,nil,SW_SHOWNORMAL);
end;

end.

========= Thank again...
Vid


Posted By: AndrewC
Date Posted: 02 Sep 12 at 9:37AM
Did you paste your license key into the line that says 

  QP.UnlockKey('<paste your license key here');   // <<<<<<<<<<<<<  Paste your key here before compiling

It will need to look something like this

  QP.UnlockKey('5hk4gh65ghk52ghkg3hj4e3');    // This is an invalid key.


We should also be checking the return value.

..
var

  ret: Integer;

...
...

  ret := QP.UnlockKey('5hk4gh65ghk52ghkg3hj4e3'); 

  if (ret <> 1)
      ShowMessage("Quick PDF Library has not been unlocked - Please check the license key");

Andrew
    



Posted By: isyscorp
Date Posted: 02 Sep 12 at 9:45AM
Yes I did, 

I have a licensed one and added to my code, but when i added VAR RET, i now received an INVALID license key...

Thanks much,
Vid 


Posted By: AndrewC
Date Posted: 02 Sep 12 at 10:10AM

Please create an official support case at  http://www.quickpdflibrary.com/support/support-query.php - http://www.quickpdflibrary.com/support/support-query.php  and when you receive a ticket number reply to the email and attach your latest source code (including your license key) and also attach the two PDF files you are trying to merge.

Andrew.


Posted By: isyscorp
Date Posted: 02 Sep 12 at 10:55AM
Hi Andrew!!! Ha ha thank you... it works now... whew... you really made my day. Thanks you so much!

Vid :)



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