PDFLibrary.MergeDocument failed: 0
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=1195
Printed Date: 12 Dec 25 at 6:17AM Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com
Topic: PDFLibrary.MergeDocument failed: 0
Posted By: Yadutt
Subject: PDFLibrary.MergeDocument failed: 0
Date Posted: 01 Sep 09 at 3:40PM
Hello, Can someone please help me. I'm getting the error -2147221504 (80040000) when trying to merge document. It seems that this error is happing when there are huge number of pages being merged.
Your help would be much appreciated.
Thank you.
|
Replies:
Posted By: Ingo
Date Posted: 01 Sep 09 at 4:47PM
Hi!
It's always important to know which version of the library you're using. What is a "huge number" ;-) Sorry but these error tells nothing. Perhaps the pdf is protected - so merging isn't possible? You can post a code snippet (please without your regkey ;-)
Cheers, Ingo
|
Posted By: Yadutt
Date Posted: 01 Sep 09 at 4:51PM
Version : QuickPDF Library 7.14 Number of Pages: 58 IDE Visual Basic 6
Thanks
|
Posted By: Yadutt
Date Posted: 01 Sep 09 at 4:53PM
' Load source PDF If mobjPDFLib.LoadFromFile(sFileName) = 0 Then Err.Raise vbObjectError, , "PDFLibrary.LoadFromFile failed: " & mobjPDFLib.LastErrorCode & _ " Filename: " & sFileName End If lSourcePDFID = mobjPDFLib.GetDocumentID(mobjPDFLib.DocumentCount) mobjPDFLib.NewPage mobjPDFLib.NewPage ' Select main document mobjPDFLib.SelectDocument mlCurrDocument ' Merge source PDF If mobjPDFLib.MergeDocument(lSourcePDFID) = 0 Then Err.Raise vbObjectError, , "PDFLibrary.MergeDocument failed: " & mobjPDFLib.LastErrorCode & _ " CurrentDocument:" & mlCurrDocument & _ " DocumentCount:" & mobjPDFLib.DocumentCount & _ " Filename:" & sFileName End If ' Select the source page mobjPDFLib.SelectPage mlCurrPage + lPageNo ' Store page size lNewWidth = mobjPDFLib.GetPageBox(2, 2) '' PageWidth lNewHeight = mobjPDFLib.GetPageBox(2, 3) '' PageHeight ' Select the work page mobjPDFLib.SelectPage mlCurrPage ' Capture the page lCaptureID = mobjPDFLib.CapturePageEx(mlCurrPage + lPageNo, 1) If lCaptureID = 0 Then Err.Raise vbObjectError, , "PDFLibrary.CapturePage failed: " & mobjPDFLib.LastErrorCode End If mobjPDFLib.SelectPage mlCurrPage ' Resolve the coordinates ResolveCoordinates lLeft, lTop, lWidth, lHeight, lHorAlign, lVertAlign, _ lNewLeft, lNewTop, lNewWidth, lNewHeight ' Draw the captured page If mobjPDFLib.DrawCapturedPage(lCaptureID, lNewLeft, lNewTop, lNewWidth, lNewHeight) = 0 Then Err.Raise vbObjectError, , "PDFLibrary.DrawCapturedPage failed: " & mobjPDFLib.LastErrorCode End If ' Delete any extra pages mobjPDFLib.DeletePages mlCurrPage + 1, mobjPDFLib.PageCount - mlCurrPage mobjPDFLib.SelectPage mlCurrPage ' Return new coordinates lLeft = lNewLeft lTop = lNewTop lWidth = lNewWidth lHeight = lNewHeight
|
Posted By: Ingo
Date Posted: 01 Sep 09 at 6:43PM
|
Hi!
Here's a sample that works:
Here is a sample about how to merge two files: QP := TQuickPDF712.Create; try QP.UnlockKey('MyKey'); fa1 := FileGetAttr(Trim(starting_file)); FileSetAttr(Trim(starting_file), faArchive); QP.LoadFromFile(starting_file); QP.Unencrypt; msd := QP.SelectedDocument; fa2 := FileGetAttr(Trim(next_file)); FileSetAttr(Trim(next_file), faArchive); QP.LoadFromFile(next_file); QP.Unencrypt; md0 := QP.SelectedDocument; QP.SelectDocument(msd); QP.MergeDocument(md0); QP.SetInformation(0,'1.4'); //erforderliche PDF-Version QP.SetInformation(5,'My Super App'); //Creator QP.SetInformation(6,'The fantastic QuickPDF'); //Producer QP.SaveToFile(The_new_file);
finally QP.RemoveDocument(msd); FileSetAttr(Trim(starting_file), fa1); FileSetAttr(Trim(next_file), fa2); QP.Free; end;
BTW: I've copied it from one of my posts here from 6th of july this year. Why you don't use the search function above?
Cheers and good luck,
Ingo
|
Posted By: Yadutt
Date Posted: 02 Sep 09 at 9:47AM
Hello Ingo, Thanks for your reply. Much appreciated.
The problem I'm encountering is not that I'm having no success in merging document, but rather the number of documents.
The Quick PDF works well when there are few pages to merge, but seems to consistently fail when the number of pages increase. I've not been able to establish as to what point it fails ( i.e. number of pages when increment), I've 58 pages or files that I would like to merge into one document.
Thanks.
|
Posted By: Ingo
Date Posted: 02 Sep 09 at 9:58AM
Hi!
Normally the current version of QuickPDF shouldn't have problems with larger files. With my posted code i've merged up to ten files and each file up to 70 mb (all together round about 220 mb). Sometimes it's not only the merge... also loading these big files costs time. 58 pages doesn't mean much... this can be 500 kb or 50 mb ;-) Perhaps here's another reader who wants to share his experiences in this case with us?
Cheers, Ingo
|
Posted By: Yadutt
Date Posted: 03 Sep 09 at 2:27PM
This is how I've fixed the problem and it works fine
If (stsOldFileName <> sFileName) Then ' New file is being loaded stsOldFileName = sFileName ' Remove if any previous source file loaded document id mobjPDFLib.RemoveDocument stlLoadedSourceDocId ' Do we have success loading file in question ? If mobjPDFLib.LoadFromFile(sFileName) = 0 Then stsOldFileName = vbNullString Err.Raise vbObjectError, , "PDFLibrary.LoadFromFile failed: " & mobjPDFLib.LastErrorCode & _ " PageNo:" & lPageNo & " Filename: " & sFileName End If ' Set focus on loaded new document stlLoadedSourceDocId = mobjPDFLib.SelectedDocument End If
'Select the document mobjPDFLib.SelectDocument stlLoadedSourceDocId
'Extract the desire page If mobjPDFLib.ExtractPageRanges(CStr(lPageNo)) = 0 Then Err.Raise vbObjectError, , "PDFLibrary.ExtracPageRanges failed: " & mobjPDFLib.LastErrorCode & _ " Filename: " & sFileName & " PageNo: " & lPageNo End If ' Set focus on the extracted desire page document lSourcePDFID = mobjPDFLib.SelectedDocument ' Set focus on our main document mobjPDFLib.SelectDocument mlCurrDocument ' Add desire number of pages. Default is 2. Please note that the extra pages will get removed ' at the end of this method mobjPDFLib.NewPages IIf(lPageNo - 1 = 0, 2, lPageNo - 1)
' Merge source PDF If mobjPDFLib.MergeDocument(lSourcePDFID) = 0 Then Err.Raise vbObjectError, , "PDFLibrary.MergeDocument failed: " & mobjPDFLib.LastErrorCode & _ " CurrentDocument:" & mlCurrDocument & " DocumentCount:" & mobjPDFLib.DocumentCount & _ " PageNo:" & lPageNo & " Filename:" & sFileName End If
' Select the source page mobjPDFLib.SelectPage mlCurrPage + lPageNo ' Store page size lNewWidth = mobjPDFLib.GetPageBox(2, 2) '' PageWidth lNewHeight = mobjPDFLib.GetPageBox(2, 3) '' PageHeight ' Select the work page mobjPDFLib.SelectPage mlCurrPage ' Capture the page lCaptureID = mobjPDFLib.CapturePageEx(mlCurrPage + lPageNo, 1)
If (lCaptureID = 0) Then Err.Raise vbObjectError, , "PDFLibrary.CapturePage failed: " & mobjPDFLib.LastErrorCode End If
mobjPDFLib.SelectPage mlCurrPage ' Resolve the coordinates ResolveCoordinates lLeft, lTop, lWidth, lHeight, lHorAlign, _ lVertAlign, lNewLeft, lNewTop, lNewWidth, lNewHeight
' Draw the captured page If mobjPDFLib.DrawCapturedPage(lCaptureID, lNewLeft, lNewTop, lNewWidth, lNewHeight) = 0 Then Err.Raise vbObjectError, , "PDFLibrary.DrawCapturedPage failed: " & mobjPDFLib.LastErrorCode End If
' Delete any extra pages mobjPDFLib.DeletePages mlCurrPage + 1, mobjPDFLib.PageCount - mlCurrPage mobjPDFLib.SelectPage mlCurrPage
|
|