Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created January 7, 2020 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/9d87de8e13e5ad79213ef7e37038e252 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/9d87de8e13e5ad79213ef7e37038e252 to your computer and use it in GitHub Desktop.
Aspose.Words for .NET - Blog
Document doc = new Document("word.docx");
// Provide PDFSaveOption compliance to PDF17
PdfSaveOptions options = new PdfSaveOptions();
options.Compliance = PdfCompliance.Pdf17;
// Convert Word to PDF
doc.Save("output.pdf", options);
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Specify font formatting
Font font = builder.Font;
font.Size = 32;
font.Bold = true;
font.Color = System.Drawing.Color.Black;
font.Name = "Arial";
font.Underline = Underline.Single;
// Insert text
builder.Writeln("This is the first page.");
builder.Writeln();
// Change formatting for next elements.
font.Underline = Underline.None;
font.Size = 10;
font.Color = System.Drawing.Color.Blue;
builder.Writeln("This following is a table");
// Insert a table
Table table = builder.StartTable();
// Insert a cell
builder.InsertCell();
// Use fixed column widths.
table.AutoFit(AutoFitBehavior.AutoFitToContents);
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.Write("This is row 1 cell 1");
// Insert a cell
builder.InsertCell();
builder.Write("This is row 1 cell 2");
builder.EndRow();
builder.InsertCell();
builder.Write("This is row 2 cell 1");
builder.InsertCell();
builder.Write("This is row 2 cell 2");
builder.EndRow();
builder.EndTable();
builder.Writeln();
// Insert image
builder.InsertImage("image.png");
// Insert page break
builder.InsertBreak(BreakType.PageBreak);
// all the elements after page break will be inserted to next page.
// Save the document
doc.Save("Document.docx");
// Load document
Document doc = new Document("Document.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Access the paragraph
var paragraph=doc.Sections[0].Body.Paragraphs[0].Runs[0];
paragraph.Text = "This is updated text";
// Save the document
doc.Save("Document_updated.docx");
// Load the document from disk.
Document doc = new Document("document.docx");
// Save as plain text
doc.Save("output.txt");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment