Convert OneNote to PDF with replacing of missing fonts
PDF documents are widely used as a standard format of exchanging documents between organizations, government sectors and individuals. It’s a popular format so developers are often asked to convert Microsoft OneNote documents to PDF documents. For this purpose, Aspose.Note for .NET supports converting OneNote to PDF documents without using any other component. This topic shows how to save a Document using a font that is not available under the current machine.
If a OneNote document uses a font that is not available under the current machine then you can specify to substitute it by another widely used font.
How to set default font name
The sample below shows how to convert OneNote to PDF while substitututing missing fonts by Times New Roman font that is available on most machines.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
3
4// Load the document into Aspose.Note.
5Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));
6
7// Convert OneNote to PDF
8dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontName_out.pdf";
9oneFile.Save(dataDir, new PdfSaveOptions()
10 {
11 FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFont("Times New Roman")
12 });
How to set a font from a file as default
The sample below shows how to convert OneNote to PDF while substitututing missing fonts by a font located in a specified file.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
3
4string fontFile = Path.Combine(dataDir, "geo_1.ttf");
5
6// Load the document into Aspose.Note.
7Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));
8
9// Convert OneNote to PDF
10dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontFromFile_out.pdf";
11oneFile.Save(dataDir, new PdfSaveOptions()
12 {
13 FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFontFromFile(fontFile)
14 });
How to set a font from a stream as default
The sample below shows how to convert OneNote to PDF while substitututing missing fonts by a font from provided stream.
1// The path to the documents directory.
2string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
3
4string fontFile = Path.Combine(dataDir, "geo_1.ttf");
5
6// Load the document into Aspose.Note.
7Document oneFile = new Document(Path.Combine(dataDir, "missing-font.one"));
8
9// Convert OneNote to PDF
10dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontFromStream_out.pdf";
11
12using (var stream = File.Open(fontFile, FileMode.Open, FileAccess.Read, FileShare.Read))
13{
14 oneFile.Save(dataDir, new PdfSaveOptions()
15 {
16 FontsSubsystem = DocumentFontsSubsystem.UsingDefaultFontFromStream(stream)
17 });
18}