Save a OneNote Document

Saving a Document to OneNote Format

How does it work?

The save method exposed by the API lets you save the document to OneNote format. The following three overloaded members provide the option to save the document in OneNote format.

1String dataDir = Utils.getSharedDataDir(SaveDocToOneNoteFormat.class) + "load/";
2		
3Document doc = new Document(dataDir + "Sample1.one");
4doc.save(dataDir + "SaveDocToOneNoteFormat_out.one");

Saving a Document Using Save Options

1String dataDir = Utils.getSharedDataDir(SaveDocToOneNoteFormat.class) + "load/";
2
3Document document = new Document(dataDir + "Sample1.one");
4
5document.save(dataDir + "SaveDocToOneNoteFormatUsingOnesaveoptions_out.one", new OneSaveOptions());

Saving a Document Using Save Format

1String dataDir = Utils.getSharedDataDir(SaveDocToOneNoteFormatUsingSaveformat.class) + "load/";
2		
3Document document = new Document(dataDir + "Sample1.one");
4
5document.save(dataDir + "SaveDocToOneNoteFormatUsingSaveformat_out.one", SaveFormat.One);

Save OneNote Document to a Stream

Users can pass a stream object to the Document.save(Stream, SaveFormat) method. When saving to a stream, you must specify the save format explicitly.

1// Load the document into Aspose.Note.
2String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
3
4Document doc = new Document(dataDir + "Sample1.one");
5
6ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
7
8doc.save(dstStream, SaveFormat.Pdf);

Specify OneNote Save Options

There are overloaded Document.save methods that accept a SaveOptions object. This should be an object of a class derived from the SaveOptions class. Each save format has a corresponding class that holds save options for that format. For example, there are PdfSaveOptions for SaveFormat.Pdf and OneSaveOptions for SaveFormat.One.

The code below shows how to set save options before saving a document to PDF.

 1// The path to the documents directory.
 2String dataDir = Utils.getSharedDataDir(SpecifySaveOptions.class) + "load\\";
 3
 4// Load the document into Aspose.Note.
 5Document doc = new Document(dataDir + "Aspose.one");
 6
 7// Initialize PdfSaveOptions object
 8PdfSaveOptions opts = new PdfSaveOptions();
 9
10// Set page index
11opts.setPageIndex(2);
12
13// Set page count
14opts.setPageCount(3);
15
16//Specify compression if required
17opts.setImageCompression(PdfImageCompression.Jpeg);
18opts.setJpegQuality(90);
19        
20dataDir = dataDir + "Document.SaveWithOptions_out.pdf";
21doc.save(dataDir, opts);

Working with Locales

Aspose.Note provides an opportunity to set locales using setLocale method under LocaleOptions class.

The code below shows how to set locales options before saving a document.

 1License license = new License();
 2   license.setLicense("licenseFile");
 3 
 4   java.util.Locale.setDefault(new java.util.Locale("en", "rs"));
 5   LocaleOptions.setLocale(Locale.US);
 6		
 7   String inputFile = "Sample1.one";
 8      Path inputPath = Utils.getPath(SaveToStream.class, inputFile);
 9
10      // Load the document into Aspose.Note
11      Document oneFile = new Document(inputPath.toString());
12      oneFile.save("sample.png");
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.