Created
May 21, 2020 15:45
-
-
Save aspose-com-gists/c34d6130720473e294257b67aee03a1f to your computer and use it in GitHub Desktop.
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 PDF document | |
Document document = new Document(); | |
// Add page | |
Aspose.Pdf.Page page = document.Pages.Add(); | |
// Create annotation | |
TextAnnotation textAnnotation = new TextAnnotation(page, new Aspose.Pdf.Rectangle(200, 400, 400, 600)); | |
textAnnotation.Title = "Sample Annotation Title"; | |
textAnnotation.Subject = "Sample Subject"; | |
textAnnotation.State = AnnotationState.Accepted; | |
textAnnotation.Contents = "Sample contents for the annotation"; | |
textAnnotation.Open = true; | |
textAnnotation.Icon = TextIcon.Key; | |
Border border = new Border(textAnnotation); | |
border.Width = 5; | |
border.Dash = new Dash(1, 1); | |
textAnnotation.Border = border; | |
textAnnotation.Rect = new Aspose.Pdf.Rectangle(200, 400, 400, 600); | |
// Add annotation in the annotations collection of the page | |
page.Annotations.Add(textAnnotation); | |
// Save the PDF document | |
document.Save("Generated-PDF.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 PDF document | |
Document document = new Document(); | |
// Add page | |
Aspose.Pdf.Page page = document.Pages.Add(); | |
// Create text fragment | |
TextFragment textFragment = new TextFragment("Text 1: We have now applied text formatting. This is PDF generated by Aspose.PDF for .NET"); | |
textFragment.Position = new Position(100, 700); | |
TextFragment textFragment1 = new TextFragment("Text 2: We have now applied text formatting. This is PDF generated by Aspose.PDF for .NET"); | |
textFragment1.Position = new Position(100, 600); | |
// Set text properties | |
textFragment.TextState.FontSize = 12; | |
textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman"); | |
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray); | |
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red); | |
textFragment1.TextState.DrawTextRectangleBorder = true; | |
textFragment1.TextState.Underline = true; | |
textFragment1.TextState.StrikeOut = true; | |
// Create new color with pattern colorspace | |
textFragment1.TextState.ForegroundColor = new Aspose.Pdf.Color() | |
{ | |
PatternColorSpace = new Aspose.Pdf.Drawing.GradientAxialShading(Color.Red, Color.Blue) | |
}; | |
// Create TextBuilder object | |
TextBuilder textBuilder = new TextBuilder(page); | |
// Append the text fragments to the PDF page | |
textBuilder.AppendText(textFragment); | |
textBuilder.AppendText(textFragment1); | |
// Save the PDF document | |
document.Save("Generated-PDF.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 PDF document | |
Document document = new Document(); | |
// Add page | |
Aspose.Pdf.Page page = document.Pages.Add(); | |
// Create Link annotation object | |
LinkAnnotation link = new LinkAnnotation(page, new Aspose.Pdf.Rectangle(100, 800, 250, 750)); | |
// Create border object for LinkAnnotation | |
Border border = new Border(link); | |
// Set the border width value as 0 | |
border.Width = 1; | |
// Set the border for LinkAnnotation | |
link.Border = border; | |
// Specify the link type as remote URI | |
link.Action = new GoToURIAction("www.aspose.com"); | |
// Add link annotation to annotations collection of first page of PDF file | |
page.Annotations.Add(link); | |
// Create Free Text annotation for the link's text | |
FreeTextAnnotation textAnnotation = new FreeTextAnnotation(document.Pages[1], new Aspose.Pdf.Rectangle(100, 800, 250, 750), new DefaultAppearance(Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman"), 10, System.Drawing.Color.Blue)); | |
// String to be added as Free text | |
textAnnotation.Contents = "Link to Aspose website"; | |
// Set the border for Free Text Annotation | |
textAnnotation.Border = border; | |
// Add FreeText annotation to annotations collection of first page of Document | |
page.Annotations.Add(textAnnotation); | |
// Save the PDF document | |
document.Save("Generated-PDF.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 PDF document | |
Document document = new Document(); | |
// Add page | |
Aspose.Pdf.Page page = document.Pages.Add(); | |
// Create a parent bookmark object | |
OutlineItemCollection pdfOutline = new OutlineItemCollection(document.Outlines); | |
pdfOutline.Title = "Parent Outline"; | |
pdfOutline.Italic = true; | |
pdfOutline.Bold = true; | |
// Create a child bookmark object | |
OutlineItemCollection pdfChildOutline = new OutlineItemCollection(document.Outlines); | |
pdfChildOutline.Title = "Child Outline"; | |
pdfChildOutline.Italic = true; | |
pdfChildOutline.Bold = true; | |
// Add child bookmark in parent bookmark's collection | |
pdfOutline.Add(pdfChildOutline); | |
// Add parent bookmark in the document's outline collection. | |
document.Outlines.Add(pdfOutline); | |
// Save the PDF document | |
document.Save("Generated-PDF.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 PDF document | |
Document document = new Document(); | |
// Specify the left margin info for the PDF file | |
document.PageInfo.Margin.Left = 40; | |
// Specify the Right margin info for the PDF file | |
document.PageInfo.Margin.Right = 40; | |
Aspose.Pdf.Page page = document.Pages.Add(); | |
// Add a line | |
Aspose.Pdf.Drawing.Graph graph1 = new Aspose.Pdf.Drawing.Graph(500, 2); | |
// Add the line to paraphraphs collection of section object | |
page.Paragraphs.Add(graph1); | |
// Specify the coordinates for the line | |
float[] posArr = new float[] { 1, 2, 500, 2 }; | |
Aspose.Pdf.Drawing.Line l1 = new Aspose.Pdf.Drawing.Line(posArr); | |
graph1.Shapes.Add(l1); | |
// Add a heading | |
// Create string variables with text containing html tags | |
string s = "<font face=\"Times New Roman\" size=4>" + | |
"<strong> How to Steer Clear of money scams</<strong> " | |
+ "</font>"; | |
// Create text paragraphs containing HTML text | |
HtmlFragment heading_text = new HtmlFragment(s); | |
page.Paragraphs.Add(heading_text); | |
Aspose.Pdf.FloatingBox box = new Aspose.Pdf.FloatingBox(); | |
// Add four columns in the section | |
box.ColumnInfo.ColumnCount = 2; | |
// Set the spacing between the columns | |
box.ColumnInfo.ColumnSpacing = "5"; | |
// Set the column widths | |
box.ColumnInfo.ColumnWidths = "250 250"; | |
// Create text | |
TextFragment text2 = new TextFragment(@"Sed augue tortor, sodales id, luctus et, pulvinar ut, eros. Suspendisse vel dolor. Sed quam. Curabitur ut massa vitae eros euismod aliquam. Pellentesque sit amet elit. Vestibulum interdum pellentesque augue. Cras mollis arcu sit amet purus. Donec augue. Nam mollis tortor a elit. Nulla viverra nisl vel mauris. Vivamus sapien. nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et,nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales.nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales. Sed augue tortor, sodales id, luctus et, pulvinar ut, eros. Suspendisse vel dolor. Sed quam. Curabitur ut massa vitae eros euismod aliquam. Pellentesque sit amet elit. Vestibulum interdum pellentesque augue. Cras mollis arcu sit amet purus. Donec augue. Nam mollis tortor a elit. Nulla viverra nisl vel mauris. Vivamus sapien. nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et,nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales.nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales. Sed augue tortor, sodales id, luctus et, pulvinar ut, eros. Suspendisse vel dolor. Sed quam. Curabitur ut massa vitae eros euismod aliquam. Pellentesque sit amet elit. Vestibulum interdum pellentesque augue. Cras mollis arcu sit amet purus. Donec augue. Nam mollis tortor a elit. Nulla viverra nisl vel mauris. Vivamus sapien. nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et,nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales.nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales. Sed augue tortor, sodales id, luctus et, pulvinar ut, eros. Suspendisse vel dolor. Sed quam. Curabitur ut massa vitae eros euismod aliquam. Pellentesque sit amet elit. Vestibulum interdum pellentesque augue. Cras mollis arcu sit amet purus. Donec augue. Nam mollis tortor a elit. Nulla viverra nisl vel mauris. Vivamus sapien. nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et,nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim Nam justo lorem, aliquam luctus, sodales et, semper sed, enim nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales.nAenean posuere ante ut neque. Morbi sollicitudin congue felis. Praesent turpis diam, iaculis sed, pharetra non, mollis ac, mauris. Phasellus nisi ipsum, pretium vitae, tempor sed, molestie eu, dui. Duis lacus purus, tristique ut, iaculis cursus, tincidunt vitae, risus. Sed commodo. *** sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Sed urna. . Duis convallis ultrices nisi. Maecenas non ligula. Nunc nibh est, tincidunt in, placerat sit amet, vestibulum a, nulla. Praesent porttitor turpis eleifend ante. Morbi sodales."); | |
// Add text to the document | |
box.Paragraphs.Add(text2); | |
page.Paragraphs.Add(box); | |
// Save the PDF document | |
document.Save("Generated-PDF.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 PDF document | |
Document document = new Document(); | |
// Add page | |
Aspose.Pdf.Page page = document.Pages.Add(); | |
// Add text to new page | |
page.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello World! This is a new PDF generated by Aspose.PDF for .NET.")); | |
// Save the PDF document | |
document.Save("Generated-PDF.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 PDF document | |
Document document = new Document(); | |
// Add page | |
Aspose.Pdf.Page page = document.Pages.Add(); | |
// Initializes a new instance of the Table | |
Aspose.Pdf.Table table = new Aspose.Pdf.Table(); | |
// Set the table border color as LightGray | |
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); | |
// Set the border for table cells | |
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)); | |
// Create a loop to add 10 rows | |
for (int row_count = 1; row_count < 10; row_count++) | |
{ | |
// Add row to table | |
Aspose.Pdf.Row row = table.Rows.Add(); | |
// Add table cells | |
row.Cells.Add("Column (" + row_count + ", 1)"); | |
row.Cells.Add("Column (" + row_count + ", 2)"); | |
row.Cells.Add("Column (" + row_count + ", 3)"); | |
} | |
// Add table to the page | |
page.Paragraphs.Add(table); | |
// Save the PDF document | |
document.Save("Generated-PDF.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 PDF document | |
Document document = new Document(); | |
// Add page | |
Aspose.Pdf.Page page = document.Pages.Add(); | |
// Set coordinates | |
int lowerLeftX = 100; | |
int lowerLeftY = 100; | |
int upperRightX = 250; | |
int upperRightY = 250; | |
// Load image into stream | |
FileStream imageStream = new FileStream("aspose_pdf.png", FileMode.Open); | |
// Add image to Images collection of Page Resources | |
page.Resources.Images.Add(imageStream); | |
// Using GSave operator: this operator saves current graphics state | |
page.Contents.Add(new Aspose.Pdf.Operators.GSave()); | |
// Create Rectangle and Matrix objects | |
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY); | |
//Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY }); | |
Matrix matrix = new Matrix(new double[] { 200, 0, 0, 200, 200, 600 }); | |
// Using ConcatenateMatrix (concatenate matrix) operator: defines how image must be placed | |
page.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(matrix)); | |
XImage ximage = page.Resources.Images[page.Resources.Images.Count]; | |
// Using Do operator: this operator draws image | |
page.Contents.Add(new Aspose.Pdf.Operators.Do(ximage.Name)); | |
// Using GRestore operator: this operator restores graphics state | |
page.Contents.Add(new Aspose.Pdf.Operators.GRestore()); | |
// Save the PDF document | |
document.Save("Generated-PDF.pdf"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment