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,
Hi Chris,
We’ll investigate this issue at our end and you’ll be updated with the results the earliest possible.
We’re sorry for the inconvenience.
Regards,
Hi Chris,
I have reproduced this issue at my end and logged it as PDFKITNET-21830 in our issue tracking system. Our team will look into this issue and you’ll be updated via this forum thread once it is resolved.
We’re sorry for the inconvenience.
Regards,
Hi,
Please can you provide me with an update on this.
I have encountered this issue again with other PDFs of around 100 meg.
having left the process to run for a long time it eventually throws the following;
System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was thrown.
at x30a678191d9b1780.x53863f600a504e05.x4130c8bdf0fc6582(Stream x160656af282c4d7b, Stream x0ecec17af75ebd13, String x319214f212f6cc99, String x682935b2be2ef7d8, Int32 xee83661000f1d43d, KeySize xc66814dd5c4c3675, Algorithm x39d921119affa3f4)
at x30a678191d9b1780.x53863f600a504e05.x4130c8bdf0fc6582(Stream x160656af282c4d7b, Stream x0ecec17af75ebd13)
at Aspose.Pdf.Kit.PdfBookmarkEditor.Save(Stream outputStream)
at Aspose.Pdf.Kit.PdfBookmarkEditor.Save(String outputFile)
This is a serious issue that we need looked at now, we cannot begin to ship our product while this bug exists because 1) we need to be able to add bookmarks to large documents and 2) because no error occurrs until there is no memory left the method is unresponsive and we have no way of knowing if it will work until it either completes after a very long time or the System.OutOfMemoryException is thrown.
The System.OutOfMemoryException suggests to me you have a memory leak occurring in this class - I have not come across this problem with other classes in the toolkit.
Ok, the stack trace I posted above was using Aspose. PDF.Kit 4.9
If I use Aspose.PDF.Kit 5.2 then it still throws System.OutOfMemoryException but the stack trace is;
System.OutOfMemoryException: Exception of type ‘System.OutOfMemoryException’ was
thrown.
at System.IO.MemoryStream.ToArray()
at Aspose.Pdf.Kit.PdfBookmarkEditor.Save(Stream outputStream)
at Aspose.Pdf.Kit.PdfBookmarkEditor.Save(String outputFile)
Hi Chris,
I’m sorry to inform you that this issue is not yet resolved. However, I have asked our development team to share the ETA of this issue. You’ll be notified via this forum thread as soon as I receive a response.
We’re sorry for the inconvenience.
Regards,
Hi Chris,
Our team has further investigated this issue and I would like to share with you that the fix for this issue will be available in our monthly release due early March 2011. You’ll be notified via this forum thread once it is released.
We’re sorry for the inconvenience.
Regards,
The issues you have found earlier (filed as 21830) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
Hi,
Hi Andrei,
Hello,
Hi Andrei,
Hi Andrei,
Hi Andrei,
2. Pass this stream as parameter into BindPdf() method.
3. Pass the same stream into Save() method
Aspose.Pdf.Facades.Bookmarks bookmarks = new
Aspose.Pdf.Facades.Bookmarks();<o:p></o:p>
for (int i = 0; i < 10; i++)
{
Aspose.Pdf.Facades.Bookmark newBookmark = new Aspose.Pdf.Facades.Bookmark()
{
Title = "level " + i,
Action = "GoTo",
PageNumber = 10
};
for (int j = 1; j <= 30; j++)
{
Aspose.Pdf.Facades.Bookmark childBookmark = new Aspose.Pdf.Facades.Bookmark()
{
Title = "document " + j,
Action = "GoTo",
PageNumber = j
};
newBookmark.ChildItems.Add(childBookmark);
}
bookmarks.Add(newBookmark);
}
PdfBookmarkEditor pdfBookmarkEditor = new PdfBookmarkEditor();
//create FileStream - open source file.
FileStream stream = new FileStream("36621.pdf", FileMode.Open, FileAccess.ReadWrite);
pdfBookmarkEditor.BindPdf(stream);
// delete any bookmarks if they existed before.
pdfBookmarkEditor.DeleteBookmarks();
foreach (Aspose.Pdf.Facades.Bookmark bMark in bookmarks)
{
pdfBookmarkEditor.CreateBookmarks(bMark);
}
// save the file again with the bookmarks.
//save result into the same stream.
pdfBookmarkEditor.Save(stream);
Please feel free to contact us for any further assistance.
Best Regards,
The issues you have found earlier (filed as PDFNEWNET-36621) have been fixed in Aspose.Pdf for .NET 9.2.0.
The blog post for this release is created over this link
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.