Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.