This Gist contains code snippets for sample code of Aspose.Note
Last active
September 24, 2020 11:24
-
-
Save aspose-com-gists/952261680cb5075c778c0ae67a69bd14 to your computer and use it in GitHub Desktop.
Aspose.Note for Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gists for Aspose.Note for Java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Aspose.Note-for-Java |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AttachFileByPath.class) + "attachments\\"; | |
// Create an object of the Document class | |
Document doc = new Document(); | |
// Initialize Page class object | |
Page page = new Page(doc); | |
// Initialize Outline class object | |
Outline outline = new Outline(doc); | |
// Initialize OutlineElement class object | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// Initialize AttachedFile class object and also pass its icon path | |
AttachedFile attachedFile = null; | |
try { | |
attachedFile = new AttachedFile(doc, dataDir + "attachment.txt", new FileInputStream(dataDir + "icon.jpg"), ImageFormat.getJpeg()); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
// Add attached file | |
outlineElem.appendChildLast(attachedFile); | |
// Add outline element node | |
outline.appendChildLast(outlineElem); | |
// Add outline node | |
page.appendChildLast(outline); | |
// Add page node | |
doc.appendChildLast(page); | |
dataDir = dataDir + "AttachFileAndSetIcon_out.one"; | |
doc.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(AttachFileByPath.class) + "attachments\\"; | |
// Create an object of the Document class | |
Document doc = new Document(); | |
// Initialize Page class object | |
Page page = new Page(doc); | |
// Initialize Outline class object | |
Outline outline = new Outline(doc); | |
// Initialize OutlineElement class object | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// Initialize AttachedFile class object | |
AttachedFile attachedFile = new AttachedFile(doc, dataDir + "attachment.txt"); | |
// Add attached file | |
outlineElem.appendChildLast(attachedFile); | |
// Add outline element node | |
outline.appendChildLast(outlineElem); | |
// Add outline node | |
page.appendChildLast(outline); | |
// Add page node | |
doc.appendChildLast(page); | |
dataDir = dataDir + "AttachFileByPath_out.one"; | |
doc.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(RetrieveAttachment.class) + "text/"; | |
// Load the document into Aspose.Note | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// Get list of attachments | |
List<AttachedFile> attachments = doc.getChildNodes(AttachedFile.class); | |
System.out.println("Total attachments: " + attachments.size()); | |
for (AttachedFile a : attachments) { | |
// Load attachment into memory | |
byte[] buffer = a.getBytes(); | |
ByteArrayInputStream stream = new ByteArrayInputStream(buffer); | |
// Save it to output location | |
String outputFile = "Output_" + a.getFileName(); | |
Path outputPath = Utils.getPath(RetrieveAttachment.class, outputFile); | |
Files.copy(stream, outputPath, StandardCopyOption.REPLACE_EXISTING); | |
System.out.println("File saved: " + outputPath); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
String inputFile = "Sample1.one"; | |
Path inputPath = Utils.getPath(UsingDocumentVisitor.class, inputFile); | |
// Load the document into Aspose.Note | |
Document doc = new Document(inputPath.toString()); | |
// Create an object that inherits from the DocumentVisitor class. | |
MyOneNoteToTxtWriter myConverter = new MyOneNoteToTxtWriter(); | |
/* | |
* This is the well known Visitor pattern. Get the model to accept a | |
* visitor.The model will iterate through itself by calling the | |
* corresponding methods on the visitor object (this is called | |
* visiting). | |
* | |
* Note that every node in the object model has the Accept method so the | |
* visiting can be executed not only for the whole document, but for any | |
* node in the document. | |
*/ | |
doc.accept(myConverter); | |
// Once the visiting is complete, we can retrieve the result of the operation, | |
// that in this example, has accumulated in the visitor. | |
System.out.println("Total Nodes: " + myConverter.getNodeCount()); | |
System.out.println(myConverter.getText()); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(AddHyperlink.class) + "hyperlinks/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Title class object | |
Title title = new Title(doc); | |
// initialize default text style | |
ParagraphStyle defaultTextStyle = new ParagraphStyle(); | |
defaultTextStyle.setFontName("Arial"); | |
defaultTextStyle.setFontSize(10); | |
defaultTextStyle.setFontColor(java.awt.Color.GRAY); | |
RichText titleText = new RichText(doc); | |
titleText.setText("Title"); | |
titleText.setParagraphStyle(defaultTextStyle); | |
Outline outline = new Outline(doc); | |
outline.setMaxWidth(200); | |
outline.setMaxHeight(200); | |
outline.setVerticalOffset(100); | |
outline.setHorizontalOffset(100); | |
OutlineElement outlineElem = new OutlineElement(doc); | |
TextStyle textStyleRed = new TextStyle(); | |
textStyleRed.setFontName("Arial"); | |
textStyleRed.setFontSize(10); | |
textStyleRed.setFontColor(java.awt.Color.red); | |
textStyleRed.setRunIndex(8); | |
TextStyle textStyleHyperlink = new TextStyle(); | |
textStyleHyperlink.setRunIndex(17); | |
textStyleHyperlink.setHyperlink(true); | |
textStyleHyperlink.setHyperlinkAddress("www.google.com"); | |
RichText text = new RichText(doc); | |
text.setText("This is hyperlink. This text is not a hyperlink."); | |
text.setParagraphStyle(defaultTextStyle); | |
text.getStyles().addItem(textStyleRed); | |
text.getStyles().addItem(textStyleHyperlink); | |
title.setTitleText(titleText); | |
page.setTitle(title); | |
outlineElem.appendChildLast(text); | |
// add outline elements | |
outline.appendChildLast(outlineElem); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
doc.save(dataDir + "AddHyperlink_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document document = new Document(); | |
Page page = new Page(document); | |
Image image = new Image(document, dataDir + "image1.jpg"); | |
image.setHyperlinkUrl( "http://www.aspose.com"); | |
page.appendChildLast(image); | |
document.appendChildLast(page); | |
document.save(dataDir + "HyperlinkToImage_out.one"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(AlternativeText.class) + "images/"; | |
Document document = new Document(); | |
Page page = new Page(document); | |
Image image = new Image(document, dataDir + "image.jpg"); | |
image.setAlternativeTextTitle("ImageAlternativeText Title"); | |
image.setAlternativeTextDescription("ImageAlternativeText Description"); | |
page.appendChildLast(image); | |
document.appendChildLast(page); | |
document.save(dataDir + "AlternativeText_out.one"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(BuildDocAndInsertImage.class) + "images/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Outline class object and set offset properties | |
Outline outline = new Outline(doc); | |
outline.setVerticalOffset(0); | |
outline.setHorizontalOffset(0); | |
// initialize OutlineElement class object | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// load an image by the file path. | |
Image image = new Image(doc, dataDir + "Input.jpg"); | |
// set image alignment | |
image.setAlignment(HorizontalAlignment.Right); | |
// add image | |
outlineElem.appendChildLast(image); | |
// add outline elements | |
outline.appendChildLast(outlineElem); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
// save OneNote document | |
// save the document in the *.one format. | |
try { | |
// oneFile.save("D://Aspose_JavaProjects//OneNote//out.one");//NOT | |
// working | |
doc.save(dataDir + "NewOneNotedocument_out", SaveFormat.Pdf);// WORKING | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(BuildDocAndInsertImageUsingImageStream.class) + "images/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
Outline outline1 = new Outline(doc); | |
outline1.setVerticalOffset(600); | |
outline1.setHorizontalOffset(0); | |
OutlineElement outlineElem1 = new OutlineElement(doc); | |
InputStream fs = null; | |
try { | |
fs = new FileInputStream(dataDir + "image.jpg"); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
// Load the second image using the image name, extension and stream. | |
Image image = new Image(doc, dataDir + "image1.jpg"); | |
// set image alignment | |
image.setAlignment(HorizontalAlignment.Right); | |
outlineElem1.appendChildLast(image); | |
outline1.appendChildLast(outlineElem1); | |
page.appendChildLast(outline1); | |
doc.appendChildLast(page); | |
// save OneNote document | |
try { | |
doc.save("D://Aspose_JavaProjects//OneNote//out3.pdf",SaveFormat.Pdf); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(BuildOneNoteDocumentfromtheScratchandInsertanImageusinganImageStream.class) + "images/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
Outline outline1 = new Outline(doc); | |
outline1.setVerticalOffset(600); | |
outline1.setHorizontalOffset(0); | |
OutlineElement outlineElem1 = new OutlineElement(doc); | |
InputStream fs = null; | |
try { | |
fs = new FileInputStream(dataDir + "image.jpg"); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
// Load the second image using the image name, extension and stream. | |
Image image = new Image(doc, dataDir + "image1.jpg"); | |
// set image alignment | |
image.setAlignment(HorizontalAlignment.Right); | |
outlineElem1.appendChildLast(image); | |
outline1.appendChildLast(outlineElem1); | |
page.appendChildLast(outline1); | |
doc.appendChildLast(page); | |
// save OneNote document | |
try { | |
doc.save("D://Aspose_JavaProjects//OneNote//out3.pdf",SaveFormat.Pdf); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
String inputFile = "image.jpg"; | |
Path inputPath = Utils.getPath(BuildOneNoteDocumentfromtheScratchandInsertanImageusinganImageStream.class, | |
inputFile); | |
String inputFile1 = "image1.jpg"; | |
Path inputPath1 = Utils.getPath(BuildOneNoteDocumentfromtheScratchandInsertanImageusinganImageStream.class, | |
inputFile1); | |
String outputFile = "Output.bmp"; | |
Path outputPath = Utils.getPath(BuildOneNoteDocumentfromtheScratchandInsertanImageusinganImageStream.class, | |
outputFile); | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
Outline outline1 = new Outline(doc); | |
outline1.setVerticalOffset(600); | |
outline1.setHorizontalOffset(0); | |
OutlineElement outlineElem1 = new OutlineElement(doc); | |
InputStream fs = null; | |
try { | |
fs = new FileInputStream(inputPath.toString()); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
// Load the second image using the image name, extension and stream. | |
Image image1 = new Image(doc, "Penguins", "jpg", fs); | |
// Load the second image using the image name, extension and stream. | |
Image image = new Image(doc, inputPath1.toString()); | |
// set image alignment | |
image.setAlignment(HorizontalAlignment.Right); | |
outlineElem1.appendChild(image); | |
outline1.appendChild(outlineElem1); | |
page.appendChild(outline1); | |
doc.appendChild(page); | |
// save OneNote document | |
try { | |
// doc.save("D://Aspose_JavaProjects//OneNote//out.one");//NOT | |
// working | |
// doc.save("D://Aspose_JavaProjects//OneNote//out3.pdf",SaveFormat.Pdf);//WORKING | |
doc.save(outputPath.toString(), SaveFormat.Bmp);// NOT WORKING | |
// doc.save("D://Aspose_JavaProjects//OneNote//out3.png",SaveFormat.Png);//NOT | |
// WORKING | |
// doc.save("D://Aspose_JavaProjects//OneNote//out3.tif",SaveFormat.Tiff);//NOT | |
// WORKING | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ExtractImages.class) + "images/"; | |
// Load the document into Aspose.Note | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// Get all images | |
List<Image> list = doc.getChildNodes(Image.class); | |
System.out.printf("Total Images: %s\n\n", list.size()); | |
// Traverse the list | |
for (int i = 0; i < list.size(); i++) { | |
Image image = list.get(i); | |
String outputFile = "ExtractImages_out" + i + "_" + image.getFileName(); | |
byte[] buffer = image.getBytes(); | |
Files.write(Paths.get(dataDir + outputFile), buffer); | |
System.out.printf("File saved: %s\n", dataDir); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetImageInfo.class) + "images/"; | |
// Load the document into Aspose.Note | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// Get all images | |
List<Image> list = doc.getChildNodes(Image.class); | |
System.out.printf("Total Images: %s\n\n", list.size()); | |
// Traverse the list | |
for (Image image : list) { | |
System.out.println("Width: " + image.getWidth()); | |
System.out.println("Height: " + image.getHeight()); | |
System.out.println("OriginalWidth: " + image.getOriginalWidth()); | |
System.out.println("OriginalHeight: " + image.getOriginalHeight()); | |
System.out.println("FileName: " + image.getFileName()); | |
System.out.println("LastModifiedTime: " + image.getLastModifiedTime()); | |
System.out.println(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load document from the stream. | |
LoadOptions options = new LoadOptions(); | |
String dataDir = Utils.getSharedDataDir(InsertanImage.class) + "images/"; | |
Document oneFile = new Document(dataDir + "Sample1.one", options); | |
// get the first page of the document. | |
Page page = oneFile.getFirstChild(); | |
// load an image from the file. | |
Image image = new Image(oneFile, dataDir + "Input.jpg"); | |
// change the image's size according to your needs (optional). | |
image.setWidth(100); | |
image.setHeight(100); | |
// set the image's location in the page (optional). | |
image.setVerticalOffset(400); | |
image.setHorizontalOffset(100); | |
// set image alignment | |
image.setAlignment(HorizontalAlignment.Right); | |
// add the image to the page. | |
page.appendChildLast(image); | |
// save the document in the *.one format. | |
try { | |
// oneFile.save("D://Aspose_JavaProjects//OneNote//out.one");//NOT | |
// working | |
oneFile.save(dataDir + "InsertanImage_out.pdf", SaveFormat.Pdf);// WORKING | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(NewOneNotedocument.class) + "images/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Outline class object and set offset properties | |
Outline outline = new Outline(doc); | |
outline.setVerticalOffset(0); | |
outline.setHorizontalOffset(0); | |
// initialize OutlineElement class object | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// load an image by the file path. | |
Image image = new Image(doc, dataDir + "Input.jpg"); | |
// set image alignment | |
image.setAlignment(HorizontalAlignment.Right); | |
// add image | |
outlineElem.appendChildLast(image); | |
// add outline elements | |
outline.appendChildLast(outlineElem); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
// save OneNote document | |
// save the document in the *.one format. | |
try { | |
// oneFile.save("D://Aspose_JavaProjects//OneNote//out.one");//NOT | |
// working | |
doc.save(dataDir + "NewOneNotedocument_out", SaveFormat.Pdf);// WORKING | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
// For complete examples and data files, please go to | |
// https://github.com/aspose-note/Aspose.Note-for-Java | |
System.out.println("Family: " + AssemblyConstants.getFamily()); | |
System.out.println("Platform: " + AssemblyConstants.getPlatform()); | |
System.out.println("Product: " + AssemblyConstants.getProduct()); | |
System.out.println("Release date: " + AssemblyConstants.getReleaseDate()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(CreateOneNoteDocumentWithFormattedRichText.class) + "introduction/"; | |
// For complete examples and data files, please go to | |
// https://github.com/aspose-note/Aspose.Note-for-Java | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Title class object | |
Title title = new Title(doc); | |
// initialize TextStyle class object and set formatting properties | |
ParagraphStyle defaultTextStyle = new ParagraphStyle(); | |
defaultTextStyle.setFontColor(Color.black); | |
defaultTextStyle.setFontName("Arial"); | |
defaultTextStyle.setFontSize(10); | |
RichText titleText = new RichText(doc); | |
titleText.setText("Title!"); | |
titleText.setParagraphStyle(defaultTextStyle); | |
// titleText.setTitleText(true); | |
// IsTitleText = true | |
Outline outline = new Outline(doc); | |
outline.setVerticalOffset(100); | |
outline.setHorizontalOffset(100); | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// RunIndex = 5 means the style will be applied only to 0-4 characters. | |
// ("Hello") | |
TextStyle textStyleForHelloWord = new TextStyle(); | |
textStyleForHelloWord.setFontColor(Color.red); | |
textStyleForHelloWord.setFontName("Arial"); | |
textStyleForHelloWord.setFontSize(10); | |
textStyleForHelloWord.setRunIndex(5); | |
// RunIndex = 13 means the style will be applied only to 5-12 | |
// characters. (" OneNote") | |
TextStyle textStyleForOneNoteWord = new TextStyle(); | |
textStyleForOneNoteWord.setFontColor(Color.green); | |
textStyleForOneNoteWord.setFontName("Calibri"); | |
textStyleForOneNoteWord.setFontSize(10); | |
textStyleForOneNoteWord.setItalic(true); | |
textStyleForOneNoteWord.setRunIndex(13); | |
// RunIndex = 18 means the style will be applied only to 13-17 | |
// characters. (" text"). | |
// Other characters ("!") will have the default style. | |
TextStyle textStyleForTextWord = new TextStyle(); | |
textStyleForTextWord.setFontColor(Color.blue); | |
textStyleForTextWord.setFontName("Arial"); | |
textStyleForTextWord.setFontSize(15); | |
textStyleForTextWord.setBold(true); | |
textStyleForTextWord.setItalic(true); | |
textStyleForTextWord.setRunIndex(18); | |
RichText text = new RichText(doc); | |
text.setText("Hello OneNote text!"); | |
text.setParagraphStyle(defaultTextStyle); | |
text.getStyles().addItem(textStyleForHelloWord); | |
text.getStyles().addItem(textStyleForOneNoteWord); | |
text.getStyles().addItem(textStyleForTextWord); | |
title.setTitleText(titleText); | |
// set page title | |
page.setTitle(title); | |
// add RichText node | |
outlineElem.appendChildLast(text); | |
// add OutlineElement node | |
outline.appendChildLast(outlineElem); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
// save OneNote document | |
doc.save(dataDir + "CreateOneNoteDocument_out.pdf", SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(CreateOneNoteDocumentWithSimpleRichText.class) + "introduction/"; | |
// For complete examples and data files, please go to | |
// https://github.com/aspose-note/Aspose.Note-for-Java | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Outline class object | |
Outline outline = new Outline(doc); | |
// initialize OutlineElement class object | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// initialize ParagraphStyle class object and set formatting properties | |
ParagraphStyle textStyle = new ParagraphStyle(); | |
textStyle.setFontColor(Color.black); | |
textStyle.setFontName("Arial"); | |
textStyle.setFontSize(10); | |
// initialize RichText class object and apply text style | |
RichText text = new RichText(doc); | |
text.setText("Hello OneNote text!"); | |
text.setParagraphStyle(textStyle); | |
// add RichText node | |
outlineElem.appendChildLast(text); | |
// add OutlineElement node | |
outline.appendChildLast(outlineElem); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
// save OneNote document | |
doc.save(dataDir + "CreateOneNoteDocumentWithSimpleRichText_out.pdf", SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(ConvertSpecificPageRangeToPdf.class) + "load/"; | |
Document oneFile = new Document(dataDir + "Sample1.one"); | |
// Initialize PdfSaveOptions object | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
// Set page index | |
opts.setPageIndex(2); | |
// Set page count | |
opts.setPageCount(3); | |
// Save the document as PDF | |
oneFile.save(dataDir +"ConvertSpecificPageRangeToPdf_out.pdf", opts); | |
System.out.println("File saved: " + dataDir + "ConvertSpecificPageRangeToPdf_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ConvertSpecificPageToImage.class) + "load/"; | |
// Load the document into Aspose.Note | |
Document oneFile = new Document(dataDir + "Sample1.one"); | |
// Initialize PdfSaveOptions object | |
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg); | |
// Specify second page for conversion | |
options.setPageIndex(1); | |
// Save the document | |
oneFile.save(dataDir + "ConvertSpecificPageToImage_out.jpg", options); | |
System.out.println("File saved: " + dataDir + "ConvertSpecificPageToImage_out.jpg"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(ConvertSpecificPageToPngImage.class) + "load/"; | |
Document oneFile = new Document(dataDir + "Sample1.one", new LoadOptions()); | |
// Initialize ImageSaveOptions object | |
ImageSaveOptions opts = new ImageSaveOptions(SaveFormat.Png); | |
// set page index | |
opts.setPageIndex(0); | |
// Save the document as PNG. | |
oneFile.save(dataDir + "ConvertSpecificPageToPngImage_out.png", opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
String inputFile = "Sample1.one"; | |
Path inputPath = Utils.getPath(ConvertToImage.class, inputFile); | |
String outputFile = "Output.png"; | |
Path outputPath = Utils.getPath(ConvertToImage.class, outputFile); | |
// Load the document into Aspose.Note | |
Document oneFile = new Document(inputPath.toString()); | |
// Initialize PdfSaveOptions object | |
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png); | |
// Save the document as PNG | |
oneFile.save(outputPath.toString(), options); | |
System.out.println("File saved: " + outputPath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
// Load the document into Aspose.Note. | |
String inputFile = "Sample1.one"; | |
Path inputPath = Utils.getPath(ConvertToImageUsingDefaultOptions.class, inputFile); | |
String outputFile = "ConvertOneNoteToImageWithDefaultOptions.gif"; | |
Path outputPath = Utils.getPath(ConvertToImageUsingDefaultOptions.class, outputFile); | |
Document oneFile = new Document(inputPath.toString(), new LoadOptions()); | |
// Save the document as Gif. | |
oneFile.save(outputPath.toString(), SaveFormat.Gif); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(ConvertToImageUsingDefaultOptions.class) + "load/"; | |
Document oneFile = new Document(dataDir + "Sample1.one", new LoadOptions()); | |
// Save the document as Gif. | |
oneFile.save(dataDir + "ConvertToImageUsingDefaultOptions_out.gif", SaveFormat.Gif); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
String inputFile = "Sample1.one"; | |
Path inputPath = Utils.getPath(ConvertToPdf.class, inputFile); | |
String outputFile = "Output.pdf"; | |
Path outputPath = Utils.getPath(ConvertToPdf.class, outputFile); | |
// Load the document into Aspose.Note | |
Document oneFile = new Document(inputPath.toString()); | |
// Initialize PdfSaveOptions object | |
PdfSaveOptions options = new PdfSaveOptions(); | |
// Set page index. Uncomment to skip first two pages | |
// options.setPageIndex(2); | |
// Set page count. Uncomment to convert only 3 pages, starting from | |
// options.getPageIndex(). | |
// options.setPageCount(3); | |
// Save the document as PDF | |
oneFile.save(outputPath.toString(), options); | |
System.out.println("File saved: " + outputPath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Title class object | |
Title title = new Title(doc); | |
// initialize TextStyle class object and set formatting properties | |
TextStyle defaultTextStyle = new TextStyle(); | |
defaultTextStyle.setFontColor(Color.black); | |
defaultTextStyle.setFontName("Arial"); | |
defaultTextStyle.setFontSize(10); | |
RichText titleText = new RichText(doc); | |
titleText.setText("Title!"); | |
titleText.setDefaultStyle(defaultTextStyle); | |
// titleText.setTitleText(true); | |
// IsTitleText = true | |
Outline outline = new Outline(doc); | |
outline.setVerticalOffset(100); | |
outline.setHorizontalOffset(100); | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// RunIndex = 5 means the style will be applied only to 0-4 characters. | |
// ("Hello") | |
TextStyle textStyleForHelloWord = new TextStyle(); | |
textStyleForHelloWord.setFontColor(Color.red); | |
textStyleForHelloWord.setFontName("Arial"); | |
textStyleForHelloWord.setFontSize(10); | |
textStyleForHelloWord.setRunIndex(5); | |
// RunIndex = 13 means the style will be applied only to 5-12 | |
// characters. (" OneNote") | |
TextStyle textStyleForOneNoteWord = new TextStyle(); | |
textStyleForOneNoteWord.setFontColor(Color.green); | |
textStyleForOneNoteWord.setFontName("Calibri"); | |
textStyleForOneNoteWord.setFontSize(10); | |
textStyleForOneNoteWord.setItalic(true); | |
textStyleForOneNoteWord.setRunIndex(13); | |
// RunIndex = 18 means the style will be applied only to 13-17 | |
// characters. (" text"). | |
// Other characters ("!") will have the default style. | |
TextStyle textStyleForTextWord = new TextStyle(); | |
textStyleForTextWord.setFontColor(Color.blue); | |
textStyleForTextWord.setFontName("Arial"); | |
textStyleForTextWord.setFontSize(15); | |
textStyleForTextWord.setBold(true); | |
textStyleForTextWord.setItalic(true); | |
textStyleForTextWord.setRunIndex(18); | |
RichText text = new RichText(doc); | |
text.setText("Hello OneNote text!"); | |
text.setDefaultStyle(defaultTextStyle); | |
text.getStyles().addItem(textStyleForHelloWord); | |
text.getStyles().addItem(textStyleForOneNoteWord); | |
text.getStyles().addItem(textStyleForTextWord); | |
title.setTitleText(titleText); | |
// set page title | |
page.setTitle(title); | |
// add RichText node | |
outlineElem.appendChildLast(text); | |
// add OutlineElement node | |
outline.appendChildLast(outlineElem); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
String dataDir = Utils.getSharedDataDir(CreateDocWithFormattedRichText.class) + "load/"; | |
// save OneNote document | |
doc.save(dataDir + "CreateDocWithFormattedRichText_out.pdf", SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CreateDocWithPageTitle.class); | |
// Create an object of the Document class | |
Document doc = new Document(); | |
// Initialize Page class object | |
Page page = new Page(doc); | |
// 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(doc); | |
RichText titleText = new RichText(doc); | |
titleText.setText("Title text."); | |
titleText.setParagraphStyle(textStyle); | |
title.setTitleText(titleText); | |
RichText titleDate = new RichText(doc); | |
Calendar cal = Calendar.getInstance(); | |
cal.set(2018, 04, 03); | |
titleDate.setText(cal.getTime().toString()); | |
titleDate.setParagraphStyle(textStyle); | |
title.setTitleDate(titleDate); | |
RichText titleTime = new RichText(doc); | |
titleTime.setText("12:34"); | |
titleTime.setParagraphStyle(textStyle); | |
title.setTitleText(titleTime); | |
page.setTitle(title); | |
// Append Page node in the document | |
doc.appendChildLast(page); | |
dataDir = dataDir + "load//CreateDocWithPageTitle_out.one"; | |
// Save OneNote document | |
doc.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Outline class object | |
Outline outline = new Outline(doc); | |
// initialize OutlineElement class object | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// initialize TextStyle class object and set formatting properties | |
TextStyle textStyle = new TextStyle(); | |
textStyle.setFontColor(Color.black); | |
textStyle.setFontName("Arial"); | |
textStyle.setFontSize(10); | |
// initialize RichText class object and apply text style | |
RichText text = new RichText(doc); | |
text.setText("Hello OneNote text!"); | |
text.setDefaultStyle(textStyle); | |
// add RichText node | |
outlineElem.appendChildLast(text); | |
// add OutlineElement node | |
outline.appendChildLast(outlineElem); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
String dataDir = Utils.getSharedDataDir(CreateDocWithSimpleRichText.class) + "load/"; | |
// save OneNote document | |
doc.save(dataDir + "CreateDocWithSimpleRichText_out.pdf", SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document document = new Document(dataDir + "Sample1.one"); | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
options.setExportCss(ResourceExportType.ExportEmbedded); | |
options.setExportImages(ResourceExportType.ExportEmbedded); | |
options.setExportFonts(ResourceExportType.ExportEmbedded); | |
options.setFontFaceTypes(FontFaceType.Ttf); | |
ByteArrayOutputStream r = new ByteArrayOutputStream(); | |
document.save(r, options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document document = new Document(dataDir + "Sample1.one"); | |
UserSavingCallbacks savingCallbacks = new UserSavingCallbacks(); | |
savingCallbacks.setRootFolder("documentFolder"); | |
savingCallbacks.setCssFolder("css"); | |
savingCallbacks.setKeepCssStreamOpened(true); | |
savingCallbacks.setImagesFolder("images"); | |
savingCallbacks.setFontsFolder("fonts"); | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
options.setFontFaceTypes(FontFaceType.Ttf); | |
options.setCssSavingCallback(savingCallbacks); | |
options.setImageSavingCallback(savingCallbacks); | |
options.setFontSavingCallback(savingCallbacks); | |
options.setExportCss(ResourceExportType.ExportEmbedded); | |
options.setExportImages(ResourceExportType.ExportEmbedded); | |
options.setExportFonts(ResourceExportType.ExportEmbedded); | |
File dir = new File(savingCallbacks.getRootFolder()); | |
if (!dir.exists()) { | |
dir.mkdir(); | |
} | |
document.save(Paths.get(savingCallbacks.getRootFolder(), "document.html").toString(), options); | |
try (OutputStreamWriter writer = new OutputStreamWriter(savingCallbacks.getCssStream(), "utf-8")) { | |
writer.write(System.lineSeparator()); | |
writer.write("/* This line is appended to stream manually by user */"); | |
writer.close(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document document = new Document(dataDir + "Sample1.one"); | |
HtmlSaveOptions options = new HtmlSaveOptions(); | |
options.setExportCss(ResourceExportType.ExportEmbedded); | |
options.setExportFonts(ResourceExportType.ExportEmbedded); | |
options.setExportImages(ResourceExportType.ExportEmbedded); | |
document.save(dataDir + "document.html", options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final int getCssSaved() { | |
return auto_CssSaved; | |
} | |
private void setCssSaved(int value) { | |
auto_CssSaved = value; | |
} | |
private int auto_CssSaved; | |
public final int getFontsSaved() { | |
return auto_FontsSaved; | |
} | |
private void setFontsSaved(int value) { | |
auto_FontsSaved = value; | |
} | |
private int auto_FontsSaved; | |
public final int getImagessSaved() { | |
return auto_ImagessSaved; | |
} | |
private void setImagessSaved(int value) { | |
auto_ImagessSaved = value; | |
} | |
private int auto_ImagessSaved; | |
public final String getRootFolder() { | |
return auto_RootFolder; | |
} | |
public final void setRootFolder(String value) { | |
auto_RootFolder = value; | |
} | |
private String auto_RootFolder; | |
public final boolean getKeepCssStreamOpened() { | |
return auto_KeepCssStreamOpened; | |
} | |
public final void setKeepCssStreamOpened(boolean value) { | |
auto_KeepCssStreamOpened = value; | |
} | |
private boolean auto_KeepCssStreamOpened; | |
public final String getCssFolder() { | |
return auto_CssFolder; | |
} | |
public final void setCssFolder(String value) { | |
auto_CssFolder = value; | |
} | |
private String auto_CssFolder; | |
public final OutputStream getCssStream() { | |
return auto_CssStream; | |
} | |
private void setCssStream(OutputStream value) { | |
auto_CssStream = value; | |
} | |
private OutputStream auto_CssStream; | |
public final String getFontsFolder() { | |
return auto_FontsFolder; | |
} | |
public final void setFontsFolder(String value) { | |
auto_FontsFolder = value; | |
} | |
private String auto_FontsFolder; | |
public final String getImagesFolder() { | |
return auto_ImagesFolder; | |
} | |
public final void setImagesFolder(String value) { | |
auto_ImagesFolder = value; | |
} | |
private String auto_ImagesFolder; | |
public final void fontSaving(FontSavingArgs args) { | |
String uri = null; | |
OutputStream stream = null; | |
String[] referenceToUri = { uri }; | |
OutputStream[] referenceToStream = { stream }; | |
this.createResourceInFolder(this.getFontsFolder(), args.getFileName(), /* out */ referenceToUri, | |
/* out */ referenceToStream); | |
uri = referenceToUri[0]; | |
stream = referenceToStream[0]; | |
args.setStream(stream); | |
args.setUri(Paths.get("..", uri).toString().replace("\\", "\\\\")); | |
this.setFontsSaved(this.getFontsSaved() + 1); | |
} | |
public final void cssSaving(CssSavingArgs args) { | |
String uri = null; | |
OutputStream stream = null; | |
String[] referenceToUri = { uri }; | |
OutputStream[] referenceToStream = { stream }; | |
this.createResourceInFolder(this.getCssFolder(), args.getFileName(), /* out */ referenceToUri, | |
/* out */ referenceToStream); | |
uri = referenceToUri[0]; | |
stream = referenceToStream[0]; | |
this.setCssStream(stream); | |
args.setStream(stream); | |
args.setKeepStreamOpen(this.getKeepCssStreamOpened()); | |
args.setUri(uri); | |
this.setCssSaved(this.getCssSaved() + 1); | |
} | |
public final void imageSaving(ImageSavingArgs args) { | |
String uri = null; | |
OutputStream stream = null; | |
String[] referenceToUri = { uri }; | |
OutputStream[] referenceToStream = { stream }; | |
this.createResourceInFolder(this.getImagesFolder(), args.getFileName(), /* out */ referenceToUri, | |
/* out */ referenceToStream); | |
uri = referenceToUri[0]; | |
stream = referenceToStream[0]; | |
args.setStream(stream); | |
args.setUri(uri); | |
this.setImagessSaved(this.getImagessSaved() + 1); | |
} | |
private void createResourceInFolder(String folder, String filename, /* out */ String[] uri, | |
/* out */ OutputStream[] stream) { | |
String relativePath = folder; | |
String fullPath = Paths.get(this.getRootFolder(), relativePath).toString(); | |
File dir = new File(fullPath); | |
try { | |
if (!dir.exists()) { | |
dir.mkdir(); | |
} | |
stream[0] = new FileOutputStream(Paths.get(fullPath, filename).toFile()); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
uri[0] = Paths.get(relativePath, filename).toString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(CreatePasswordProtectedOneNoteDocuments.class) + "load/"; | |
Document document = new Document(dataDir + "Sample1.one"); | |
OneSaveOptions saveOptions = new OneSaveOptions(); | |
saveOptions.setDocumentPassword("pass"); | |
document.save(dataDir + "CreatePasswordProtected_out.one", saveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document doc = new Document(); | |
// Returns NodeType.Document | |
System.out.println(doc.getNodeType()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ExtractOneNoteContentUsingDocumentvisitor extends DocumentVisitor { | |
final private StringBuilder mBuilder; | |
final private boolean mIsSkipText; | |
private int nodecount; | |
public ExtractOneNoteContentUsingDocumentvisitor() { | |
nodecount = 0; | |
mIsSkipText = false; | |
mBuilder = new StringBuilder(); | |
} | |
// Gets the plain text of the document that was accumulated by the visitor. | |
public String GetText() { | |
return mBuilder.toString(); | |
} | |
// Adds text to the current output. Honors the enabled/disabled output flag. | |
private void AppendText(String text) { | |
if (!mIsSkipText) | |
mBuilder.append(text); | |
} | |
// Called when a RichText node is encountered in the document. | |
public /* override */ void VisitRichTextStart(RichText run) { | |
++nodecount; | |
AppendText(run.getText()); | |
} | |
// Called when a Document node is encountered in the document. | |
public /* override */ void VisitDocumentStart(Document document) { | |
++nodecount; | |
} | |
// Called when a Page node is encountered in the document. | |
public /* override */ void VisitPageStart(Page page) { | |
++nodecount; | |
} | |
// Called when a Title node is encountered in the document. | |
public /* override */ void VisitTitleStart(Title title) { | |
++nodecount; | |
} | |
// Called when a Image node is encountered in the document. | |
public /* override */ void VisitImageStart(Image image) { | |
++nodecount; | |
} | |
// Called when a OutlineGroup node is encountered in the document. | |
public /* override */ void VisitOutlineGroupStart(OutlineGroup outlineGroup) { | |
++nodecount; | |
} | |
// Called when a Outline node is encountered in the document. | |
public void VisitOutlineStart(Outline outline) { | |
++nodecount; | |
} | |
// Called when a OutlineElement node is encountered in the document. | |
public void VisitOutlineElementStart(OutlineElement outlineElement) { | |
++nodecount; | |
} | |
// Gets the total count of nodes by the Visitor | |
public int NodeCount() { | |
return this.nodecount; | |
} | |
public static void main(String[] args) throws IOException { | |
// Open the document we want to convert. | |
String dataDir = Utils.getSharedDataDir(ExtractOneNoteContentUsingDocumentvisitor.class) + "load/"; | |
Document doc = new Document(dataDir + "Sample1.one", new LoadOptions()); | |
// Create an object that inherits from the DocumentVisitor class. | |
ExtractOneNoteContentUsingDocumentvisitor myConverter = new ExtractOneNoteContentUsingDocumentvisitor(); | |
// This is the well known Visitor pattern. Get the model to accept a | |
// visitor. | |
// The model will iterate through itself by calling the corresponding | |
// methods | |
// on the visitor object (this is called visiting). | |
// | |
// Note that every node in the object model has the Accept method so the | |
// visiting | |
// can be executed not only for the whole document, but for any node in | |
// the document. | |
doc.accept(myConverter); | |
// Once the visiting is complete, we can retrieve the result of the | |
// operation, | |
// that in this example, has accumulated in the visitor. | |
System.out.println(myConverter.GetText()); | |
System.out.println(myConverter.NodeCount()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
System.out.println("Family: " + AssemblyConstants.getFamily()); | |
System.out.println("Platform: " + AssemblyConstants.getPlatform()); | |
System.out.println("Product: " + AssemblyConstants.getProduct()); | |
System.out.println("Release date: " + AssemblyConstants.getReleaseDate()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetFileFormatInfo.class) + "load/"; | |
Document document = new Document(dataDir + "Aspose.one"); | |
switch (document.getFileFormat()) | |
{ | |
case FileFormat.OneNote2010: | |
// Process OneNote 2010 | |
break; | |
case FileFormat.OneNoteOnline: | |
// Process OneNote Online | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
// Load the document into Aspose.Note. | |
String inputFile = "Sample1.one"; | |
Path inputPath = Utils.getPath(LoadDocIntoAsposeNoteUsingPdfsaveoptions.class, inputFile); | |
String outputFile = "LoadDocIntoAsposeNoteUsingPdfsaveoptions.pdf"; | |
Path outputPath = Utils.getPath(LoadDocIntoAsposeNoteUsingPdfsaveoptions.class, outputFile); | |
Document oneFile = new Document(inputPath.toString()); | |
// Save the document as PDF | |
oneFile.save(outputPath.toString(), new PdfSaveOptions()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
// Load the document into Aspose.Note. | |
String inputFile = "Sample1.one"; | |
Path inputPath = Utils.getPath(LoadDocIntoAsposeNoteUsingSaveformat.class, inputFile); | |
String outputFile = "LoadDocIntoAsposeNoteUsingSaveformat.pdf"; | |
Path outputPath = Utils.getPath(LoadDocIntoAsposeNoteUsingSaveformat.class, outputFile); | |
Document oneFile = new Document(inputPath.toString()); | |
// Save the document as PDF | |
oneFile.save(outputPath.toString(), SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(LoadDocIntoAsposeNoteUsingSaveformat.class) + "load/"; | |
Document oneFile = new Document(dataDir + "Sample1.one"); | |
// Save the document as PDF | |
oneFile.save(dataDir + "LoadDocIntoAsposeNoteUsingSaveformat_out.pdf", SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
Document oneFile = new Document(dataDir + "Aspose.one"); | |
System.out.println(oneFile.getFileFormat()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(LoadPasswordProtectedOneNoteDoc.class) + "load/"; | |
LoadOptions loadOptions = new LoadOptions(); | |
loadOptions.setDocumentPassword("password"); | |
Document doc = new Document(dataDir + "Sample1.one", loadOptions); | |
System.out.println(doc.getFileFormat()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(OptimizeExportPerformance.class) + "load/"; | |
// initialize the new Document | |
Document doc = new Document(); | |
// Disable detection of layout changes | |
doc.setAutomaticLayoutChangesDetectionEnabled(false); | |
// Create a new Page | |
Page page = new Page(doc); | |
// Style for all text in the document. | |
ParagraphStyle textStyle = new ParagraphStyle(); | |
textStyle.setFontColor(Color.BLACK); | |
textStyle.setFontName("Arial"); | |
textStyle.setFontSize(10); | |
// Create title text | |
RichText titleText = new RichText(doc); | |
titleText.setText("Title text."); | |
titleText.setParagraphStyle(textStyle); | |
// Create title date | |
RichText titleDate = new RichText(doc); | |
titleDate.setText("2011,11,11"); | |
titleDate.setParagraphStyle(textStyle); | |
// Create title time | |
RichText titleTime = new RichText(doc); | |
titleTime.setText("12:34"); | |
titleTime.setParagraphStyle(textStyle); | |
// Add title to page | |
Title title = new Title(doc); | |
title.setTitleText(titleText); | |
title.setTitleDate(titleDate); | |
title.setTitleTime(titleTime); | |
page.setTitle(title); | |
// Add page to document | |
doc.appendChildLast(page); | |
// save OneNote document in the PDF format | |
doc.save(dataDir + "OptimizeExportPerformance_out.pdf"); | |
// Save document in the TIFF format | |
doc.save(dataDir + "OptimizeExportPerformance_out.tiff"); | |
// save OneNote document in the JPG format | |
doc.save(dataDir + "OptimizeExportPerformance_out.jpg"); | |
// set text font size | |
textStyle.setFontSize(24); | |
// Manually trigger layout detection | |
doc.detectLayoutChanges(); | |
// save OneNote document in the BMP format | |
doc.save(dataDir + "OptimizeExportPerformance_out.bmp"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(OptimizePerformanceForConsequentExportOperations.class) + "load/"; | |
// initialize the new Document | |
Document doc = new Document(); | |
doc.setAutomaticLayoutChangesDetectionEnabled(false); | |
// initialize the new Page | |
Page page = new Page(doc); | |
// default style for all text in the document. | |
ParagraphStyle textStyle = new ParagraphStyle(); | |
textStyle.setFontColor(Color.BLACK); | |
textStyle.setFontName("Arial"); | |
textStyle.setFontSize(10); | |
// title text | |
RichText titleText = new RichText(doc); | |
titleText.setText("Title text."); | |
titleText.setParagraphStyle(textStyle); | |
// title date | |
RichText titleDate = new RichText(doc); | |
titleDate.setText("2011,11,11"); | |
titleDate.setParagraphStyle(textStyle); | |
// title time | |
RichText titleTime = new RichText(doc); | |
titleTime.setText("12:34"); | |
titleTime.setParagraphStyle(textStyle); | |
Title title = new Title(doc); | |
title.setTitleText(titleText); | |
title.setTitleDate(titleDate); | |
title.setTitleTime(titleTime); | |
page.setTitle(title); | |
// append page node | |
doc.appendChildLast(page); | |
// save OneNote document in the HTML format | |
try { | |
doc.save(dataDir + "OptimizePerformanceForConsequentExportOperations_out.html"); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
// e.printStackTrace(); | |
System.out.println("Saving as Html: " + e.getMessage()); | |
} | |
// save OneNote document in the PDF format | |
try { | |
doc.save(dataDir + "OptimizePerformanceForConsequentExportOperations_out.pdf"); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
// e.printStackTrace(); | |
System.out.println("Saving as PDF: " + e.getMessage()); | |
} | |
// save OneNote document in the JPG format | |
try { | |
doc.save(dataDir + "OptimizePerformanceForConsequentExportOperations_out.jpg"); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
// e.printStackTrace(); | |
System.out.println("Saving as JPG: " + e.getMessage()); | |
} | |
// set text font size | |
textStyle.setFontSize(11); | |
// detect layout changes manually | |
doc.detectLayoutChanges(); | |
// save OneNote document in the BMP format | |
try { | |
doc.save(dataDir + "OptimizePerformanceForConsequentExportOperations_out.bmp"); | |
} catch (Exception e) { | |
// TODO Auto-generated catch block | |
// e.printStackTrace(); | |
System.out.println("Saving as bmp: " + e.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(SaveDocToOneNoteFormat.class) + "load/"; | |
Document doc = new Document(dataDir + "Sample1.one"); | |
doc.save(dataDir + "SaveDocToOneNoteFormat_out.one"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(SaveDocToOneNoteFormat.class) + "load/"; | |
Document document = new Document(dataDir + "Sample1.one"); | |
document.save(dataDir + "SaveDocToOneNoteFormatUsingOnesaveoptions_out.one", new OneSaveOptions()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(SaveDocToOneNoteFormatUsingSaveformat.class) + "load/"; | |
Document document = new Document(dataDir + "Sample1.one"); | |
document.save(dataDir + "SaveDocToOneNoteFormatUsingSaveformat_out.one", SaveFormat.One); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/"; | |
Document doc = new Document(dataDir + "Sample1.one"); | |
ByteArrayOutputStream dstStream = new ByteArrayOutputStream(); | |
doc.save(dstStream, SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(SaveOneNoteDocToStream.class) + "load/"; | |
// Load the document into Aspose.Note | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// Create a stream object | |
ByteArrayOutputStream stream = new ByteArrayOutputStream(); | |
// Save the document to stream as a PDF | |
doc.save(stream, SaveFormat.Pdf); | |
System.out.println("Stream Size: " + stream.size() + " bytes"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(SetOutputImageResolution.class) + "load/"; | |
Document doc = new Document(dataDir + "Sample1.one"); | |
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.Jpeg); | |
imageSaveOptions.setResolution(120); | |
doc.save(dataDir + "SetOutputImageResolution_out.jpeg", imageSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SpecifySaveOptions.class) + "load\\"; | |
// Load the document into Aspose.Note. | |
Document doc = new Document(dataDir + "Aspose.one"); | |
// Initialize PdfSaveOptions object | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
// Set page index | |
opts.setPageIndex(2); | |
// Set page count | |
opts.setPageCount(3); | |
//Specify compression if required | |
opts.setImageCompression(PdfImageCompression.Jpeg); | |
opts.setJpegQuality(90); | |
dataDir = dataDir + "Document.SaveWithOptions_out.pdf"; | |
doc.save(dataDir, opts); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.setPageSplittingAlgorithm(new AlwaysSplitObjectsAlgorithm()); | |
// Or | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepPartAndCloneSolidObjectToNextPageAlgorithm()); | |
// Or | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepSolidObjectsAlgorithm()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float heightLimitOfClonedPart = 500; | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepPartAndCloneSolidObjectToNextPageAlgorithm(heightLimitOfClonedPart)); | |
// Or | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepSolidObjectsAlgorithm(heightLimitOfClonedPart)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pdfSaveOptions.setPageSplittingAlgorithm(new KeepSolidObjectsAlgorithm(100)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pdfSaveOptions.setPageSplittingAlgorithm(new KeepSolidObjectsAlgorithm(400)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
float heightLimitOfClonedPart = 500; | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions | |
.setPageSplittingAlgorithm(new KeepPartAndCloneSolidObjectToNextPageAlgorithm(heightLimitOfClonedPart)); | |
// or | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepSolidObjectsAlgorithm(heightLimitOfClonedPart)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepSolidObjectsAlgorithm(100)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepSolidObjectsAlgorithm(400)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepPartAndCloneSolidObjectToNextPageAlgorithm(100)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepPartAndCloneSolidObjectToNextPageAlgorithm(400)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pdfSaveOptions.setPageSplittingAlgorithm(new KeepPartAndCloneSolidObjectToNextPageAlgorithm(100)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pdfSaveOptions.setPageSplittingAlgorithm(new KeepPartAndCloneSolidObjectToNextPageAlgorithm(400)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
String inputFile = "Sample1.one"; | |
Path inputPath = Utils.getPath(UsingSplittingAlgorithmMethod.class, inputFile); | |
String outputFile = "output.Jpeg"; | |
Path outputPath = Utils.getPath(UsingSplittingAlgorithmMethod.class, outputFile); | |
Document doc = new Document(inputPath.toString()); | |
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions(); | |
pdfSaveOptions.setPageSplittingAlgorithm(new AlwaysSplitObjectsAlgorithm()); | |
// or | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepPartAndCloneSolidObjectToNextPageAlgorithm()); | |
// or | |
pdfSaveOptions.setPageSplittingAlgorithm(new KeepSolidObjectsAlgorithm()); | |
try { | |
doc.save(outputPath.toString(), pdfSaveOptions); | |
} catch (Exception ex) { | |
System.out.println("Exception: " + ex.getMessage()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
License license = new License(); | |
license.setLicense("licenseFile"); | |
java.util.Locale.setDefault(new java.util.Locale("en", "rs")); | |
LocaleOptions.setLocale(Locale.US); | |
String inputFile = "Sample1.one"; | |
Path inputPath = Utils.getPath(SaveToStream.class, inputFile); | |
// Load the document into Aspose.Note | |
Document oneFile = new Document(inputPath.toString()); | |
oneFile.save("sample.png"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(AddChildNode.class) + "Notebook/"; | |
// Load a OneNote Notebook | |
Notebook notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2"); | |
// Append a new child to the Notebook | |
notebook.appendChild(new Document(dataDir + "Neuer Abschnitt 1.one")); | |
dataDir = dataDir + "AddChildNodetoOneNoteNotebook_out.onetoc2"; | |
// Save the Notebook | |
notebook.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ConvertToImage.class) + "Notebook/"; | |
// Load a OneNote Notebook | |
Notebook notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2"); | |
dataDir = dataDir + "ExportNotebooktoImage_out.png"; | |
// Save the Notebook | |
notebook.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ConvertToImageAsFlattenedNotebook.class) + "Notebook/"; | |
Notebook notebook = new Notebook(dataDir + "test.onetoc2"); | |
NotebookImageSaveOptions saveOptions = new NotebookImageSaveOptions(SaveFormat.Png); | |
ImageSaveOptions documentSaveOptions = saveOptions.getDocumentSaveOptions(); | |
documentSaveOptions.setResolution(400); | |
saveOptions.setFlatten(true); | |
notebook.save(dataDir + "ExportImageasFlattenedNotebook_out.png", saveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ConvertToImageWithOptions.class) + "Notebook/"; | |
// Load a OneNote Notebook | |
Notebook notebook = new Notebook(dataDir + "test.onetoc2"); | |
NotebookImageSaveOptions notebookSaveOptions = new NotebookImageSaveOptions(SaveFormat.Png); | |
ImageSaveOptions documentSaveOptions = notebookSaveOptions.getDocumentSaveOptions(); | |
documentSaveOptions.setResolution(400); | |
dataDir = dataDir + "ExportNotebooktoImagewithOptions_out.png"; | |
// Save the Notebook | |
notebook.save(dataDir, notebookSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ConvertToPDF.class) + "Notebook/"; | |
// Load a OneNote Notebook | |
Notebook notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2"); | |
dataDir = dataDir + "ExportNotebooktoPDF_out.pdf"; | |
// Save the Notebook | |
notebook.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ConvertToPDFAsFlattened.class) + "Notebook/"; | |
// Load a OneNote Notebook | |
Notebook notebook = new Notebook(dataDir + "Notizbuch îffnen.onetoc2"); | |
NotebookPdfSaveOptions notebookSaveOptions = new NotebookPdfSaveOptions(); | |
notebookSaveOptions.setFlatten(true); | |
dataDir = dataDir + "ExportNotebookToPDFAsFlattened_out.pdf"; | |
// Save the Notebook | |
notebook.save(dataDir, notebookSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ConvertToPDFWithOptions.class) + "Notebook/"; | |
// Load a OneNote Notebook | |
Notebook notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2"); | |
NotebookPdfSaveOptions notebookSaveOptions = new NotebookPdfSaveOptions(); | |
PdfSaveOptions documentSaveOptions = notebookSaveOptions.getDocumentSaveOptions(); | |
documentSaveOptions.setPageSplittingAlgorithm (new KeepSolidObjectsAlgorithm()); | |
dataDir = dataDir + "ExportNotebooktoPDFwithOptions_out.pdf"; | |
// Save the Notebook | |
notebook.save(dataDir, notebookSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ExportNotebookToPDFAsFlattened.class) + "Notebook/"; | |
// Load a OneNote Notebook | |
Notebook notebook = new Notebook(dataDir + "Notizbuch îffnen.onetoc2"); | |
NotebookPdfSaveOptions notebookSaveOptions = new NotebookPdfSaveOptions(); | |
notebookSaveOptions.setFlatten(true); | |
dataDir = dataDir + "ExportNotebookToPDFAsFlattened_out.pdf"; | |
// Save the Notebook | |
notebook.save(dataDir, notebookSaveOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(LoadingNotebook.class) + "Notebook/"; | |
Notebook notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2"); | |
for (INotebookChildNode notebookChildNode : notebook) { | |
System.out.println(notebookChildNode.getDisplayName()); | |
if (notebookChildNode instanceof Document) { | |
// Do something with child document | |
} else if (notebookChildNode instanceof Notebook) { | |
// Do something with child notebook | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(LoadingNotebookFilewithLoadOptions.class) + "Notebook/"; | |
// By default children loading is "lazy". | |
Notebook notebook = new Notebook(dataDir + "test.onetoc2"); | |
for (INotebookChildNode notebookChildNode : notebook) { | |
// Actual loading of the child document happens only here. | |
if (notebookChildNode instanceof Document) { | |
// Do something with child document | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// By default children loading is "lazy". | |
// Therefore for instant loading has took place, | |
// it is necessary to set the NotebookLoadOptions.InstantLoading flag. | |
NotebookLoadOptions loadOptions = new NotebookLoadOptions(); | |
loadOptions.setInstantLoading(true); | |
String dataDir = Utils.getSharedDataDir(LoadingNotebookInstantly.class) + "Notebook/"; | |
Notebook notebook = new Notebook(dataDir + "test.onetoc2", loadOptions); | |
// All child documents are already loaded. | |
for (INotebookChildNode notebookChildNode : notebook) { | |
if (notebookChildNode instanceof Document) { | |
// Do something with child document | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(LoadPasswordProtectedDocuments.class) + "Notebook/"; | |
NotebookLoadOptions loadOptions = new NotebookLoadOptions(); | |
loadOptions.setDeferredLoading(true); | |
Notebook notebook = new Notebook(dataDir + "Notizbuch �ffnen.onetoc2", loadOptions); | |
notebook.loadChildDocument(dataDir + "Neuer Abschnitt 1.one"); | |
LoadOptions documentLoadOptions1 = new LoadOptions(); | |
documentLoadOptions1.setDocumentPassword("pass"); | |
notebook.loadChildDocument(dataDir + "Locked Pass1.one", documentLoadOptions1); | |
LoadOptions documentLoadOptions2 = new LoadOptions(); | |
documentLoadOptions2.setDocumentPassword("pass"); | |
notebook.loadChildDocument(dataDir + "Locked Pass2.one", documentLoadOptions2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(LoadingNotebook.class) + "Notebook/"; | |
Notebook rootNotebook = new Notebook(dataDir + "test.onetoc2"); | |
List<RichText> allRichTextNodes = rootNotebook.getChildNodes(RichText.class); | |
for (RichText richTextNode : allRichTextNodes) { | |
System.out.println(richTextNode.getText()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(RemoveChildNode.class) + "Notebook/"; | |
// Load a OneNote Notebook | |
Notebook notebook = new Notebook(dataDir + "test.onetoc2"); | |
// Traverse through its child nodes for searching the desired child item | |
for (INotebookChildNode child : new List<>(notebook)) | |
{ | |
if (child.getDisplayName() == "Remove Me") | |
{ | |
// Remove the Child Item from the Notebook | |
notebook.removeChild(child); | |
} | |
} | |
dataDir = dataDir + "RemoveChildNodeFromOneNoteNotebook_out.onetoc2"; | |
// Save the Notebook | |
notebook.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(RetrieveDocumentsfromOneNoteNotebook.class) + "Notebook/"; | |
Notebook rootNotebook = new Notebook(dataDir + "test.onetoc2"); | |
List<Document> allDocuments = rootNotebook.getChildNodes(Document.class); | |
for (Document document : allDocuments) { | |
System.out.println(document.getDisplayName()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(SaveNotebooktoStream.class) + "Notebook/"; | |
Notebook notebook = new Notebook(); | |
FileOutputStream stream = new FileOutputStream(dataDir + "output.onetoc2"); | |
notebook.save(stream); | |
if (notebook.getCount() > 0) { | |
Document childDocument0 = (Document) notebook.get_Item(0); | |
OutputStream childStream = new FileOutputStream(dataDir + "childStream.one"); | |
childDocument0.save(childStream); | |
Document childDocument1 = (Document) notebook.get_Item(1); | |
childDocument1.save(dataDir + "child.one"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
String dataDir = Utils.getSharedDataDir(WritingPasswordProtectedDoc.class) + "Notebook/"; | |
Notebook notebook = new Notebook(); | |
NotebookOneSaveOptions saveOptions = new NotebookOneSaveOptions(); | |
saveOptions.setDeferredSaving(true); | |
notebook.save(dataDir + "Open Notebook.onetoc2", saveOptions); | |
Document childDocument0 = (Document) notebook.get_Item(0); | |
childDocument0.save(dataDir + "Not Locked.one"); | |
Document childDocument1 = (Document) notebook.get_Item(1); | |
OneSaveOptions documentSaveOptions1 = new OneSaveOptions(); | |
documentSaveOptions1.setDocumentPassword("pass1"); | |
childDocument1.save(dataDir + "Locked Pass1.one", documentSaveOptions1); | |
Document childDocument2 = (Document) notebook.get_Item(2); | |
OneSaveOptions documentSaveOptions2 = new OneSaveOptions(); | |
documentSaveOptions2.setDocumentPassword("pass2"); | |
childDocument2.save(dataDir + "Locked Pass2.one", documentSaveOptions2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetInfo.class) + "pages/"; | |
// Load the document into Aspose.Note | |
LoadOptions options = new LoadOptions(); | |
Document doc = new Document(dataDir + "Aspose.one", options); | |
DateFormat df = new SimpleDateFormat("dd.MM.yyyy HH.mm.ss"); | |
PageHistory history = doc.getPageHistory(doc.getFirstChild()); | |
for (int i = 0; i < history.size(); i++) | |
{ | |
Page historyPage = history.get_Item(i); | |
System.out.format(" %d. Author: %s, %s", | |
i, | |
historyPage.getPageContentRevisionSummary().getAuthorMostRecent(), | |
df.format(historyPage.getPageContentRevisionSummary().getLastModifiedTime())); | |
System.out.println(historyPage.isConflictPage() ? ", IsConflict: true" : ""); | |
// By default conflict pages are just skipped on saving. | |
// If mark it as non-conflict then it will be saved as usual one in the history. | |
if (historyPage.isConflictPage()) | |
historyPage.setConflictPage(false); | |
} | |
doc.save(dataDir + "ConflictPageManipulation_out.one", SaveFormat.One); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(CreateDocWithRootAndSubPages.class) + "pages/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object and set its level | |
Page page1 = new Page(doc); | |
page1.setLevel((byte) 1); | |
// initialize Page class object and set its level | |
Page page2 = new Page(doc); | |
page1.setLevel((byte) 2); | |
// initialize Page class object and set its level | |
Page page3 = new Page(doc); | |
page1.setLevel((byte) 1); | |
// ---------- Adding nodes to first Page ---------- | |
Outline outline = new Outline(doc); | |
OutlineElement outlineElem = new OutlineElement(doc); | |
ParagraphStyle textStyle = new ParagraphStyle(); | |
textStyle.setFontColor(java.awt.Color.black); | |
textStyle.setFontName("David Transparent"); | |
textStyle.setFontSize(10); | |
RichText text = new RichText(doc); | |
text.setText("First page."); | |
text.setParagraphStyle(textStyle); | |
outlineElem.appendChildLast(text); | |
outline.appendChildLast(outlineElem); | |
page1.appendChildLast(outline); | |
// ---------- Adding nodes to second Page ---------- | |
Outline outline2 = new Outline(doc); | |
OutlineElement outlineElem2 = new OutlineElement(doc); | |
// var textStyle2 = new TextStyle { FontColor = Color.Black, FontName = | |
// "Arial", FontSize = 10 }; | |
ParagraphStyle textStyle2 = new ParagraphStyle(); | |
textStyle2.setFontColor(java.awt.Color.black); | |
textStyle2.setFontName("David Transparent"); | |
textStyle2.setFontSize(10); | |
// var text2 = new RichText(doc) { Text = "Second page.", DefaultStyle = | |
// textStyle2 }; | |
RichText text2 = new RichText(doc); | |
text2.setText("Second page."); | |
text2.setParagraphStyle(textStyle2); | |
outlineElem2.appendChildLast(text2); | |
outline2.appendChildLast(outlineElem2); | |
page2.appendChildLast(outline2); | |
// ---------- Adding nodes to third Page ---------- | |
Outline outline3 = new Outline(doc); | |
OutlineElement outlineElem3 = new OutlineElement(doc); | |
ParagraphStyle textStyle3 = new ParagraphStyle(); | |
textStyle3.setFontColor(java.awt.Color.black); | |
textStyle3.setFontName("Broadway"); | |
textStyle3.setFontSize(10); | |
RichText text3 = new RichText(doc); | |
text3.setText("Third page."); | |
text3.setParagraphStyle(textStyle3); | |
outlineElem3.appendChildLast(text3); | |
outline3.appendChildLast(outlineElem3); | |
page3.appendChildLast(outline3); | |
// ---------- Add pages to the OneNote Document ---------- | |
doc.appendChildLast(page1); | |
doc.appendChildLast(page2); | |
doc.appendChildLast(page3); | |
try { | |
doc.save(dataDir + "GenerateRootAndSubLevelPagesInOneNote_out.bmp", SaveFormat.Bmp); | |
} catch (IOException e) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetInfo.class) + "pages/"; | |
// Load the document into Aspose.Note | |
LoadOptions options = new LoadOptions(); | |
Document doc = new Document(dataDir + "Sample1.one", options); | |
// Get page revisions | |
List<Page> pages = doc.getChildNodes(Page.class); | |
// Traverse list of pages | |
for (Page pageRevision : pages) { | |
System.out.println("LastModifiedTime: " + pageRevision.getLastModifiedTime()); | |
System.out.println("CreationTime: " + pageRevision.getCreationTime()); | |
System.out.println("Title: " + pageRevision.getTitle()); | |
System.out.println("Level: " + pageRevision.getLevel()); | |
System.out.println("Author: " + pageRevision.getAuthor()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetPageCount.class) + "pages/"; | |
// Load the document into Aspose.Note | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// Get number of pages | |
int count = doc.getChildNodes(Page.class).size(); | |
// Print page count | |
System.out.printf("Total Pages: %s", count); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetPageRevisions.class) + "pages/"; | |
LoadOptions loadOptions = new LoadOptions(); | |
loadOptions.setLoadHistory(true); | |
// load OneNote document | |
Document document = new Document(dataDir + "Sample1.one", loadOptions); | |
// get first page | |
Page firstPage = document.getFirstChild(); | |
for (Page pageRevision : document.getPageHistory(firstPage)) { | |
// Use pageRevision like a regular page. | |
System.out.println("LastModifiedTime: " + pageRevision.getLastModifiedTime()); | |
System.out.println("CreationTime: " + pageRevision.getCreationTime()); | |
System.out.println("Title: " + pageRevision.getTitle()); | |
System.out.println("Level: " + pageRevision.getLevel()); | |
System.out.println("Author: " + pageRevision.getAuthor()); | |
System.out.println(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetRevisions.class) + "pages/"; | |
// Load the document into Aspose.Note | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// Get first page | |
Page firstPage = doc.getFirstChild(); | |
// Get page revisions | |
PageHistory revisions = doc.getPageHistory(firstPage); | |
// Traverse list of page revisions | |
for (Page pageRevision : revisions) { | |
System.out.println("LastModifiedTime: " + pageRevision.getLastModifiedTime()); | |
System.out.println("CreationTime: " + pageRevision.getCreationTime()); | |
System.out.println("Title: " + pageRevision.getTitle()); | |
System.out.println("Level: " + pageRevision.getLevel()); | |
System.out.println("Author: " + pageRevision.getAuthor()); | |
System.out.println(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-note/Aspose.Note-for-Java | |
// create an object of the Document class | |
Document doc = new Document(); | |
// Initialize Page class object and set its level | |
Page page1 = new Page(doc); | |
page1.setLevel((byte) 1); | |
// Initialize Page class object and set its level | |
Page page2 = new Page(doc); | |
page1.setLevel((byte) 2); | |
// Initialize Page class object and set its level | |
Page page3 = new Page(doc); | |
page1.setLevel((byte) 1); | |
// Adding nodes to first Page | |
Outline outline = new Outline(doc); | |
OutlineElement outlineElem = new OutlineElement(doc); | |
TextStyle textStyle = new TextStyle(); | |
textStyle.setFontColor(java.awt.Color.black); | |
textStyle.setFontName("David Transparent"); | |
textStyle.setFontSize(10); | |
RichText text = new RichText(doc); | |
text.setText("First page."); | |
text.setDefaultStyle(textStyle); | |
outlineElem.appendChild(text); | |
outline.appendChild(outlineElem); | |
page1.appendChild(outline); | |
// Adding nodes to second Page | |
Outline outline2 = new Outline(doc); | |
OutlineElement outlineElem2 = new OutlineElement(doc); | |
TextStyle textStyle2 = new TextStyle(); | |
textStyle2.setFontColor(java.awt.Color.black); | |
textStyle2.setFontName("David Transparent"); | |
textStyle2.setFontSize(10); | |
RichText text2 = new RichText(doc); | |
text2.setText("Second page."); | |
text2.setDefaultStyle(textStyle2); | |
outlineElem2.appendChild(text2); | |
outline2.appendChild(outlineElem2); | |
page2.appendChild(outline2); | |
// Adding nodes to third Page | |
Outline outline3 = new Outline(doc); | |
OutlineElement outlineElem3 = new OutlineElement(doc); | |
TextStyle textStyle3 = new TextStyle(); | |
textStyle3.setFontColor(java.awt.Color.black); | |
textStyle3.setFontName("Broadway"); | |
textStyle3.setFontSize(10); | |
RichText text3 = new RichText(doc); | |
text3.setText("Third page."); | |
text3.setDefaultStyle(textStyle3); | |
outlineElem3.appendChild(text3); | |
outline3.appendChild(outlineElem3); | |
page3.appendChild(outline3); | |
// Add pages to the OneNote Document | |
doc.appendChild(page1); | |
doc.appendChild(page2); | |
doc.appendChild(page3); | |
Path outputBmp = Utils.getPath(InsertPages.class, "Output.bmp"); | |
doc.save(outputBmp.toString(), SaveFormat.Bmp); | |
System.out.printf("File Saved: %s\n", outputBmp); | |
Path outputPdf = Utils.getPath(InsertPages.class, "Output.pdf"); | |
doc.save(outputPdf.toString(), SaveFormat.Pdf); | |
System.out.printf("File Saved: %s\n", outputPdf); | |
Path outputGif = Utils.getPath(InsertPages.class, "Output.gif"); | |
doc.save(outputGif.toString(), SaveFormat.Gif); | |
System.out.printf("File Saved: %s\n", outputGif); | |
Path outputJpg = Utils.getPath(InsertPages.class, "Output.jpg"); | |
doc.save(outputJpg.toString(), SaveFormat.Jpeg); | |
System.out.printf("File Saved: %s\n", outputJpg); | |
Path outputPng = Utils.getPath(InsertPages.class, "Output.png"); | |
doc.save(outputPng.toString(), SaveFormat.Png); | |
System.out.printf("File Saved: %s\n", outputPng); | |
Path outputTiff = Utils.getPath(InsertPages.class, "Output.tiff"); | |
doc.save(outputTiff.toString(), SaveFormat.Tiff); | |
System.out.printf("File Saved: %s\n", outputTiff); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(InsertPages.class) + "pages/"; | |
// Load OneNote document and get first child | |
Document document = new Document(dataDir + "Sample1.one"); | |
Page page = document.getFirstChild(); | |
PageHistory pageHistory = document.getPageHistory(page); | |
pageHistory.removeRange(0, 1); | |
pageHistory.set_Item(0, new Page(document)); | |
pageHistory.get_Item(1).getTitle().getTitleText().setText("New Title"); | |
pageHistory.addItem(new Page(document)); | |
pageHistory.insertItem(1, new Page(document)); | |
document.save(dataDir + "ModifyPageHistory_out.one"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(InsertPages.class) + "pages/"; | |
// Load OneNote document and get first child | |
Document document = new Document(dataDir + "Sample1.one"); | |
Page page = document.getFirstChild(); | |
PageHistory pageHistory = document.getPageHistory(page); | |
pageHistory.addItem(page.deepClone()); | |
document.save(dataDir + "PushCurrentPageVersion_out.one"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(InsertPages.class) + "pages/"; | |
// Load OneNote document and get first child | |
Document document = new Document(dataDir + "Sample1.one"); | |
Page page = document.getFirstChild(); | |
PageHistory pageHistory = document.getPageHistory(page); | |
document.removeChild(page); | |
document.appendChildLast(pageHistory.get_Item(pageHistory.size() - 1)); | |
document.save(dataDir + "RollBackToPreviousPageVersion_out.one"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(WorkingWithPageRevisions.class) + "pages\\"; | |
// Load OneNote document and get first child | |
Document document = new Document(dataDir + "Sample1.one"); | |
Page page = document.getFirstChild(); | |
// Reading Content Revision Summary for this page | |
RevisionSummary pageRevisionInfo = page.getPageContentRevisionSummary(); | |
System.out.println(String.format("Author:\t%s\nModified:\t%s", | |
pageRevisionInfo.getAuthorMostRecent(), | |
pageRevisionInfo.getLastModifiedTime().toString())); | |
// Update Page Revision Summary for this page | |
pageRevisionInfo.setAuthorMostRecent("New Author"); | |
Calendar modifiedDate = Calendar.getInstance(); | |
pageRevisionInfo.setLastModifiedTime(modifiedDate.getTime()); | |
document.save(dataDir + "WorkingWithPageRevisions_out.one"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(AlternativeText.class) + "load/"; | |
Document document = new Document(dataDir + "Aspose.one"); | |
document.print(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Prints 3 copies of first and second pages using virtual pdf printer doPDF 8 | |
//It is free and can be downloaded here http://www.dopdf.com/download.php | |
String dataDir = Utils.getSharedDataDir(AlternativeText.class) + "load/"; | |
Document doc = new Document(dataDir + "test.one"); | |
final DocumentPrintAttributeSet asposeAttr = new DocumentPrintAttributeSet("doPDF 8"); | |
asposeAttr.setPrintRange(1, 2); | |
asposeAttr.setCopies(3); | |
PrintOptions printOptions = new PrintOptions(); | |
printOptions.setDocumentName("Test.one"); | |
printOptions.setPrinterSettings(asposeAttr); | |
doc.print(printOptions); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(AlternativeText.class) + "load/"; | |
Document document = new Document(dataDir + "Aspose.one"); | |
//Prints first and second pages using Microsoft XPS Document Writer | |
final DocumentPrintAttributeSet asposeAttr = new DocumentPrintAttributeSet("Microsoft XPS Document Writer"); | |
asposeAttr.setPrintRange(1, 2); | |
//Uncomment line below to retarget output to specified file. | |
//This functionality is supported by Microsoft XPS Document Writer. | |
//It is not guaranteed that other printers support it. | |
//asposeAttr.add(new Destination((new java.io.File("./out.xps")).toURI())); | |
document.print(asposeAttr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ChangeTextStyle.class) + "styles/"; | |
// Load the document into Aspose.Note | |
Document document = new Document(dataDir + "Sample1.one"); | |
// Get a particular RichText node | |
List<RichText> richTextNodes = document.getChildNodes(RichText.class); | |
RichText richText = richTextNodes.get(0); | |
for (TextStyle style : richText.getStyles()) { | |
// Set font color | |
style.setFontColor(Color.yellow); | |
// Set highlight color | |
style.setHighlight(Color.blue); | |
// Set font size | |
style.setFontSize(20); | |
} | |
document.save(dataDir + "ChangeTextStyle_out.pdf"); | |
System.out.printf("File saved: %s\n", dataDir + "ChangeTextStyle_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(CreateTableWithLockedColumns.class) + "tables\\"; | |
// Create an object of the Document class | |
Document doc = new Document(); | |
// Initialize Page class object | |
Page page = new Page(doc); | |
// Initialize TableRow class object | |
TableRow row1 = new TableRow(doc); | |
// Initialize TableCell class object and set text content | |
TableCell cell11 = new TableCell(doc); | |
cell11.appendChildLast(InsertTable.GetOutlineElementWithText(doc, "Small text")); | |
row1.appendChildLast(cell11); | |
// Initialize TableRow class object | |
TableRow row2 = new TableRow(doc); | |
// Initialize TableCell class object and set text content | |
TableCell cell21 = new TableCell(doc); | |
cell21.appendChildLast(InsertTable.GetOutlineElementWithText(doc, "Long text with several words and spaces.")); | |
row2.appendChildLast(cell21); | |
// Initialize Table class object | |
Table table = new Table(doc); | |
table.setBordersVisible(true); | |
TableColumn col = new TableColumn(); | |
col.setWidth(200); | |
col.setLockedWidth(true); | |
table.getColumns().addItem(col); | |
// Add rows | |
table.appendChildLast(row1); | |
table.appendChildLast(row2); | |
Outline outline = new Outline(doc); | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// Add table node | |
outlineElem.appendChildLast(table); | |
// Add outline element node | |
outline.appendChildLast(outlineElem); | |
// Add outline node | |
page.appendChildLast(outline); | |
// Add page node | |
doc.appendChildLast(page); | |
dataDir = dataDir + "CreateTableWithLockedColumns_out.one"; | |
doc.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ExtractRowtextfromtableinOneNotedocument.class) + "tables/"; | |
// Load the document into Aspose.Note. | |
Document document = new Document(dataDir + "Sample1.one", new LoadOptions()); | |
// Get a list of table nodes | |
List<Table> nodes = (List<Table>) document.getChildNodes(Table.class); | |
// Set row count | |
int rowCount = 0; | |
for (Table table : nodes) { | |
// Iterate through table rows | |
for (TableRow row : table) { | |
rowCount++; | |
// Retrieve text | |
List<RichText> textNodes = (List<RichText>) row.getChildNodes(RichText.class); | |
StringBuilder text = new StringBuilder(); | |
for (RichText richText : textNodes) { | |
text = text.append(richText.getText().toString()); | |
} | |
// Print text on the output screen | |
System.out.println(text); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ExtractTextFromTable.class) + "tables/"; | |
// Load the document into Aspose.Note | |
Document document = new Document(dataDir + "Sample1.one"); | |
// Get a list of table nodes | |
List<Table> nodes = document.getChildNodes(Table.class); | |
for (int i = 0; i < nodes.size(); i++) { | |
Table table = nodes.get(i); | |
System.out.println("Table # " + i); | |
// Retrieve text | |
List<RichText> textNodes = (List<RichText>) table.getChildNodes(RichText.class); | |
StringBuilder text = new StringBuilder(); | |
for (RichText richText : textNodes) { | |
text = text.append(richText.getText().toString()); | |
} | |
// Print text on the output screen | |
System.out.println(text); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetCellTextFromRowOfTable.class) + "tables/"; | |
// Load the document into Aspose.Note. | |
Document document = new Document(dataDir + "Sample1.one"); | |
// Get a list of table nodes | |
List<Table> nodes = (List<Table>) document.getChildNodes(Table.class); | |
for (Table table : nodes) { | |
// Iterate through table rows | |
for (TableRow row : table) { | |
// Get list of TableCell nodes | |
List<TableCell> cellNodes = (List<TableCell>) row.getChildNodes(TableCell.class); | |
// iterate through table cells | |
for (TableCell cell : cellNodes) { | |
// Retrieve text | |
List<RichText> textNodes = (List<RichText>) cell.getChildNodes(RichText.class); | |
StringBuilder text = new StringBuilder(); | |
for (RichText richText : textNodes) { | |
text = text.append(richText.getText().toString()); | |
} | |
// Print text on the output screen | |
System.out.println(text); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static OutlineElement GetOutlineElementWithText(Document doc, String text) | |
{ | |
OutlineElement outlineElem = new OutlineElement(doc); | |
ParagraphStyle textStyle = new ParagraphStyle(); | |
textStyle.setFontColor(Color.BLACK); | |
textStyle.setFontName("Arial"); | |
textStyle.setFontSize(10);; | |
RichText richText = new RichText(doc); | |
richText.setText(text); | |
richText.setParagraphStyle(textStyle); | |
outlineElem.appendChildLast(richText); | |
return outlineElem; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to th documents directory. | |
String dataDir = Utils.getSharedDataDir(InsertTable.class) + "tables\\"; | |
Document doc = new Document(); | |
// Initialize Page class object | |
Page page = new Page(doc); | |
// Initialize TableRow class object | |
TableRow row1 = new TableRow(doc); | |
// Initialize TableCell class objects | |
TableCell cell11 = new TableCell(doc); | |
TableCell cell12 = new TableCell(doc); | |
TableCell cell13 = new TableCell(doc); | |
// Append outline elements in the table cell | |
cell11.appendChildLast(GetOutlineElementWithText(doc, "cell_1.1")); | |
cell12.appendChildLast(GetOutlineElementWithText(doc, "cell_1.2")); | |
cell13.appendChildLast(GetOutlineElementWithText(doc, "cell_1.3")); | |
// Table cells to rows | |
row1.appendChildLast(cell11); | |
row1.appendChildLast(cell12); | |
row1.appendChildLast(cell13); | |
// Initialize TableRow class object | |
TableRow row2 = new TableRow(doc); | |
// initialize TableCell class objects | |
TableCell cell21 = new TableCell(doc); | |
TableCell cell22 = new TableCell(doc); | |
TableCell cell23 = new TableCell(doc); | |
// Append outline elements in the table cell | |
cell21.appendChildLast(GetOutlineElementWithText(doc, "cell_2.1")); | |
cell22.appendChildLast(GetOutlineElementWithText(doc, "cell_2.2")); | |
cell23.appendChildLast(GetOutlineElementWithText(doc, "cell_2.3")); | |
// Append table cells to rows | |
row2.appendChildLast(cell21); | |
row2.appendChildLast(cell22); | |
row2.appendChildLast(cell23); | |
// Initialize Table class object and set column widths | |
Table table = new Table(doc); | |
table.setBordersVisible(true); | |
TableColumn col = new TableColumn(); | |
col.setWidth(200); | |
table.getColumns().addItem(col); | |
table.getColumns().addItem(col); | |
table.getColumns().addItem(col); | |
// Append table rows to table | |
table.appendChildLast(row1); | |
table.appendChildLast(row2); | |
// Initialize Outline object | |
Outline outline = new Outline(doc); | |
// Initialize OutlineElement object | |
OutlineElement outlineElem = new OutlineElement(doc); | |
// Add table to outline element node | |
outlineElem.appendChildLast(table); | |
// Add outline element to outline | |
outline.appendChildLast(outlineElem); | |
// Add outline to page node | |
page.appendChildLast(outline); | |
// Add page to document node | |
doc.appendChildLast(page); | |
dataDir = dataDir + "InsertTable_out.one"; | |
doc.save(dataDir); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static OutlineElement GetOutlineElementWithText(Document doc, String string) { | |
// TODO Auto-generated method stub | |
OutlineElement outlineElem = new OutlineElement(doc); | |
ParagraphStyle textStyle = new ParagraphStyle(); | |
textStyle.setFontColor(Color.BLACK); | |
textStyle.setFontName("Arial"); | |
textStyle.setFontSize(10); | |
RichText richText = new RichText(doc); | |
richText.setText(string); | |
richText.setParagraphStyle(textStyle); | |
outlineElem.appendChildLast(richText); | |
return outlineElem; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the document into Aspose.Note. | |
Document doc = new Document(); | |
// Initialize TableRow class object | |
TableRow row1 = new TableRow(doc); | |
// Initialize TableCell class object and set text content | |
TableCell cell11 = new TableCell(doc); | |
cell11.appendChildLast(GetOutlineElementWithText(doc, "Small text")); | |
cell11.setBackgroundColor(Color.BLACK); | |
row1.appendChildLast(cell11); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetOutlookTask.class) + "tasks/"; | |
// Load the document into Aspose.Note | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// Get all RichText nodes | |
List<RichText> nodes = (List<RichText>) doc.getChildNodes(RichText.class); | |
// Iterate through each node | |
for (RichText richText : nodes) { | |
for (NoteTagCore tag : richText.getTags()) { | |
if (tag.getClass() == NoteTask.class) { | |
NoteTask noteTask = (NoteTask) tag; | |
// Retrieve properties | |
System.out.println("Completed Time: " + noteTask.getCompletedTime()); | |
System.out.println("Create Time: " + noteTask.getCreationTime()); | |
System.out.println("Due Date: " + noteTask.getDueDate()); | |
System.out.println("Status: " + noteTask.getStatus()); | |
System.out.println("Task Type: " + noteTask.getTaskType()); | |
System.out.println("Icon: " + noteTask.getIcon()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(CreateBulletedList.class) + "text/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Outline class object | |
Outline outline = new Outline(doc); | |
// initialize TextStyle class object and set formatting properties | |
ParagraphStyle defaultStyle = new ParagraphStyle(); | |
defaultStyle.setFontColor(Color.black); | |
defaultStyle.setFontName("Arial"); | |
defaultStyle.setFontSize(10); | |
// initialize OutlineElement class objects and apply bullets | |
OutlineElement outlineElem1 = new OutlineElement(doc); | |
outlineElem1.setNumberList(new NumberList("*", "Arial", 10)); | |
// initialize RichText class object and apply text style | |
RichText text1 = new RichText(doc); | |
text1.setText("First"); | |
text1.setParagraphStyle(defaultStyle); | |
outlineElem1.appendChildLast(text1); | |
OutlineElement outlineElem2 = new OutlineElement(doc); | |
outlineElem2.setNumberList(new NumberList("*", "Arial", 10)); | |
RichText text2 = new RichText(doc); | |
text2.setText("Second"); | |
text2.setParagraphStyle(defaultStyle); | |
outlineElem2.appendChildLast(text2); | |
OutlineElement outlineElem3 = new OutlineElement(doc); | |
outlineElem3.setNumberList(new NumberList("*", "Arial", 10)); | |
RichText text3 = new RichText(doc); | |
text3.setText("Third"); | |
text3.setParagraphStyle(defaultStyle); | |
outlineElem3.appendChildLast(text3); | |
// add outline elements | |
outline.appendChildLast(outlineElem1); | |
outline.appendChildLast(outlineElem2); | |
outline.appendChildLast(outlineElem3); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
// save the document | |
doc.save(dataDir + "CreateBulletedList_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(CreateChineseNumberedList.class) + "text/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Outline class object | |
Outline outline = new Outline(doc); | |
// initialize TextStyle class object and set formatting properties | |
ParagraphStyle defaultStyle = new ParagraphStyle(); | |
defaultStyle.setFontColor(Color.black); | |
defaultStyle.setFontName("Arial"); | |
defaultStyle.setFontSize(10); | |
// initialize OutlineElement class objects and apply numbering | |
// numbers in the same outline are automatically incremented. | |
OutlineElement outlineElem1 = new OutlineElement(doc); | |
outlineElem1.setNumberList(new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10)); | |
RichText text1 = new RichText(doc); | |
text1.setText("First"); | |
text1.setParagraphStyle(defaultStyle); | |
outlineElem1.appendChildLast(text1); | |
OutlineElement outlineElem2 = new OutlineElement(doc); | |
outlineElem2.setNumberList(new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10)); | |
RichText text2 = new RichText(doc); | |
text2.setText("Second"); | |
text2.setParagraphStyle(defaultStyle); | |
outlineElem2.appendChildLast(text2); | |
OutlineElement outlineElem3 = new OutlineElement(doc); | |
outlineElem3.setNumberList(new NumberList("{0})", NumberFormat.ChineseCounting, "Arial", 10)); | |
RichText text3 = new RichText(doc); | |
text3.setText("Third"); | |
text3.setParagraphStyle(defaultStyle); | |
outlineElem3.appendChildLast(text3); | |
// add outline elements | |
outline.appendChildLast(outlineElem1); | |
outline.appendChildLast(outlineElem2); | |
outline.appendChildLast(outlineElem3); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
// save the document | |
doc.save(dataDir + "CreateChineseNumberedList_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(CreateNumberedList.class) + "text/"; | |
// create an object of the Document class | |
Document doc = new Document(); | |
// initialize Page class object | |
Page page = new Page(doc); | |
// initialize Outline class object | |
Outline outline = new Outline(doc); | |
// initialize TextStyle class object and set formatting properties | |
ParagraphStyle defaultStyle = new ParagraphStyle(); | |
defaultStyle.setFontColor(Color.black); | |
defaultStyle.setFontName("Arial"); | |
defaultStyle.setFontSize(10); | |
// initialize OutlineElement class objects and apply numbering | |
// numbers in the same outline are automatically incremented. | |
OutlineElement outlineElem1 = new OutlineElement(doc); | |
outlineElem1.setNumberList(new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10)); | |
RichText text1 = new RichText(doc); | |
text1.setText("First"); | |
text1.setParagraphStyle(defaultStyle); | |
outlineElem1.appendChildLast(text1); | |
OutlineElement outlineElem2 = new OutlineElement(doc); | |
outlineElem2.setNumberList(new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10)); | |
RichText text2 = new RichText(doc); | |
text2.setText("Second"); | |
text2.setParagraphStyle(defaultStyle); | |
outlineElem2.appendChildLast(text2); | |
OutlineElement outlineElem3 = new OutlineElement(doc); | |
outlineElem3.setNumberList(new NumberList("{0})", NumberFormat.DecimalNumbers, "Arial", 10)); | |
RichText text3 = new RichText(doc); | |
text3.setText("Third"); | |
text3.setParagraphStyle(defaultStyle); | |
outlineElem3.appendChildLast(text3); | |
// add outline elements | |
outline.appendChildLast(outlineElem1); | |
outline.appendChildLast(outlineElem2); | |
outline.appendChildLast(outlineElem3); | |
// add Outline node | |
page.appendChildLast(outline); | |
// add Page node | |
doc.appendChildLast(page); | |
// save the document | |
doc.save(dataDir + "CreateNumberedList_out.pdf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExtractingAllText.class) + "text\\"; | |
// Load the document into Aspose.Note. | |
Document oneFile = new Document(dataDir + "Sample1.one"); | |
// Retrieve text | |
List<RichText> textNodes = (List<RichText>) oneFile.getChildNodes(RichText.class); | |
StringBuilder text = new StringBuilder(); | |
for (RichText richText : textNodes) { | |
text = text.append(richText.getText().toString()); | |
} | |
// Print text on the output screen | |
System.out.println(text); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ExtractingTextFromAPage.class) + "text\\"; | |
// Load the document into Aspose.Note. | |
Document oneFile = new Document(dataDir + "Sample1.one"); | |
// Get list of page nodes | |
List<Node> nodes = oneFile.getChildNodes(Node.class); | |
if (nodes.size() > 0 && nodes.get(0).getNodeType() == NodeType.Page) | |
{ | |
Page page = (Page)nodes.get(0); | |
// Retrieve text | |
List<RichText> textNodes = (List<RichText>) page.getChildNodes(RichText.class); | |
StringBuilder text = new StringBuilder(); | |
for (RichText richText : textNodes) { | |
text = text.append(richText.getText().toString()); | |
} | |
// Print text on the output screen | |
System.out.println(text); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ExtractText.class) + "text/"; | |
// Load the document into Aspose.Note | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// Get list of page nodes | |
List<Page> pages = doc.getChildNodes(Page.class); | |
for (Page p : pages) { | |
List<RichText> textNodes = (List<RichText>) p.getChildNodes(RichText.class); | |
StringBuilder text = new StringBuilder(); | |
for (RichText richText : textNodes) { | |
text = text.append(richText.getText().toString()); | |
} | |
System.out.println(text.toString()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(GetListProperties.class) + "text/"; | |
// Load the document into Aspose.Note | |
Document oneFile = new Document(dataDir + "Sample1.one"); | |
// Retrieve a collection nodes of the outline element | |
List<OutlineElement> nodes = oneFile.getChildNodes(OutlineElement.class); | |
// Iterate through each node | |
for (OutlineElement node : nodes) { | |
if (node.getNumberList() != null) { | |
NumberList list = node.getNumberList(); | |
// Retrieve font name | |
System.out.println("Font Name: " + list.getFont()); | |
// Retrieve font length | |
System.out.println("Font Length: " + list.getFont()); | |
// Retrieve font size | |
System.out.println("Font Size: " + list.getFontSize()); | |
// Retrieve font color | |
System.out.println("Font Color: " + list.getFontColor()); | |
// Retrieve format | |
System.out.println("Font format: " + list.getFormat()); | |
// Check bold | |
System.out.println("Is bold: " + list.isBold()); | |
// Check italic | |
System.out.println("Is italic: " + list.isItalic()); | |
System.out.println(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ReplaceTextonAllPages.class) + "text/"; | |
Map<String, String> replacements = new HashMap<String, String>(); | |
replacements.put("2. Get organized", "New Text Here"); | |
// Load the document into Aspose.Note. | |
LoadOptions options = new LoadOptions(); | |
Document oneFile = new Document(dataDir + "Sample1.one", options); | |
// Get all RichText nodes | |
List<RichText> textNodes = (List<RichText>) oneFile.getChildNodes(RichText.class);// <RichText.class>(); | |
// Traverse all nodes and compare text against the key text | |
for (RichText richText : textNodes) { | |
for (String key : replacements.keySet()) { | |
if (richText != null && richText.getText().contains(key)) { | |
// Replace text of a shape | |
richText.setText(richText.getText().replace(key, replacements.get(key))); | |
} | |
} | |
} | |
// Save to any supported file format | |
oneFile.save(dataDir + "ReplaceTextonAllPages_out.pdf", SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(ReplaceTextonParticularPage.class) + "text/"; | |
Map<String, String> replacements = new HashMap<String, String>(); | |
replacements.put("2. Get organized", "New Text Here"); | |
// Load the document into Aspose.Note. | |
Document oneFile = new Document(dataDir + "Sample1.one", new LoadOptions()); | |
List<Page> pageNodes = (List<Page>) oneFile.getChildNodes(Page.class); | |
// Get all RichText nodes | |
List<RichText> textNodes = (List<RichText>) pageNodes.get(0).getChildNodes(RichText.class); | |
for (RichText richText : textNodes) { | |
for (String key : replacements.keySet()) { | |
if (richText != null && richText.getText().contains(key)) { | |
// Replace text of a shape | |
richText.setText(richText.getText().replace(key, replacements.get(key))); | |
} | |
} | |
} | |
// Save to any supported file format | |
oneFile.save(dataDir + "ReplaceTextonParticularPage_out.pdf", SaveFormat.Pdf); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String dataDir = Utils.getSharedDataDir(SettingPageTitleinMicrosoftOneNoteStyle.class) + "text/"; | |
// initialize new Document | |
Document doc = new Document(dataDir + "Sample1.one"); | |
// initialize new Page | |
Page page = new Page(doc); | |
// title text | |
RichText titleText = new RichText(doc); | |
titleText.setText("Title text."); | |
titleText.setParagraphStyle(ParagraphStyle.getDefault()); | |
// title date | |
RichText titleDate = new RichText(doc); | |
titleDate.setText("2011,11,11"); | |
titleDate.setParagraphStyle(ParagraphStyle.getDefault()); | |
// title time | |
RichText titleTime = new RichText(doc); | |
titleTime.setText("12:34"); | |
titleTime.setParagraphStyle(ParagraphStyle.getDefault()); | |
Title title = new Title(doc); | |
title.setTitleText(titleText); | |
title.setTitleDate(titleDate); | |
title.setTitleTime(titleTime); | |
page.setTitle(title); | |
// append page node | |
doc.appendChildLast(page); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The MIT License (MIT) | |
Copyright (c) 2001-2016 Aspose Pty Ltd | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment