I’m converting a word doc to pdf, my word doc contains headings (style=Heading 1), after converting I cannot display the bookmark navigation pane.
Imports Aspose.Words
Dim doc As Document = New Document(filepath)
If doc.HasRevisions Then doc.AcceptAllRevisions()
Dim options As Saving.PdfSaveOptions = New Saving.PdfSaveOptions()
options.OutlineOptions.CreateMissingOutlineLevels = True
options.OutlineOptions.DefaultBookmarksOutlineLevel = 1
options.SaveFormat = SaveFormat.Pdf
doc.Save(new_path, options)
Please use OutlineOptions.HeadingsOutlineLevels property to achieve your requirement. This property specifies how many levels of headings (paragraphs formatted with the Heading styles) to include in the document outline.
Specify 0 for no headings in the outline; specify 1 for one level of headings in the outline and so on.
Thanks for your reply, it working correctly now when converting word to pdf.
But, after converting I’m doing a merge of two PDFs, the bookmarks are lost in the merged PDF file:
My code doing the merge:
'Coverpage file
Dim CoverFile As TFile = DirectCast(CoverPageFile, TFile)
Dim pdf1 As New FileStream(CoverFile.getPhysicalPath, FileMode.Open, FileAccess.Read)
'Original File
Dim Original As TFile = DirectCast(OriginalFile, TFile)
Dim pdf2 As New FileStream(Original.getPhysicalPath, FileMode.Open, FileAccess.Read)
Dim output_filename As String = Path.GetFileNameWithoutExtension(filetitle) & ".pdf"
Dim filesToConcat As String() = {CoverFile.getPhysicalPath, Original.getPhysicalPath}
Dim buffer1 As Byte() = New Byte(Convert.ToInt32(pdf1.Length) - 1) {}
Dim buffer2 As Byte() = New Byte(Convert.ToInt32(pdf2.Length) - 1) {}
Dim index As Integer = 0
''read PDF file contents into byte arrays
index = pdf1.Read(buffer1, 0, Convert.ToInt32(pdf1.Length))
index = pdf2.Read(buffer2, 0, Convert.ToInt32(pdf2.Length))
'Create output file stream
Dim outputPDFPath As String = cnf(Of String)(ECoreConfiguration.UploadDirectoryTmpFiles) & Path.GetFileNameWithoutExtension(Original.filename) & "_Merged.pdf"
'Dim ofs As New FileStream(outputPDFPath, FileMode.Create)
Dim ret As Boolean
Dim pdfEditor As New PdfFileEditor()
''pdfEditor.UseDiskBuffer = True
''ret = pdfEditor.Concatenate(filesToConcat, outputPDFPath)
Using pdfStream As New MemoryStream()
Using fileStream1 As New MemoryStream(buffer1)
Using fileStream2 As New MemoryStream(buffer2)
ret = pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream)
If Not ret Then
outputPDFConversion.Message = "An Error Occured while generating the file."
outputPDFConversion.Status = PDFConverionStatus.Error
End If
'convert MemoryStream back to byte array
Dim data As Byte() = pdfStream.ToArray()
'create a FileStream to save the output PDF file
Dim output As New FileStream(outputPDFPath, FileMode.Create)
'write byte array contents in the output file stream
output.Write(data, 0, data.Length)
'close output file
output.Close()
End Using
End Using
End Using
the “output” does NOT contain Bookmarks, knowing that pdf2 contains bookmarks.
Your query is related to Aspose.PDF. We are moving this forum thread to Aspose.Total forum. Our colleague from Aspose.PDF team will take care of your concerns.
Would you please share source and generated PDF files so that we may try to reproduce and investigate it in our environment. Before sharing requested data, please ensure using Aspose.PDF for .NET 19.4.
Imports Aspose.Pdf.Facades
Imports Aspose.Pdf
'Coverpage file
Dim CoverFile As TFile = DirectCast(CoverPageFile, TFile)
Dim pdf1 As New FileStream(CoverFile.getPhysicalPath, FileMode.Open, FileAccess.Read)
'Original File
Dim Original As TFile = DirectCast(OriginalFile, TFile)
Dim pdf2 As New FileStream(Original.getPhysicalPath, FileMode.Open, FileAccess.Read)
Dim output_filename As String = Path.GetFileNameWithoutExtension(filetitle) & ".pdf"
Dim filesToConcat As String() = {CoverFile.getPhysicalPath, Original.getPhysicalPath}
Dim buffer1 As Byte() = New Byte(Convert.ToInt32(pdf1.Length) - 1) {}
Dim buffer2 As Byte() = New Byte(Convert.ToInt32(pdf2.Length) - 1) {}
Dim index As Integer = 0
''read PDF file contents into byte arrays
index = pdf1.Read(buffer1, 0, Convert.ToInt32(pdf1.Length))
index = pdf2.Read(buffer2, 0, Convert.ToInt32(pdf2.Length))
'Create output file stream
Dim outputPDFPath As String = cnf(Of String)(ECoreConfiguration.UploadDirectoryTmpFiles) & Path.GetFileNameWithoutExtension(Original.filename) & "_Merged.pdf"
'Dim ofs As New FileStream(outputPDFPath, FileMode.Create)
Dim ret As Boolean
Dim pdfEditor As New PdfFileEditor()
''pdfEditor.UseDiskBuffer = True
''ret = pdfEditor.Concatenate(filesToConcat, outputPDFPath)
Using pdfStream As New MemoryStream()
Using fileStream1 As New MemoryStream(buffer1)
Using fileStream2 As New MemoryStream(buffer2)
ret = pdfEditor.Concatenate(fileStream1, fileStream2, pdfStream)
If Not ret Then
outputPDFConversion.Message = "An Error Occured while generating the file."
outputPDFConversion.Status = PDFConverionStatus.Error
End If
'convert MemoryStream back to byte array
Dim data As Byte() = pdfStream.ToArray()
'create a FileStream to save the output PDF file
Dim output As New FileStream(outputPDFPath, FileMode.Create)
'write byte array contents in the output file stream
output.Write(data, 0, data.Length)
'close output file
output.Close()
End Using
End Using
End Using
I’m concatenating pdf1 and pdf2 and merging it into the “output” which should contain the same bookmarks of pdf2.
I have the code below after the line “output.Close()” and the bookmarks are displayed successfully in the PDf file.
But I cannot be moved to the correct content when I click to the bookmark title.
'add bookmarks
Dim pCE As PdfBookmarkEditor = New PdfBookmarkEditor()
pCE.BindPdf(pdf2.Name)
Dim pCE1 As PdfBookmarkEditor = New PdfBookmarkEditor()
pCE1.BindPdf(output.Name)
For Each item As OutlineItemCollection In pCE.Document.Outlines
pCE1.Document.Outlines.Add(item)
Next
pCE1.Save(output.Name)
Dim pdf2BookmarkEditor As PdfBookmarkEditor = New PdfBookmarkEditor()
pdf2BookmarkEditor.BindPdf(pdf2.Name)
Dim outputBookmarkEditor As PdfBookmarkEditor = New PdfBookmarkEditor() outputBookmarkEditor.BindPdf(output.Name)
Dim bookmarks As Bookmarks = pdf2BookmarkEditor.ExtractBookmarks()
For Each bm As Bookmark In bookmarks
bm.PageNumber += 1
outputBookmarkEditor.CreateBookmarks(bm)
Next
Would you please share latest version of your SSCCE code along with source and generated files and elaborate with the help of screenshots how do you expect the output to be, so that we may investigate your requirements further and assist you accordingly.