Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files from any .NET platform (C#, VB.NET, ASP.NET, .NET Core) and Java applications (J2SE and J2EE) with fast and high quality performance.

Mon Jun 10, 2019 1:38 am

Hello,

I have a word file and I find there're no bookmarks after converting it to pdf . But there're bookmarks if I save the word as pdf directly in Micrsoft Word.

Question: how can I keep the bookmarks in Sprire.Doc when converting word to pdf?

I have attached a file.zip and it contains 3 files:
orginal_word_file.docx - this is the word file I used;
word_save_as_pdf.pdf - this is the pdf I saved from Micrsoft Word;
word_to_pdf_with_spire.doc.pdf - this is what I converted with Spire.Doc

this is the code I used to convert:

var document = new Document(filePath);
document.KeepSameFormat = true;
document.SaveToFile(outputPath, FileFormat.PDF);


Please help and respond ASAP. Thanks again!

Xiutao
You do not have the required permissions to view the files attached to this post.

xiutao.liu
 
Posts: 3
Joined: Fri Apr 12, 2019 2:59 am

Mon Jun 10, 2019 6:56 am

Hello,

Thanks for your inquiry.
Please refer to the following sample code to create the bookmarks and convert the word document to PDF/A file. Here I also attached my result PDF for your reference. If there is any question, just feel free to write back.
Code: Select all
var document = new Document(@"orginal_word_file.docx");
ToPdfParameterList ps = new ToPdfParameterList();
ps.PdfConformanceLevel = Spire.Pdf.PdfConformanceLevel.Pdf_A1B;
ps.CreateWordBookmarks = true;
ps.CreateWordBookmarksUsingHeadings = true;
document.SaveToFile(@"result.pdf", ps);

Sincerely,
Lisa
E-iceblue support team
You do not have the required permissions to view the files attached to this post.
User avatar

Lisa.Li
 
Posts: 1049
Joined: Wed Apr 25, 2018 3:20 am

Mon Jun 10, 2019 7:25 am

Hello,

thanks for your quick response.

I tried with your code but it still didn't work.

Code: Select all
Document doc = new Document(docFilePath);

            ToPdfParameterList toPdf = new ToPdfParameterList();
            toPdf.PdfConformanceLevel = Spire.Pdf.PdfConformanceLevel.Pdf_A1B;
            toPdf.CreateWordBookmarks = true;
            toPdf.CreateWordBookmarksUsingHeadings = true;

            doc.SaveToFile(outputPath, toPdf);


Did I miss something? The pdf generated from the above code looks same as before (no bookmarks)

The Spire.Doc version on my Visual Studio is 7.5.9 on .netcore (BTW, I didn't install the Spire.Pdf and only Spire.Doc installed)

Your result looks great. I only need to figure out what I missed.

thanks,
Xiutao

xiutao.liu
 
Posts: 3
Joined: Fri Apr 12, 2019 2:59 am

Mon Jun 10, 2019 7:48 am

Hello,

My "result.pdf" is generated by .net framework. However, when testing this code on .Net Core, I did notice that the bookmarks aren't created and the PDF/A format also isn't saved successfully. The issue has been logged into our bug tracking system for investigating and fixing. If there is any update, we will let you know. Sorry for the inconvenience caused.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1049
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Doc