Quantcast
Viewing all articles
Browse latest Browse all 3131

PDFBookmarkEditor.Save hangs when trying to save Large PDF with added bookmarks

Hi,

When using PDFBookMarkEditor to save bookmarks to a PDF, I came across a problem that causes PDFBookmarkEditor.Save to hang and not return control.

See the following command line app (In Visual Studio, create a new Command Line app, add Aspose.pdf.kit as a reference (tested with the latest v5 dll) and overwrite the Main sub with the below code;)
'*****************************************************
Sub Main()
        Dim sourcePDF As String = "C:\UXGuide.pdf"
        Dim destPDF As String = "C:\UXGuide_2.pdf"
        Dim Editor As New Aspose.Pdf.Kit.PdfBookmarkEditor

        Dim ExtractedBookMarks As Aspose.Pdf.Kit.Bookmarks
        Dim NewBookmark As New Aspose.Pdf.Kit.Bookmark

        Editor.BindPdf(sourcePDF)
        ExtractedBookMarks = Editor.ExtractBookmarks()
        NewBookmark.ChildItem = ExtractedBookMarks

        'We must bind to the source PDF again because PdfBookmarkEditor.ExtractBookmarks
        'closes the stream to the source PDF
        Editor.BindPdf(sourcePDF)

        Editor.DeleteBookmarks()

        Editor.CreateBookmarks(NewBookmark)
        '
        'Normally I would add other bookmarks here and then re-add the extracted bookmarks
        'it works for small PDF's but this is an example of a PDF that causes an exception
        '

        Try
            Editor.Save(destPDF)
        Catch ex As Exception
            Console.Write(ex.ToString)
        End Try

        Console.Write(Environment.NewLine)
        Console.Write("Press any key to end...")
        Console.Read()

    End Sub
'*****************************************************

The save call will not return, and the application will be left waiting for it to return. It does not even throw an exception. (if you are lucky enough to get it to throw an exception, it may return SystemNullException).

The PDF I used for this test can be found here;

Windows User Experience Interaction Guidelines (pdf)
http://www.microsoft.com/downloads/en/confirmation.aspx?displaylang=en&FamilyID=e49820cb-954d-45ae-9cb3-1b9e8ea7fe8c

Any help in explaining why this happens, how it can be avoided would be appreciated.

Regards,

Viewing all articles
Browse latest Browse all 3131

Trending Articles