Skip to content

Commit c9a9a6e

Browse files
Added sample for Rename-PDF-Bookmarks-From-Word
1 parent 0de9b01 commit c9a9a6e

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30804.86
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rename-PDF-Bookmarks-From-Word", "Rename-PDF-Bookmarks-From-Word\Rename-PDF-Bookmarks-From-Word.csproj", "{E214E65C-980A-46F5-8207-6D02212A49F5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E214E65C-980A-46F5-8207-6D02212A49F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E214E65C-980A-46F5-8207-6D02212A49F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E214E65C-980A-46F5-8207-6D02212A49F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E214E65C-980A-46F5-8207-6D02212A49F5}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {404A7F36-0167-4219-AE4D-2B0626CEB7E3}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.IO;
2+
using Syncfusion.DocIO;
3+
using System.Reflection;
4+
using Syncfusion.DocIO.DLS;
5+
using Syncfusion.DocIORenderer;
6+
using Syncfusion.OfficeChart;
7+
using Syncfusion.Pdf;
8+
using Syncfusion.Pdf.Interactive;
9+
using Syncfusion.Pdf.Parsing;
10+
11+
namespace Rename_PDF_Bookmarks_From_Word
12+
{
13+
class Program
14+
{
15+
static void Main(string[] args)
16+
{
17+
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"../../../Data/Template.docx"), FileMode.Open))
18+
{
19+
//Loads an existing Word document.
20+
using (WordDocument wordDocument = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic))
21+
{
22+
//Creates an instance of DocIORenderer.
23+
using (DocIORenderer renderer = new DocIORenderer())
24+
{
25+
//Sets ExportBookmarks for preserving Word document headings as PDF bookmarks.
26+
renderer.Settings.ExportBookmarks = ExportBookmarkType.Bookmarks;
27+
//Converts Word document into PDF document
28+
using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument))
29+
{
30+
//Saves the PDF document to MemoryStream.
31+
using (MemoryStream stream = new MemoryStream())
32+
{
33+
pdfDocument.Save(stream);
34+
stream.Position = 0;
35+
//Load the PDF document.
36+
using (PdfLoadedDocument pdfLoadedDocument = new PdfLoadedDocument(stream))
37+
{
38+
int i = 1;
39+
//Get each bookmark and changes the title of the bookmark.
40+
foreach (PdfBookmark pdfBookmark in pdfLoadedDocument.Bookmarks)
41+
{
42+
pdfBookmark.Title = "PdfBookMark" + i++;
43+
}
44+
//Saves the PDF file to file system.
45+
using (FileStream outputStream = new FileStream(Path.GetFullPath(@"../../../WordToPDF.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
46+
{
47+
pdfLoadedDocument.Save(outputStream);
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Rename_PDF_Bookmarks_From_Word</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
11+
</ItemGroup>
12+
13+
</Project>

0 commit comments

Comments
 (0)