Convert or Save OneNote Document to Image Formats BMP, JPG or Jpeg, TIFF in Java API

Saving a Document to image Format

How does it work?

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

Saving a Document as Image in BMP format Using ImageSaveOptions

 1        // The path to the documents directory.
 2        String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
 3
 4        // Load the document into Aspose.Note.
 5        Document oneFile = new Document(dataDir + "Aspose.one");
 6
 7        dataDir = dataDir + "SaveToBmpImageUsingImageSaveOptions_out.bmp";
 8
 9        // Save the document.
10        oneFile.save(dataDir, new ImageSaveOptions(SaveFormat.Bmp));

Saving a Document as Image in Jpeg format Using SaveFormat

 1        // The path to the documents directory.
 2        String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
 3
 4        // Load the document into Aspose.Note.
 5        Document oneFile = new Document(dataDir + "Aspose.one");
 6
 7        dataDir = dataDir + "SaveToJpegImageUsingSaveFormat_out.jpg";
 8
 9        // Save the document.
10        oneFile.save(dataDir, SaveFormat.Jpeg);

Saving a Document as Image in TIFF format Using JPEG compression

 1        // The path to the documents directory.
 2        String dataDir = Paths.get(Utils.getSharedDataDir(SaveOneNoteDocToStream.class), "load").toString();
 3
 4        // Load the document into Aspose.Note.
 5        Document oneFile = new Document(Paths.get(dataDir, "Aspose.one").toString());
 6
 7        ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
 8        options.setTiffCompression(TiffCompression.Jpeg);
 9        options.setQuality(93);
10
11        oneFile.save(Paths.get(dataDir,"SaveToTiffUsingJpegCompression.tiff").toString(), options);

Saving a Document as Image in TIFF format Using PackBits compression

 1        // The path to the documents directory.
 2        String dataDir = Paths.get(Utils.getSharedDataDir(SaveOneNoteDocToStream.class), "load").toString();
 3
 4        // Load the document into Aspose.Note.
 5        Document oneFile = new Document(Paths.get(dataDir, "Aspose.one").toString());
 6
 7        ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
 8        options.setTiffCompression(TiffCompression.PackBits);
 9
10        oneFile.save(Paths.get(dataDir, "SaveToTiffUsingPackBitsCompression.tiff").toString(), options);

Saving a Document as Grayscale Image

 1        // The path to the documents directory.
 2        String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
 3
 4        // Load the document into Aspose.Note.
 5        Document oneFile = new Document(dataDir + "Aspose.one");
 6
 7        dataDir = dataDir + "SaveAsGrayscaleImage_out.png";
 8
 9        ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
10        options.setColorMode(ColorMode.GrayScale);
11
12        // Save the document.
13        oneFile.save(dataDir, options);

Saving a Document as Binary Image Using Fixed Threshold

 1        // The path to the documents directory.
 2        String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
 3
 4        // Load the document into Aspose.Note.
 5        Document oneFile = new Document(dataDir + "Aspose.one");
 6
 7        dataDir = dataDir + "SaveToBinaryImageUsingFixedThreshold_out.png";
 8
 9        ImageBinarizationOptions binarizationOptions = new ImageBinarizationOptions();
10        binarizationOptions.setBinarizationMethod(BinarizationMethod.FixedThreshold);
11        binarizationOptions.setBinarizationThreshold(123);
12
13        ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
14        options.setColorMode(ColorMode.BlackAndWhite);
15        options.setBinarizationOptions(binarizationOptions);
16
17        // Save the document as gif.
18        oneFile.save(dataDir, options);

Saving a Document as Binary Image Using Otsu’s Method

 1        // The path to the documents directory.
 2        String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
 3
 4        // Load the document into Aspose.Note.
 5        Document oneFile = new Document(dataDir + "Aspose.one");
 6
 7        dataDir = dataDir + "SaveToBinaryImageUsingOtsuMethod_out.png";
 8
 9        ImageBinarizationOptions binarizationOptions = new ImageBinarizationOptions();
10        binarizationOptions.setBinarizationMethod(BinarizationMethod.Otsu);
11
12        ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
13        options.setColorMode(ColorMode.BlackAndWhite);
14        options.setBinarizationOptions(binarizationOptions);
15
16        // Save the document.
17        oneFile.save(dataDir, options);

Saving a Document as Binary Image in TIFF format Using CCITT Group 3 fax compression.

 1        // The path to the documents directory.
 2        String dataDir = Paths.get(Utils.getSharedDataDir(SaveOneNoteDocToStream.class), "load").toString();
 3
 4        // Load the document into Aspose.Note.
 5        Document oneFile = new Document(Paths.get(dataDir, "Aspose.one").toString());
 6
 7        ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
 8        options.setColorMode(ColorMode.BlackAndWhite);
 9        options.setTiffCompression(TiffCompression.Ccitt3);
10
11        oneFile.save(Paths.get(dataDir, "SaveToTiffUsingCcitt3Compression.tiff").toString(), options);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.