Bookmarks not working after pdf document is saved with Adobe Reader X

Hi,

i discovered a strange problem.

1. Use Adobe.Pdf.dll 7.6.0.0 to merge several pdf files into a single pdf document.
2. After merging, some bookmarks a created (see file SI-bookmarks_working.pdf)
3. Open the merged pdf file with Adobe Acrobat Reader. The bookmarks are working.
3. Create a note and save the merged pdf document to a new directory via the command “Save As” in Adobe Reader.
4. Close pdf document.
5. Reopen the document in Adobe Reader. The bookmarks are still there but they aren’t working (see file SI_bookmarks_not_working.pdf).

Aspose.Pdf.dll 7.6.0.0
internal bugid#4839


  • In step 3. it’s not neccessary to add a note or the modify the content of the merged pdf document.

    - The command “Save As” destroys the bookmarks if the merged pdf document is saved to a new directory.


Other pdf tools (like Foxit PDF Reader) or older Adobe Acrobat Raeder (Version 9.0) don’t show this problem.

Hi Martin,


Thanks for highlighting issue. I’m afraid I couldn’t reproduce the reported issue at my side. Could you please double check this on some other machine? Moreover, please share your working environment.

Best Regards,

Hi,

here are some of my test result.

Plattform:

Windows 8, 64 Bit
Adobe Reader 11.0.2

SI-bookmarks_working.pdf ==> Bookmarks are fine
SI-bookmarks_working.pdf saved to new directory, close document, reopen new pdf ==> After this, bookmarks are broken

Windows 7, 64 Bit
Adobe Reader <span style=“font-size:11.0pt;font-family:“Calibri”,“sans-serif”;
mso-ascii-theme-font:minor-latin;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:“Times New Roman”;
mso-bidi-theme-font:minor-bidi;mso-ansi-language:DE;mso-fareast-language:EN-US;
mso-bidi-language:AR-SA”>10.1.0.534<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:HyphenationZone>21</w:HyphenationZone>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>DE</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<w:DoNotOptimizeForBrowser/>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val=“–”/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Normale Tabelle"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-fareast-language:EN-US;}

<![endif]–>
SI-bookmarks_working.pdf ==> Bookmarks are fine
SI-bookmarks_working.pdf saved to new directory, close document, reopen new pdf ==> After this, bookmarks are broken


Windows XP
Adobe Reader 9.5.0
SI-bookmarks_working.pdf ==> Bookmarks are fine
SI-bookmarks_working.pdf saved to new directory, close document, reopen new pdf ==> After this bookmarks are fine. Maybe this works because Adobe Reader 9.5 has no features to edit pdf dcoument content. ==> SaveAs with Adobe Reader 9.5 might be just a file copy operation.

Windows XP
Foxit Reader 5.4.5.0124
SI-bookmarks_working.pdf ==> Bookmarks are fine
SI-bookmarks_working.pdf saved to new directory, close document, reopen new pdf ==> After this, bookmarks are fine

I tested some other pdf documents (not created with Aspose tools) with a lot of bookmarks. This pdf files don’t show this issue. The bookmarks are still working.


Best regards, Martin Pfeifer

Hi Martin,


Thanks for providing additional information. I’m able to notice the reported issue in shared pdf files. For further investigation, could you please share your sample code used to concatenate and adding bookmarks? So we look into it and provide you more information accordingly.

Sorry for the inconvenience faced.

Best Regards,

Here’s my sample code.

The attached files s1-4.pdf get merged. After that bookmarks and watermarks are added. The result file is result.pdf - bookmarks are fine.

After that the result.pdf is opened with Adobe Reader 11 and saved as result_corrupt_bookmarks.pdf - bookmarks are broken.

using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections.Generic;

using Aspose.Pdf.Generator;
using Aspose.Pdf.Facades;

using Microsoft.VisualStudio.TestTools.UnitTesting;


[TestClass]
public class PdfMergeExample
{
public class MergeItem
{
public MergeItem(string filename, string bookmark, int pages, string watermark)
{
FileName = filename;
Bookmark = bookmark;
Pages = pages;
FirstPage = 0;
Watermark = watermark;
}
public string FileName;
public string Bookmark;
public int Pages;
public int FirstPage;
public string Watermark;
}


[TestMethod]
public void MergeTest()
{
PdfMergeExample merger = new PdfMergeExample();

MergeItem[] items = new MergeItem[] { new MergeItem(“C:\Temp\s1.pdf”, “Bookmark 1”, 46, “Watermark 1”), new MergeItem(“C:\Temp\s2.pdf”, “Bookmark 2”, 3, “Watermark 2”), new MergeItem(“C:\Temp\s3.pdf”, “Bookmark 3”, 86, “Watermark 3”), new MergeItem(“C:\Temp\s4.pdf”, “Bookmark 4”, 1, “Watermark 4”) };

merger.Merge(items, “C:\Temp\dest_tmp1.pdf”);

merger.AddBookmarks(items, “C:\Temp\dest_tmp1.pdf”, “C:\Temp\dest_tmp2.pdf”);

merger.AddWatermark(items, “C:\Temp\dest_tmp2.pdf”, “C:\Temp\result.pdf”);

File.Delete(“C:\Temp\dest_tmp1.pdf”);
File.Delete(“C:\Temp\dest_tmp2.pdf”);
}


public PdfMergeExample()
{
LicenceRead();
}

public bool AddWatermark(MergeItem[] items, string strSource, string strDest)
{
if (File.Exists(strDest))
{
File.Delete(strDest);
}

FileStream inputStream = new FileStream(strSource, FileMode.Open);
FileStream outputStream = new FileStream(strDest, FileMode.Create);

Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(inputStream);
foreach (MergeItem currItem in items)
{
for (int i = 0; i < currItem.Pages; i++)
{
Aspose.Pdf.Stamp stamper = new Aspose.Pdf.TextStamp(currItem.Watermark);
stamper.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;
stamper.RightMargin = 30;
stamper.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
stamper.TopMargin = 30;
pdfDoc.Pages[currItem.FirstPage + i].AddStamp(stamper);
}
}

pdfDoc.Save(outputStream);
pdfDoc.Dispose();

inputStream.Close();
outputStream.Flush();
outputStream.Close();

return true;
}

public bool AddBookmarks(MergeItem[] items, string strSource, string strDest)
{
if (File.Exists(strDest))
{
File.Delete(strDest);
}

string[] names = new string[items.Length];
int[] pages = new int[items.Length];
int lastPage = 1;

for (int i = 0; i < items.Length; i++)
{
names[i] = items[i].Bookmark;
pages[i] = lastPage;
items[i].FirstPage = lastPage;
lastPage += items[i].Pages;
}

PdfBookmarkEditor bookmarEditor = new PdfBookmarkEditor();
bookmarEditor.BindPdf(strSource);
bookmarEditor.DeleteBookmarks();
bookmarEditor.CreateBookmarkOfPage(names, pages);
bookmarEditor.Save(strDest);
bookmarEditor.Close();

return true;
}

public bool Merge(MergeItem[] sourceFiles, string destFile)
{
if (File.Exists(destFile))
{
File.Delete(destFile);
}

// not in sample code : testing files and filter corrupt pdf filed via PdfFileInfo.IsPdf()

Stream[] sourceStreams= StreamOpen(sourceFiles);
Stream destStream = new FileStream(destFile, FileMode.Create, FileAccess.Write);

bool result = Merge(sourceStreams, destStream);

destStream.Close();

return result;
}

public bool Merge(Stream[] sourceFiles, Stream destFile)
{
PdfFileEditor pdfEditor = new PdfFileEditor();
pdfEditor.CloseConcatenatedStreams = true;
pdfEditor.AllowConcatenateExceptions = true;
pdfEditor.CorruptedFileAction = PdfFileEditor.ConcatenateCorruptedFileAction.StopWithError;

bool result= pdfEditor.Concatenate(sourceFiles, destFile);

return result;
}

private Stream[] StreamOpen(MergeItem[] files)
{
Stream[] streams = new Stream[files.Length];
int i=0;

foreach (MergeItem s in files)
{
streams[i]= new FileStream(s.FileName, FileMode.Open, FileAccess.Read);
i++;
}
return streams;
}

private void LicenceRead() {
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“C:\Temp\Aspose.Total.lic”);
}
}

Hi Martin,


Thanks for providing additional information.

Sorry for the inconvenience faced. I've logged the issue in our bug tracking system as PDFNEWNET-35037. for further investigation and resolution. I've also linked your request to this issue and you will be notified via this thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Martin,


Thanks for your patience. We have a good news for you. Your reported issue has be fixed in current release i.e. 7.9.0 , in result of another bookmark issue resolution. Please download and try latest version for the fix.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Tilal,

it’s working great. Thanks a lot.

Martin

Hi Martin,


We are glad to hear that your problem is resolved in latest release version of Aspose.Pdf for .NET 7.9.0. Please continue using our product and in the event of any further query, please feel free to contact.

Hi

I am using version 17.9 trial version and getting this problem, the bookmarks work well but if loaded into Adobe Acrobat reader and saved as a new version then the bookmarks are there but the links fail.

Is there any update to this please.

Steve

@clusteruk,
Kindly send us the complete details of the use case, including source PDF and code. We will investigate and share our findings with you.

You can get a 30 day temporary license from the purchase portal and its option is available in step 5. A temporary license is a time-restricted full license that lets you test every aspect of a product before buying it. You need to apply the license to Aspose.Pdf for .NET library by adding a couple of lines of code. Please refer to the download section and licensing help topic: Download Aspose.Pdf for .NET API and Apply license to Aspose.Pdf for .NET API.

Hi

Here is the code that adds the bookmarks, sadly the test documents are confidential but I am sure you can just test one of your documents create in aspose.pdf in Adobe Acrobat and save and try to see if the same effect happens. This works no problem in all other PDF annotation/reader type software we have tried.

If you need a sample PDF I will build a pack without confidential documents.

Steve Jones

// Add Bookmarks

try
{
// Open document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(document_pack_filepath);
// Delete all bookmarks
pdfDocument.Outlines.Delete();
Aspose.Pdf.OutlineItemCollection pdfOutline = new Aspose.Pdf.OutlineItemCollection(pdfDocument.Outlines);
pdfOutline.Title = “First Document”;
pdfOutline.Italic = true;
pdfOutline.Bold = true;
pdfOutline.Action = new Aspose.Pdf.Annotations.GoToAction(1);
// Add bookmark in the document’s outline collection.
pdfDocument.Outlines.Add(pdfOutline);
int count = 0;
foreach (int page in pages)
{
if ((count + 1) < pages.Length)
{
// Create a parent bookmark object
Aspose.Pdf.OutlineItemCollection pdfReportOutline = new Aspose.Pdf.OutlineItemCollection(pdfDocument.Outlines);
pdfReportOutline.Title = pageTitles[count].Replace(".pdf", “”);
pdfReportOutline.Italic = true;
pdfReportOutline.Bold = true;

		pdfReportOutline.Action = new Aspose.Pdf.Annotations.GoToAction(pages[count + 1]);
		// Add bookmark in the document's outline collection.
		pdfDocument.Outlines.Add(pdfReportOutline);
	}
	count++;
}
// Save updated file
pdfDocument.Save(document_pack_filepath);

}
catch { }

@clusteruk,
Please list down all steps to replicate the problem behavior along with a sample PDF and fully compilable code. Please review attached input and output PDFs in your environment and see if you can find the problematic behavior. These are the PDF files: PDFs.zip (3.5 KB)

Hi, I cannot download the file, I am logged in?

Steve

@clusteruk,
Please download the Zip file from this URL: Dropbox - PDFs.zip - Simplify your life

Hi

Whilst this is not a very good test because the only menu item goes to page one which does not show a page change, however, it does show that saving OutputPDF_17.10.pdf does lose its menus when saved in Adobe Acrobat.

Are you saying you are aware of the issue now and it can be fixed?

Steve

@clusteruk,

Please highlight the difference with the help of a screenshot.

We recommend our clients to share the complete details of their scenarios in the form of use cases, including source PDF and code. We will investigate and share our findings with you.

Ok, I will mockup an app with this and demonstrate on non private papers this week.

Thanks