Einführung

Erstellen Sie ein Hello World OneNote -Dokument mit der API

In diesem Artikel wird erläutert, wie ein OneNote -Dokument von Grund auf neu erstellt wird, indem die einfachen APIs von Aspose.Notefür Java bereitgestellt werden. Um ein OneNote -Dokument zu erstellen, fügen Sie die Seite, den Umriss, den Umrisselement und den Text dynamisch mit dem in der ASSOSPLE. ASSEL Namespace verpackten Klassen hinzu.

Bitte befolgen Sie diese Schritte, um ein OneNote -Dokument mithilfe der ASPOSPEN. APIS zu erstellen:

  1. Erstellen Sie eine Instanz der Dokument Klasse, die ein OneNote -Dokument darstellt.
  2. Wenn Sie eine Lizenz gekauft haben, betten Sie den Code ein, um diese Lizenz mit Hilfe der Lizenz Klasse zu beantragen.
  3. Initialisieren Sie ein Objekt von Seite, Umriss, Umrisselement und Richtext Klassen, die das Objekt Dokument Klasse umgehen. Aufrufen der AppendChildLast -Methode der Umrissung, Umriss, Seite und Dokument Klassen fügt einen geeigneten neuen Knoten hinzu, mit dem das OneNote -Dokument neue Knoten hinzugefügt werden kann.
  4. Die Klasse Textstyle definiert die Textformatierung. In ähnlicher Weise ermöglicht die von RichText -Klasse ausgesetzte Eigenschaftseigenschaft die Anwendung für das Format im Text.
  5. Generieren Sie das OneNote -Dokument, indem Sie die Speichermethode des Dokuments -Objekts aufrufen.

Diese Artikel zeigen, wie man:

Erstellen Sie ein OneNote -Dokument mit einfachem Richtext

 1String dataDir = Utils.getSharedDataDir(CreateOneNoteDocumentWithSimpleRichText.class) + "introduction/";
 2
 3// For complete examples and data files, please go to
 4// https://github.com/aspose-note/Aspose.Note-for-Java
 5// create an object of the Document class
 6Document doc = new Document();
 7// initialize Page class object
 8Page page = new Page(doc);
 9// initialize Outline class object
10Outline outline = new Outline(doc);
11// initialize OutlineElement class object
12OutlineElement outlineElem = new OutlineElement(doc);
13
14// initialize ParagraphStyle class object and set formatting properties
15ParagraphStyle textStyle = new ParagraphStyle();
16textStyle.setFontColor(Color.black);
17textStyle.setFontName("Arial");
18textStyle.setFontSize(10);
19
20// initialize RichText class object and apply text style
21RichText text = new RichText(doc);
22text.setText("Hello OneNote text!");
23text.setParagraphStyle(textStyle);
24
25// add RichText node
26outlineElem.appendChildLast(text);
27// add OutlineElement node
28outline.appendChildLast(outlineElem);
29// add Outline node
30page.appendChildLast(outline);
31// add Page node
32doc.appendChildLast(page);
33// save OneNote document
34doc.save(dataDir + "CreateOneNoteDocumentWithSimpleRichText_out.pdf", SaveFormat.Pdf);

Erstellen Sie ein OneNote -Dokument mit formatiertem Richtext

 1String dataDir = Utils.getSharedDataDir(CreateOneNoteDocumentWithFormattedRichText.class) + "introduction/";
 2
 3// For complete examples and data files, please go to
 4// https://github.com/aspose-note/Aspose.Note-for-Java
 5// create an object of the Document class
 6Document doc = new Document();
 7// initialize Page class object
 8Page page = new Page(doc);
 9// initialize Title class object
10Title title = new Title(doc);
11// initialize TextStyle class object and set formatting properties
12ParagraphStyle defaultTextStyle = new ParagraphStyle();
13defaultTextStyle.setFontColor(Color.black);
14defaultTextStyle.setFontName("Arial");
15defaultTextStyle.setFontSize(10);
16
17RichText titleText = new RichText(doc);
18titleText.setText("Title!");
19titleText.setParagraphStyle(defaultTextStyle);
20
21// titleText.setTitleText(true);
22// IsTitleText = true
23
24Outline outline = new Outline(doc);
25outline.setVerticalOffset(100);
26outline.setHorizontalOffset(100);
27
28OutlineElement outlineElem = new OutlineElement(doc);
29// RunIndex = 5 means the style will be applied only to 0-4 characters.
30// ("Hello")
31TextStyle textStyleForHelloWord = new TextStyle();
32textStyleForHelloWord.setFontColor(Color.red);
33textStyleForHelloWord.setFontName("Arial");
34textStyleForHelloWord.setFontSize(10);
35textStyleForHelloWord.setRunIndex(5);
36
37// RunIndex = 13 means the style will be applied only to 5-12
38// characters. (" OneNote")
39TextStyle textStyleForOneNoteWord = new TextStyle();
40textStyleForOneNoteWord.setFontColor(Color.green);
41textStyleForOneNoteWord.setFontName("Calibri");
42textStyleForOneNoteWord.setFontSize(10);
43textStyleForOneNoteWord.setItalic(true);
44textStyleForOneNoteWord.setRunIndex(13);
45
46// RunIndex = 18 means the style will be applied only to 13-17
47// characters. (" text").
48// Other characters ("!") will have the default style.
49TextStyle textStyleForTextWord = new TextStyle();
50textStyleForTextWord.setFontColor(Color.blue);
51textStyleForTextWord.setFontName("Arial");
52textStyleForTextWord.setFontSize(15);
53textStyleForTextWord.setBold(true);
54textStyleForTextWord.setItalic(true);
55textStyleForTextWord.setRunIndex(18);
56
57RichText text = new RichText(doc);
58text.setText("Hello OneNote text!");
59text.setParagraphStyle(defaultTextStyle);
60text.getStyles().addItem(textStyleForHelloWord);
61text.getStyles().addItem(textStyleForOneNoteWord);
62text.getStyles().addItem(textStyleForTextWord);
63
64title.setTitleText(titleText);
65// set page title
66page.setTitle(title);
67// add RichText node
68outlineElem.appendChildLast(text);
69// add OutlineElement node
70outline.appendChildLast(outlineElem);
71// add Outline node
72page.appendChildLast(outline);
73// add Page node
74doc.appendChildLast(page);
75// save OneNote document
76doc.save(dataDir + "CreateOneNoteDocument_out.pdf", SaveFormat.Pdf);
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.