Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Using MergeFiles in Delphi
  FAQ FAQ  Forum Search   Register Register  Login Login

Using MergeFiles in Delphi

 Post Reply Post Reply
Author
Message
TomInJax View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Nov 12
Location: North Florida
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote TomInJax Quote  Post ReplyReply Direct Link To This Post Topic: Using MergeFiles in Delphi
    Posted: 14 Nov 12 at 8:53PM
I hope that this is an easy one to help me with, but I seem to not be using the MergeFiles function properly.  The error that is reported is "Could not open output file".  Embarrassed

What I wish to do, is to merge several PDF documents into a large PDF - but not remove or alter the original documents.  I pass the two names of the original documents in, and pass the full path including filename of the document that I would like to create as the result.

Can someone post a sample of this?  I don't need any bookmarks, annotations, etc.  Just the plain PDF documents merged.

Thanks in advance!
Tom

Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 14 Nov 12 at 10:04PM
Hi Tom!

"...Could not open output file..."
This sounds like some probs in your code structure
about what comes first and what comes last.
But we can't look inside the glass ball ...
perhaps it's better to post your relevant code parts here?

Cheers and welcome here,
Ingo

BTW: For merge there's a sample on the official support pages.

Back to Top
TomInJax View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Nov 12
Location: North Florida
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote TomInJax Quote  Post ReplyReply Direct Link To This Post Posted: 14 Nov 12 at 11:58PM
I found the problem.  It seems that if the path as spaces in it, then there is a problem with saving the document.  I am now using a simple path with no spaces and everything is working.

Tom
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 15 Nov 12 at 10:17AM
The library fully support spaces in file names so it could be something else ? 

Can you post a small code sample and tell us which compiler / tool you are using ?

Andrew.
Back to Top
TomInJax View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Nov 12
Location: North Florida
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote TomInJax Quote  Post ReplyReply Direct Link To This Post Posted: 15 Nov 12 at 12:15PM
Thanks Andrew.  Here is the actual test code that I am using.  I added a tab to the demo project for this.

I am using version 8.15 (Source Code License), Delphi XE, on Windows XP.

The functionality is this:

1. "Add" button adds a file name to the TListbox (lstDocs), which also has an object with more properties (full path including filename).
2. A temporary file folder and file name is selected in a Filename Edit control (edtTmpFile.Text).  This will be the merged document.
3. Save button is the event sample code.  It reads the full path and passes it into the MergeFiles function, along with the path for the merged document.  It iterates through the list and concatenates the documents together.

The GetErrorMessage function decodes the error number, translating it to the error text.

Here is the code:

procedure TfrmDemo.btnSaveDocClick(Sender: TObject);
var
  x: integer;
  QP: TQuickPDF;
  tempFileName: string;
begin
  if (lstDocs.Items.Count > 0) then
  begin
    QP := TQuickPDF.Create;

    // Concatenate Documents to one big PDF document
    try
      tempFileName := TDocumentProps(lstDocs.Items.Objects[0]).FullPath;
      for x := 1 to lstDocs.Items.Count - 1 do
      begin
        if QP.MergeFiles(tempFileName, TDocumentProps(lstDocs.Items.Objects[x]).FullPath, edtTmpFile.Text) = 0 then
          ShowMessage(GetErrorMessage(QP.LastErrorCode));

        tempFileName := edtTmpFile.Text;
      end;
    finally
      QP.Free;
    end;
  end;
end;

Tom


Back to Top
TomInJax View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Nov 12
Location: North Florida
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote TomInJax Quote  Post ReplyReply Direct Link To This Post Posted: 15 Nov 12 at 1:03PM
I found the problem.  The filename edit component that I am using is adding double quotes to the beginning and end of the filename. 

Sorry!  D'Oh!!! Embarrassed

Tom


Edited by TomInJax - 15 Nov 12 at 3:33PM
Back to Top
TomInJax View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Nov 12
Location: North Florida
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote TomInJax Quote  Post ReplyReply Direct Link To This Post Posted: 15 Nov 12 at 1:26PM
Ok, there must be a simpler method to concatenate several PDF documents than the way I am doing it.  This code creates a result document with a number added to the filename.  This seems to be necessary since the MergeFiles function cannot merge into the same document it is concatenating to.  The oldest temporary file is removed, then the final document is renamed to the document that was selected by the user in the FilenameEdit control.

This test code is limited to 10 documents, otherwise the code breaks.

Code:
procedure TfrmDemo.btnSaveDocClick(Sender: TObject);
var
  x: integer;
  QP: TQuickPDF;
  tempFileName: string;
begin
  if (lstDocs.Items.Count > 0) then
  begin
    QP := TQuickPDF.Create;
    tempFileName := TDocumentProps(lstDocs.Items.Objects[0]).FullPath;
    try
      for x := 1 to lstDocs.Items.Count - 1 do
      begin

      // Concatenate Documents to one big PDF document
        begin
          if QP.MergeFiles(tempFileName, TDocumentProps(lstDocs.Items.Objects[x]).FullPath, Copy(edtTmpFile.Text,1,POS('.PDF',ToUpper(edtTmpFile.Text))-1)+IntToStr(x)+'.PDF') = 0 then
            ShowMessage(GetErrorMessage(QP.LastErrorCode));

          tempFileName := Copy(edtTmpFile.Text,1,POS('.PDF',ToUpper(edtTmpFile.Text))-1)+IntToStr(x)+'.PDF';

          //  Delete old file
          if FileExists(Copy(edtTmpFile.Text,1,POS('.PDF',ToUpper(edtTmpFile.Text))-1)+IntToStr(x-1)+'.PDF') then
            DeleteFile(Copy(edtTmpFile.Text,1,POS('.PDF',ToUpper(edtTmpFile.Text))-1)+IntToStr(x-1)+'.PDF');
        end;
      end;
    finally
      QP.Free;
      RenameFile(Copy(edtTmpFile.Text,1,POS('.PDF',ToUpper(edtTmpFile.Text))-1)+IntToStr(x-1)+'.PDF',edtTmpFile.Text);
    end;
  end;
end;

Back to Top
Wheeley View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 Oct 05
Location: United States
Status: Offline
Points: 146
Post Options Post Options   Thanks (0) Thanks(0)   Quote Wheeley Quote  Post ReplyReply Direct Link To This Post Posted: 15 Nov 12 at 11:26PM
I would suggest using MergeFilesFast. You still have the can't merge into the same file problem, but you can use file lists and merge everything in one command. Just make sure the files are not encrypted before merging. Search the forums for merge. I gave some pseudo code before on this method.

Wheeley
Back to Top
TomInJax View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Nov 12
Location: North Florida
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote TomInJax Quote  Post ReplyReply Direct Link To This Post Posted: 16 Nov 12 at 1:33AM
Thanks Wheely,

That code looks much easier and simpler.  I will try in in my test app tomorrow. 

Now I will know a couple ways to merge a PDF document together! Big smile  (Yes I read the documentation, but example code is always much easier to understand)

I appreciate you, Ingo, and AndrewC taking time to assist me so quickly.  If any of you ever come to North Florida, I will be happy to buy a glass of your favorite drink for you.

Cheers,
Tom
Back to Top
lcap View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Dec 13
Location: 36
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote lcap Quote  Post ReplyReply Direct Link To This Post Posted: 14 Dec 13 at 1:04PM
Sorry, I was testing the code, but does not identify "TDocumentProps", which unit or library I have to import. In the unit have now uses QuickPDF .... and recognized all other commands or less "TDocumentProps".

Can you help me?

Edited by lcap - 14 Dec 13 at 1:04PM
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 15 Dec 13 at 11:30AM
TDocumentprops looks like a class in the OP's own program.  The parameters for the Debenu MergeFiles function (look them up) are simple strings.
Back to Top
TomInJax View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Nov 12
Location: North Florida
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote TomInJax Quote  Post ReplyReply Direct Link To This Post Posted: 15 Dec 13 at 7:57PM
Originally posted by lcap lcap wrote:

Sorry, I was testing the code, but does not identify "TDocumentProps", which unit or library I have to import. In the unit have now uses QuickPDF .... and recognized all other commands or less "TDocumentProps".

Can you help me?

As TFrost said, TDocumentProps is an object that I create that is used in each item with additional properties.  In this case:

TDocumentProps(lstDocs.Items.Objects[x]).FullPath
translates to the full filepath to the file.  It contains something like this: c:\documents\doc3.pdf. 
Sorry for not simplifying my code at the time to make a better example.

Cheers,
Tom
Back to Top
lcap View Drop Down
Beginner
Beginner
Avatar

Joined: 14 Dec 13
Location: 36
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote lcap Quote  Post ReplyReply Direct Link To This Post Posted: 08 Feb 14 at 6:13PM
I can unify one imagems file "teste.jpg" + * file. pdf "test.pdf" and turn into a big pdf file "1_teste.pdf" unified with debenu?
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 11 Feb 14 at 7:46AM
Hi Icap!
 
Yes! You can ;-)
But first you have to convert the image into pdf (this you can do with QP, too).
Then you can merge both pdf to one new big pdf.
Have a look at the merge-functions here:
 
Cheers and welcome here,
Ingo
 
Cheers,
Ingo

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store