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 - PDFLibrary.MergeDocument failed: 0
  FAQ FAQ  Forum Search   Register Register  Login Login

PDFLibrary.MergeDocument failed: 0

 Post Reply Post Reply
Author
Message
Yadutt View Drop Down
Beginner
Beginner


Joined: 01 Sep 09
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote Yadutt Quote  Post ReplyReply Direct Link To This Post Topic: PDFLibrary.MergeDocument failed: 0
    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.
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: 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

Back to Top
Yadutt View Drop Down
Beginner
Beginner


Joined: 01 Sep 09
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote Yadutt Quote  Post ReplyReply Direct Link To This Post Posted: 01 Sep 09 at 4:51PM
Version : QuickPDF Library 7.14
Number of Pages: 58
IDE Visual Basic 6

Thanks
Back to Top
Yadutt View Drop Down
Beginner
Beginner


Joined: 01 Sep 09
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote Yadutt Quote  Post ReplyReply Direct Link To This Post 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

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: 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
 
Back to Top
Yadutt View Drop Down
Beginner
Beginner


Joined: 01 Sep 09
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote Yadutt Quote  Post ReplyReply Direct Link To This Post 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.
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: 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



Edited by Ingo - 02 Sep 09 at 10:01AM
Back to Top
Yadutt View Drop Down
Beginner
Beginner


Joined: 01 Sep 09
Status: Offline
Points: 10
Post Options Post Options   Thanks (0) Thanks(0)   Quote Yadutt Quote  Post ReplyReply Direct Link To This Post 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
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