Skip to content

Instantly share code, notes, and snippets.

@aspose-note-gists
Last active August 2, 2021 07:20
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-note-gists/0cd64f0457fdd6d56a68993a62169500 to your computer and use it in GitHub Desktop.
Save aspose-note-gists/0cd64f0457fdd6d56a68993a62169500 to your computer and use it in GitHub Desktop.
aspose.note.java.samples
String dataDir = Paths.get(Utils.getSharedDataDir(LoadPasswordProtectedOneNoteDoc.class), "load").toString();
Document ref[] = { null };
if (!Document.isEncrypted(Paths.get(dataDir, "Sample1.one").toString(), "VerySecretPassword", ref))
{
if (ref[0] != null)
{
System.out.println("The document is decrypted. It is loaded and ready to be processed.");
}
else
{
System.out.println("The document is encrypted. Invalid password was provided.");
}
}
else
{
System.out.println("The document is NOT encrypted. It is loaded and ready to be processed.");
}
String dataDir = Paths.get(Utils.getSharedDataDir(LoadPasswordProtectedOneNoteDoc.class), "load").toString();
LoadOptions loadOptions = new LoadOptions();
loadOptions.setDocumentPassword("password");
FileInputStream stream = new FileInputStream(Paths.get(dataDir, "Sample1.one").toString());
try {
Document ref[] = { null };
if (!Document.isEncrypted(stream, loadOptions, ref))
{
System.out.println("The document is loaded and ready to be processed.");
}
else
{
System.out.println("The document is encrypted. Provide a password.");
}
}
finally {
stream.close();
}
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir = dataDir + "SaveToBinaryImageUsingFixedThreshold_out.png";
ImageBinarizationOptions binarizationOptions = new ImageBinarizationOptions();
binarizationOptions.setBinarizationMethod(BinarizationMethod.FixedThreshold);
binarizationOptions.setBinarizationThreshold(123);
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
options.setColorMode(ColorMode.BlackAndWhite);
options.setBinarizationOptions(binarizationOptions);
// Save the document as gif.
oneFile.save(dataDir, options);
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir = dataDir + "SaveToBinaryImageUsingOtsuMethod_out.png";
ImageBinarizationOptions binarizationOptions = new ImageBinarizationOptions();
binarizationOptions.setBinarizationMethod(BinarizationMethod.Otsu);
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
options.setColorMode(ColorMode.BlackAndWhite);
options.setBinarizationOptions(binarizationOptions);
// Save the document.
oneFile.save(dataDir, options);
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir = dataDir + "SaveToBmpImageUsingImageSaveOptions_out.bmp";
// Save the document.
oneFile.save(dataDir, new ImageSaveOptions(SaveFormat.Bmp));
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir = dataDir + "SaveAsGrayscaleImage_out.png";
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
options.setColorMode(ColorMode.GrayScale);
// Save the document.
oneFile.save(dataDir, options);
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
// Load the document into Aspose.Note.
Document oneFile = new Document(dataDir + "Aspose.one");
dataDir = dataDir + "SaveToJpegImageUsingSaveFormat_out.jpg";
// Save the document.
oneFile.save(dataDir, SaveFormat.Jpeg);
// The path to the documents directory.
String dataDir = Paths.get(Utils.getSharedDataDir(SaveOneNoteDocToStream.class), "load").toString();
// Load the document into Aspose.Note.
Document oneFile = new Document(Paths.get(dataDir, "Aspose.one").toString());
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
options.setColorMode(ColorMode.BlackAndWhite);
options.setTiffCompression(TiffCompression.Ccitt3);
oneFile.save(Paths.get(dataDir, "SaveToTiffUsingCcitt3Compression.tiff").toString(), options);
// The path to the documents directory.
String dataDir = Paths.get(Utils.getSharedDataDir(SaveOneNoteDocToStream.class), "load").toString();
// Load the document into Aspose.Note.
Document oneFile = new Document(Paths.get(dataDir, "Aspose.one").toString());
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
options.setTiffCompression(TiffCompression.Jpeg);
options.setQuality(93);
oneFile.save(Paths.get(dataDir,"SaveToTiffUsingJpegCompression.tiff").toString(), options);
// The path to the documents directory.
String dataDir = Paths.get(Utils.getSharedDataDir(SaveOneNoteDocToStream.class), "load").toString();
// Load the document into Aspose.Note.
Document oneFile = new Document(Paths.get(dataDir, "Aspose.one").toString());
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Tiff);
options.setTiffCompression(TiffCompression.PackBits);
oneFile.save(Paths.get(dataDir, "SaveToTiffUsingPackBitsCompression.tiff").toString(), options);
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
String fontFile = Paths.get(dataDir, "geo_1.ttf").toString();
// Load the document into Aspose.Note.
Document oneFile = new Document(Paths.get(dataDir, "missing-font.one").toString());
// Save the document as PDF
dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontFromFile_out.pdf";
PdfSaveOptions options = new PdfSaveOptions();
options.setFontsSubsystem(DocumentFontsSubsystem.usingDefaultFontFromFile(fontFile));
oneFile.save(dataDir, options);
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
String fontFile = Paths.get(dataDir, "geo_1.ttf").toString();
// Load the document into Aspose.Note.
Document oneFile = new Document(Paths.get(dataDir, "missing-font.one").toString());
// Save the document as PDF
dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontFromStream_out.pdf";
InputStream stream = new FileInputStream(fontFile);
try
{
PdfSaveOptions options = new PdfSaveOptions();
options.setFontsSubsystem(DocumentFontsSubsystem.usingDefaultFontFromStream(stream));
oneFile.save(dataDir, options);
}
catch (Exception e)
{
stream.close();
}
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/";
// Load the document into Aspose.Note.
Document oneFile = new Document(Paths.get(dataDir, "missing-font.one").toString());
// Save the document as PDF
dataDir = dataDir + "SaveUsingDocumentFontsSubsystemWithDefaultFontName_out.pdf";
PdfSaveOptions options = new PdfSaveOptions();
options.setFontsSubsystem(DocumentFontsSubsystem.usingDefaultFont("Times New Roman"));
oneFile.save(dataDir, options);
String dataDir = Paths.get(Utils.getSharedDataDir(LoadPasswordProtectedOneNoteDoc.class), "styles").toString();
Document document = new Document();
Page page = new Page(document);
Outline outline = new Outline(document);
OutlineElement outlineElem = new OutlineElement(document);
StringBuilder builder = new StringBuilder();
builder.append("DefaultParagraphFontAndSize");
builder.append(System.lineSeparator());
builder.append("OnlyDefaultParagraphFont");
builder.append(System.lineSeparator());
builder.append("OnlyDefaultParagraphFontSize");
ParagraphStyle defaultStyle = new ParagraphStyle();
defaultStyle.setFontName("Courier New");
defaultStyle.setFontSize(20);
RichText text = new RichText(document);
text.setText(builder.toString());
text.setParagraphStyle(defaultStyle);
// Font and font size are from text.ParagraphStyle
TextStyle style = new TextStyle();
style.setRunIndex(27);
text.getStyles().addItem(style);
// Only font is from text.ParagraphStyle
style = new TextStyle();
style.setFontSize(14);
style.setRunIndex(53);
text.getStyles().addItem(style);
// Only font size is from text.ParagraphStyle
style = new TextStyle();
style.setFontName("Verdana");
style.setRunIndex(text.getText().length());
text.getStyles().addItem(style);
outlineElem.appendChildLast(text);
outline.appendChildLast(outlineElem);
page.appendChildLast(outline);
document.appendChildLast(page);
document.save(Paths.get(dataDir, "SetDefaultParagraphStyle.one").toString());
private static void setRowStyle(TableRow row, Color highlightColor, boolean bold, boolean italic) {
for (TableCell cell: row)
{
cell.setBackgroundColor(highlightColor);
for (RichText node: cell.getChildNodes(RichText.class))
{
node.getParagraphStyle().setBold(bold);
node.getParagraphStyle().setItalic(italic);
for (TextStyle style: node.getStyles())
{
style.setBold(bold);
style.setItalic(italic);
}
}
}
}
public static void main(String... args) throws IOException {
String dataDir = Utils.getSharedDataDir(CreateTableWithLockedColumns.class) + "tables\\";
// Load the document into Aspose.Note.
Document document = new Document(dataDir + "ChangeTableStyleIn.one");
// Get a list of table nodes
List<Table> nodes = document.getChildNodes(Table.class);
for (Table table: nodes)
{
setRowStyle(table.getFirstChild(), Color.GRAY, true, true);
// Highlight first row after head.
boolean flag = false;
List<TableRow> rows = table.getChildren();
for (int i = 1; i < rows.size(); ++i)
{
setRowStyle(rows.get(i), flag ? Color.lightGray : new java.awt.Color(-1, true), false, false);
flag = !flag;
}
}
document.save(Paths.get(dataDir, "ChangeTableStyleOut.one").toString());
}
String dataDir = Paths.get(Utils.getSharedDataDir(LoadPasswordProtectedOneNoteDoc.class), "text").toString();
Document document = new Document();
Page page = new Page(document);
Outline outline = new Outline(document);
OutlineElement outlineElem = new OutlineElement(document);
RichText text = new RichText(document);
text.setText("United States Germany China");
text.setParagraphStyle(ParagraphStyle.getDefault());
// Font and font size are from text.ParagraphStyle
TextStyle style = new TextStyle();
style.setLanguage(Locale.forLanguageTag("en-US"));
style.setRunIndex(13);
text.getStyles().addItem(style);
// Only font is from text.ParagraphStyle
style = new TextStyle();
style.setLanguage(Locale.forLanguageTag("de-DE"));
style.setRunIndex(21);
text.getStyles().addItem(style);
// Only font size is from text.ParagraphStyle
style = new TextStyle();
style.setLanguage(Locale.forLanguageTag("zh-CN"));
style.setRunIndex(text.getText().length());
text.getStyles().addItem(style);
outlineElem.appendChildLast(text);
outline.appendChildLast(outlineElem);
page.appendChildLast(outline);
document.appendChildLast(page);
document.save(Paths.get(dataDir, "SetProofingLanguageForText.one").toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment