Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active June 28, 2022 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/c33928f5143ea337f2a3fb12217436dc to your computer and use it in GitHub Desktop.
Save aspose-com-gists/c33928f5143ea337f2a3fb12217436dc to your computer and use it in GitHub Desktop.
Convert OneNote to PDF using Java | OneNote to PDF in Java

Learn how to convert a OneNote document to a PDF using Java : http://blog.aspose.com/2022/06/28/convert-onenote-to-pdf-using-java/

The following topics are covered in this article:

  1. OneNote to PDF Converter Java API
  2. Convert Existing OneNote Document to PDF
  3. Create OneNote Document and Convert it to PDF
  4. Convert Range of OneNote Pages to PDF
  5. Convert OneNote to PDF with Image Compression
// This code example demonstrates how to convert an existing OneNote to PDF.
// Load an existing OneNote document.
Document oneFile = new Document("C:\\Files\\Sample1.one");
// Save OneNote as PDF
oneFile.save("C:\\Files\\Sample1_out.pdf", SaveFormat.Pdf);
// This code example demonstrates how to convert a range of pages of a OneNote to PDF.
// Load the document
Document oneFile = new Document("C:\\Files\\Sample1.one");
// Initialize PdfSaveOptions object
PdfSaveOptions options = new PdfSaveOptions();
// Set page index: 0 means to start saving from first page.
options.setPageIndex(0);
// Set page count: 1 means to save only one page.
options.setPageCount(1);
// Save OneNote as PDF
oneFile.save("C:\\Files\\ConvertRange_out.pdf", options);
// This code example demonstrates how to convert a OneNote to PDF with Image compression.
// Load the document
Document oneFile = new Document("C:\\Files\\Sample1.one");
// Initialize PdfSaveOptions object
PdfSaveOptions options = new PdfSaveOptions();
// Use Jpeg compression
options.setImageCompression(PdfImageCompression.Jpeg);
// Quality for JPEG compression
options.setJpegQuality(90);
// Save OneNote as PDF
oneFile.save("C:\\Files\\ConvertWithImageCompression.pdf", options);
// This code example demonstrates how to create a new OneNote document and convert to PDF.
// Initialize OneNote document
Document doc = new Document();
// Add new Page
Page page = new Page();
// Default style for all text in the document.
ParagraphStyle textStyle = new ParagraphStyle();
textStyle.setFontColor(Color.BLACK);
textStyle.setFontName("Arial");
textStyle.setFontSize(10);
// Set page title properties
Title title = new Title();
RichText titleText = new RichText();
titleText.setText("Title text.");
titleText.setParagraphStyle(textStyle);
title.setTitleText(titleText);
RichText titleDate = new RichText();
Calendar cal = Calendar.getInstance();
cal.set(2018, 04, 03);
titleDate.setText(cal.getTime().toString());
titleDate.setParagraphStyle(textStyle);
title.setTitleDate(titleDate);
RichText titleTime = new RichText();
titleTime.setText("12:34");
titleTime.setParagraphStyle(textStyle);
title.setTitleText(titleTime);
page.setTitle(title);
// Append Page node in the document
doc.appendChildLast(page);
// Save into PDF format
doc.save("C:\\Files\\CreateOneNoteDocAndSaveAsPDF.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment