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!
Using MergeFiles in Delphi |
Post Reply |
Author | |
TomInJax
Beginner Joined: 14 Nov 12 Location: North Florida Status: Offline Points: 7 |
Post Options
Thanks(0)
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".
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 |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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. |
|
TomInJax
Beginner Joined: 14 Nov 12 Location: North Florida Status: Offline Points: 7 |
Post Options
Thanks(0)
|
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 |
|
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
|
The library fully support spaces in file names so it could be something else ? Andrew.
|
|
TomInJax
Beginner Joined: 14 Nov 12 Location: North Florida Status: Offline Points: 7 |
Post Options
Thanks(0)
|
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; |
|
TomInJax
Beginner Joined: 14 Nov 12 Location: North Florida Status: Offline Points: 7 |
Post Options
Thanks(0)
|
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!!! Tom Edited by TomInJax - 15 Nov 12 at 3:33PM |
|
TomInJax
Beginner Joined: 14 Nov 12 Location: North Florida Status: Offline Points: 7 |
Post Options
Thanks(0)
|
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; |
|
Wheeley
Senior Member Joined: 30 Oct 05 Location: United States Status: Offline Points: 146 |
Post Options
Thanks(0)
|
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 |
|
TomInJax
Beginner Joined: 14 Nov 12 Location: North Florida Status: Offline Points: 7 |
Post Options
Thanks(0)
|
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! (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 |
|
lcap
Beginner Joined: 14 Dec 13 Location: 36 Status: Offline Points: 2 |
Post Options
Thanks(0)
|
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 |
|
tfrost
Senior Member Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
Post Options
Thanks(0)
|
TDocumentprops looks like a class in the OP's own program. The parameters for the Debenu MergeFiles function (look them up) are simple strings.
|
|
TomInJax
Beginner Joined: 14 Nov 12 Location: North Florida Status: Offline Points: 7 |
Post Options
Thanks(0)
|
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 |
|
lcap
Beginner Joined: 14 Dec 13 Location: 36 Status: Offline Points: 2 |
Post Options
Thanks(0)
|
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?
|
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
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 |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store