Skip to content

Instantly share code, notes, and snippets.

// Open a document
auto doc = MakeObject<Document>(u"OpenType.Document.docx");
// When the text shaper factory is set, the layout starts to use OpenType features.
// An Instance property returns static BasicTextShaperCache object wrapping HarfBuzzTextShaperFactory
doc->get_LayoutOptions()->set_TextShaperFactory(Shaping::HarfBuzz::HarfBuzzTextShaperFactory::get_Instance());
// Render the document to PDF format
doc->Save(u"OpenType.Document.pdf");
@aspose-words-gists
aspose-words-gists / recovery-mode.java
Last active September 15, 2025 18:00
Examples for a release notes 25.9 Java version
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
LoadOptions loadOptions = new LoadOptions();
loadOptions.setRecoveryMode(DocumentRecoveryMode.TRY_RECOVER);
Document doc = new Document(getMyDir() + "Corrupted footnotes.docx", loadOptions);
@aspose-words-gists
aspose-words-gists / extract-pages-with-options.java
Last active September 15, 2025 18:00
Examples for a release notes 25.8 Java version
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Page fields.docx");
// Default behavior:
// The extracted page numbering is the same as in the original document, as if we had selected "Print 2 pages" in MS Word.
// The start page will be set to 2 and the field indicating the number of pages will be removed
// and replaced with a constant value equal to the number of pages.
Document extractedDoc1 = doc.extractPages(1, 1);
extractedDoc1.save(getArtifactsDir() + "Document.ExtractPagesWithOptions.Default.docx");
@aspose-words-gists
aspose-words-gists / export-office-math-as-latex.cs
Last active September 3, 2025 12:39
Examples for a release notes 25.9 .NET version
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET.git.
Document doc = new Document(MyDir + "Office math.docx");
MarkdownSaveOptions saveOptions = new MarkdownSaveOptions();
saveOptions.OfficeMathExportMode = MarkdownOfficeMathExportMode.Latex;
doc.Save(ArtifactsDir + "MarkdownSaveOptions.ExportOfficeMathAsLatex.md", saveOptions);
@aspose-words-gists
aspose-words-gists / grid-layout.java
Created August 22, 2025 08:04
Aspose.Words for Java. Convert a multi-page document using Java.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Rendering.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
// Set up a grid layout with:
// - 3 columns per row.
// - 10pts spacing between pages (horizontal and vertical).
options.setPageLayout(MultiPageLayout.grid(3, 10, 10));
// Customize the background and border.
@aspose-words-gists
aspose-words-gists / grid-layout.cs
Created August 22, 2025 07:56
Aspose.Words for .NET. Convert a multi-page document using C#.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET.git.
Document doc = new Document(MyDir + "Rendering.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);
// Set up a grid layout with:
// - 3 columns per row.
// - 10pts spacing between pages (horizontal and vertical).
options.PageLayout = MultiPageLayout.Grid(3, 10, 10);
// Customize the background and border.
@aspose-words-gists
aspose-words-gists / access-bookmarks.java
Created August 22, 2025 07:30
Aspose.Words for Java. Working with bookmarks using Java.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Bookmarks.docx");
// By index:
Bookmark bookmark1 = doc.getRange().getBookmarks().get(0);
// By name:
Bookmark bookmark2 = doc.getRange().getBookmarks().get("MyBookmark3");
@aspose-words-gists
aspose-words-gists / access-styles.java
Last active August 22, 2025 07:09
Aspose.Words for Java. Styles and themes using Java.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document();
String styleName = "";
// Get styles collection from the document.
StyleCollection styles = doc.getStyles();
for (Style style : styles) {
if ("".equals(styleName)) {
styleName = style.getName();
@aspose-words-gists
aspose-words-gists / bind-sdt-to-custom-xml-part.java
Created August 22, 2025 07:02
Aspose.Words for Java. Working with Sdt using Java.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document();
CustomXmlPart xmlPart =
doc.getCustomXmlParts().add(UUID.randomUUID().toString(), "<root><text>Hello, World!</text></root>");
StructuredDocumentTag sdt = new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.BLOCK);
doc.getFirstSection().getBody().appendChild(sdt);
sdt.getXmlMapping().setMapping(xmlPart, "/root[1]/text[1]", "");
@aspose-words-gists
aspose-words-gists / ranges-delete-text.java
Created August 22, 2025 07:02
Aspose.Words for Java. Working with ranges using Java.
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git.
Document doc = new Document(getMyDir() + "Document.docx");
doc.getSections().get(0).getRange().delete();