Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save aspose-pdf/7e1330795d76012fcb04248bb81d45b3 to your computer and use it in GitHub Desktop.
Save aspose-pdf/7e1330795d76012fcb04248bb81d45b3 to your computer and use it in GitHub Desktop.
This Gist contains examples of Aspose.Pdf for .Net
This gist exceeds the recommended number of files (~10). To access all files, please clone this gist.
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document pdfDocument = new Document(dataDir + "AddAnnotation.pdf");
// Create annotation
TextAnnotation textAnnotation = new TextAnnotation(pdfDocument.Pages[1], 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
pdfDocument.Pages[1].Annotations.Add(textAnnotation);
dataDir = dataDir + "AddAnnotation_out.pdf";
// Save output file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
Document doc = new Document();
Page pdfPage = doc.Pages.Add();
System.Drawing.Rectangle drect = new System.Drawing.Rectangle();
drect.Height = (int)pdfPage.Rect.Height;
drect.Width = (int)pdfPage.Rect.Width;
drect.X = 0;
drect.Y = 0;
Aspose.Pdf.Rectangle arect = Aspose.Pdf.Rectangle.FromRect(drect);
IList<Point[]> inkList = new List<Point[]>();
Aspose.Pdf.Point[] arrpt = new Aspose.Pdf.Point[3];
inkList.Add(arrpt);
arrpt[0] = new Aspose.Pdf.Point(100, 800);
arrpt[1] = new Aspose.Pdf.Point(200, 800);
arrpt[2] = new Aspose.Pdf.Point(200, 700);
InkAnnotation ia = new InkAnnotation(pdfPage, arect, inkList);
ia.Title = "XXX";
ia.Color = Aspose.Pdf.Color.LightBlue; // (GetColorFromString(stroke.InkColor));
ia.CapStyle = CapStyle.Rounded;
Border border = new Border(ia);
border.Width = 25;
ia.Opacity = 0.5;
pdfPage.Annotations.Add(ia);
dataDir = dataDir + "AddlnkAnnotation_out.pdf";
// Save output file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open the PDF document
Document doc = new Document(dataDir + "AddSwfFileAsAnnotation.pdf");
// Get reference of the page to which you need to add the annotation
Page page = doc.Pages[1];
// Create ScreenAnnotation object with .swf multimedia file as an argument
ScreenAnnotation annotation = new ScreenAnnotation(page, new Aspose.Pdf.Rectangle(0, 400, 600, 700), dataDir + "input.swf");
// Add the annotation to annotations collection of page
page.Annotations.Add(annotation);
dataDir = dataDir + "AddSwfFileAsAnnotation_out.pdf";
// Save the update PDF document with annotation
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document pdfDocument = new Document(dataDir + "DeleteAllAnnotationsFromPage.pdf");
// Delete particular annotation
pdfDocument.Pages[1].Annotations.Delete();
dataDir = dataDir + "DeleteAllAnnotationsFromPage_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document pdfDocument = new Document(dataDir + "DeleteParticularAnnotation.pdf");
// Delete particular annotation
pdfDocument.Pages[1].Annotations.Delete(1);
dataDir = dataDir + "DeleteParticularAnnotation_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
Document doc = new Document(dataDir + "ExtractHighlightedText.pdf");
// Loop through all the annotations
foreach (Annotation annotation in doc.Pages[1].Annotations)
{
// Filter TextMarkupAnnotation
if (annotation is TextMarkupAnnotation)
{
TextMarkupAnnotation highlightedAnnotation = annotation as TextMarkupAnnotation;
// Retrieve highlighted text fragments
TextFragmentCollection collection = highlightedAnnotation.GetMarkedTextFragments();
foreach (TextFragment tf in collection)
{
// Display highlighted text
Console.WriteLine(tf.Text);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document pdfDocument = new Document(dataDir + "GetAllAnnotationsFromPage.pdf");
// Loop through all the annotations
foreach (MarkupAnnotation annotation in pdfDocument.Pages[1].Annotations)
{
// Get annotation properties
Console.WriteLine("Title : {0} ", annotation.Title);
Console.WriteLine("Subject : {0} ", annotation.Subject);
Console.WriteLine("Contents : {0} ", annotation.Contents);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document pdfDocument = new Document(dataDir + "GetParticularAnnotation.pdf");
// Get particular annotation
TextAnnotation textAnnotation = (TextAnnotation)pdfDocument.Pages[1].Annotations[1];
// Get annotation properties
Console.WriteLine("Title : {0} ", textAnnotation.Title);
Console.WriteLine("Subject : {0} ", textAnnotation.Subject);
Console.WriteLine("Contents : {0} ", textAnnotation.Contents);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document doc = new Document(dataDir + "input.pdf");
FreeTextAnnotation annotation = new FreeTextAnnotation(doc.Pages[1], new Aspose.Pdf.Rectangle(50, 600, 250, 650), new DefaultAppearance("Helvetica", 16, System.Drawing.Color.Red));
annotation.Contents = "ABCDEFG";
annotation.Characteristics.Border = System.Drawing.Color.Red;
annotation.Flags = AnnotationFlags.Print | AnnotationFlags.NoView;
doc.Pages[1].Annotations.Add(annotation);
dataDir = dataDir + "InvisibleAnnotation_out.pdf";
// Save output file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
Document doc = new Document();
doc.Pages.Add();
IList<Point[]> inkList = new List<Point[]>();
LineInfo lineInfo = new LineInfo();
lineInfo.VerticeCoordinate = new float[] { 55, 55, 70, 70, 70, 90, 150, 60 };
lineInfo.Visibility = true;
lineInfo.LineColor = System.Drawing.Color.Red;
lineInfo.LineWidth = 2;
int length = lineInfo.VerticeCoordinate.Length / 2;
Aspose.Pdf.Point[] gesture = new Aspose.Pdf.Point[length];
for (int i = 0; i < length; i++)
{
gesture[i] = new Aspose.Pdf.Point(lineInfo.VerticeCoordinate[2 * i], lineInfo.VerticeCoordinate[2 * i + 1]);
}
inkList.Add(gesture);
InkAnnotation a1 = new InkAnnotation(doc.Pages[1], new Aspose.Pdf.Rectangle(100, 100, 300, 300), inkList);
a1.Subject = "Test";
a1.Title = "Title";
a1.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green);
Border border = new Border(a1);
border.Width = 3;
border.Effect = BorderEffect.Cloudy;
border.Dash = new Dash(1, 1);
border.Style = BorderStyle.Solid;
doc.Pages[1].Annotations.Add(a1);
dataDir = dataDir + "lnkAnnotationLineWidth_out.pdf";
// Save output file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
Aspose.Pdf.Facades.PdfAnnotationEditor editor = new Aspose.Pdf.Facades.PdfAnnotationEditor();
// Redact certain page region
editor.RedactArea(1, new Aspose.Pdf.Rectangle(100, 100, 20, 70), System.Drawing.Color.White);
editor.BindPdf(dataDir + "input.pdf");
editor.Save( dataDir + "FacadesApproach_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document doc = new Document(dataDir + "input.pdf");
// Create RedactionAnnotation instance for specific page region
RedactionAnnotation annot = new RedactionAnnotation(doc.Pages[1], new Aspose.Pdf.Rectangle(200, 500, 300, 600));
annot.FillColor = Aspose.Pdf.Color.Green;
annot.BorderColor = Aspose.Pdf.Color.Yellow;
annot.Color = Aspose.Pdf.Color.Blue;
// Text to be printed on redact annotation
annot.OverlayText = "REDACTED";
annot.TextAlignment = Aspose.Pdf.HorizontalAlignment.Center;
// Repat Overlay text over redact Annotation
annot.Repeat = true;
// Add annotation to annotations collection of first page
doc.Pages[1].Annotations.Add(annot);
// Flattens annotation and redacts page contents (i.e. removes text and image
// Under redacted annotation)
annot.Redact();
dataDir = dataDir + "RedactPage_out.pdf";
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document pdfDocument = new Document(dataDir + "SetFreeTextAnnotationFormatting.pdf");
// Instantiate DefaultAppearance object
DefaultAppearance default_appearance = new DefaultAppearance("Arial", 28, System.Drawing.Color.Red);
// Create annotation
FreeTextAnnotation freetext = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(200, 400, 400, 600), default_appearance);
// Specify the contents of annotation
freetext.Contents = "Free Text";
// Add anootation to annotations collection of page
pdfDocument.Pages[1].Annotations.Add(freetext);
dataDir = dataDir + "SetFreeTextAnnotationFormatting_out.pdf";
// Save the updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document document = new Document(dataDir + "input.pdf");
// Create TextFragment Absorber instance to search particular text fragment
Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber("Estoque");
// Iterate through pages of PDF document
for (int i = 1; i <= document.Pages.Count; i++)
{
// Get first page of PDF document
Page page = document.Pages[1];
page.Accept(textFragmentAbsorber);
}
// Create a collection of Absorbed text
Aspose.Pdf.Text.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
// Iterate on above collection
for (int j = 1; j <= textFragmentCollection.Count; j++)
{
Aspose.Pdf.Text.TextFragment textFragment = textFragmentCollection[j];
// Get rectangular dimensions of TextFragment object
Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(
(float)textFragment.Position.XIndent,
(float)textFragment.Position.YIndent,
(float)textFragment.Position.XIndent +
(float)textFragment.Rectangle.Width,
(float)textFragment.Position.YIndent +
(float)textFragment.Rectangle.Height);
// Instantiate StrikeOut Annotation instance
StrikeOutAnnotation strikeOut = new StrikeOutAnnotation(textFragment.Page, rect);
// Set opacity for annotation
strikeOut.Opacity = .80f;
// Set the border for annotation instance
strikeOut.Border = new Border(strikeOut);
// Set the color of annotation
strikeOut.Color = Aspose.Pdf.Color.Red;
// Add annotation to annotations collection of TextFragment
textFragment.Page.Annotations.Add(strikeOut);
}
dataDir = dataDir + "StrikeOutWords_out.pdf";
document.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Annotations();
// Open document
Document doc1 = new Document(dataDir + "input.pdf");
// Set font size and color of the annotation:
(doc1.Pages[1].Annotations[0] as FreeTextAnnotation).TextStyle.FontSize = 18;
(doc1.Pages[1].Annotations[0] as FreeTextAnnotation).TextStyle.Color = System.Drawing.Color.Green;
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();
// Open document
Document pdfDocument = new Document(dataDir + "AddAttachment.pdf");
// Setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification(dataDir + "test.txt", "Sample text file");
// Add attachment to document's attachment collection
pdfDocument.EmbeddedFiles.Add(fileSpecification);
dataDir = dataDir + "AddAttachment_out.pdf";
// Save new output
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();
// Open document
Document pdfDocument = new Document(dataDir + "DeleteAllAttachments.pdf");
// Delete all attachments
pdfDocument.EmbeddedFiles.Delete();
dataDir = dataDir + "DeleteAllAttachments_out.pdf";
// Save updated file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();
Document pdfDocument = new Document(dataDir + "GetAlltheAttachments.pdf");
// Setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification("test_out.txt", "Sample text file");
// Specify Encoding proparty setting it to FileEncoding.None
fileSpecification.Encoding = FileEncoding.None;
// Add attachment to document's attachment collection
pdfDocument.EmbeddedFiles.Add(fileSpecification);
dataDir = dataDir + "DisableFilesCompression_out.pdf";
// Save new output
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();
// Open document
Document pdfDocument = new Document(dataDir + "GetAlltheAttachments.pdf");
// Get embedded files collection
EmbeddedFileCollection embeddedFiles = pdfDocument.EmbeddedFiles;
// Get count of the embedded files
Console.WriteLine("Total files : {0}", embeddedFiles.Count);
int count = 1;
// Loop through the collection to get all the attachments
foreach (FileSpecification fileSpecification in embeddedFiles)
{
Console.WriteLine("Name: {0}", fileSpecification.Name);
Console.WriteLine("Description: {0}",
fileSpecification.Description);
Console.WriteLine("Mime Type: {0}", fileSpecification.MIMEType);
// Check if parameter object contains the parameters
if (fileSpecification.Params != null)
{
Console.WriteLine("CheckSum: {0}",
fileSpecification.Params.CheckSum);
Console.WriteLine("Creation Date: {0}",
fileSpecification.Params.CreationDate);
Console.WriteLine("Modification Date: {0}",
fileSpecification.Params.ModDate);
Console.WriteLine("Size: {0}", fileSpecification.Params.Size);
}
// Get the attachment and write to file or stream
byte[] fileContent = new byte[fileSpecification.Contents.Length];
fileSpecification.Contents.Read(fileContent, 0,
fileContent.Length);
FileStream fileStream = new FileStream(dataDir + count + "_out" + ".txt",
FileMode.Create);
fileStream.Write(fileContent, 0, fileContent.Length);
fileStream.Close();
count+=1;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();
// Open document
Document pdfDocument = new Document(dataDir + "GetAttachmentInfo.pdf");
// Get particular embedded file
FileSpecification fileSpecification = pdfDocument.EmbeddedFiles[1];
// Get the file properties
Console.WriteLine("Name: {0}", fileSpecification.Name);
Console.WriteLine("Description: {0}", fileSpecification.Description);
Console.WriteLine("Mime Type: {0}", fileSpecification.MIMEType);
// Check if parameter object contains the parameters
if (fileSpecification.Params != null)
{
Console.WriteLine("CheckSum: {0}",
fileSpecification.Params.CheckSum);
Console.WriteLine("Creation Date: {0}",
fileSpecification.Params.CreationDate);
Console.WriteLine("Modification Date: {0}",
fileSpecification.Params.ModDate);
Console.WriteLine("Size: {0}", fileSpecification.Params.Size);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Attachments();
// Open document
Document pdfDocument = new Document(dataDir + "GetIndividualAttachment.pdf");
// Get particular embedded file
FileSpecification fileSpecification = pdfDocument.EmbeddedFiles[1];
// Get the file properties
Console.WriteLine("Name: {0}", fileSpecification.Name);
Console.WriteLine("Description: {0}", fileSpecification.Description);
Console.WriteLine("Mime Type: {0}", fileSpecification.MIMEType);
// Check if parameter object contains the parameters
if (fileSpecification.Params != null)
{
Console.WriteLine("CheckSum: {0}",
fileSpecification.Params.CheckSum);
Console.WriteLine("Creation Date: {0}",
fileSpecification.Params.CreationDate);
Console.WriteLine("Modification Date: {0}",
fileSpecification.Params.ModDate);
Console.WriteLine("Size: {0}", fileSpecification.Params.Size);
}
// Get the attachment and write to file or stream
byte[] fileContent = new byte[fileSpecification.Contents.Length];
fileSpecification.Contents.Read(fileContent, 0, fileContent.Length);
FileStream fileStream = new FileStream(dataDir + "test_out" + ".txt", FileMode.Create);
fileStream.Write(fileContent, 0, fileContent.Length);
fileStream.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document pdfDocument = new Document(dataDir + "AddBookmark.pdf");
// Create a bookmark object
OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
pdfOutline.Title = "Test Outline";
pdfOutline.Italic = true;
pdfOutline.Bold = true;
// Set the destination page number
pdfOutline.Action = new GoToAction(pdfDocument.Pages[1]);
// Add bookmark in the document's outline collection.
pdfDocument.Outlines.Add(pdfOutline);
dataDir = dataDir + "AddBookmark_out.pdf";
// Save output
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document pdfDocument = new Document(dataDir + "AddChildBookmark.pdf");
// Create a parent bookmark object
OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
pdfOutline.Title = "Parent Outline";
pdfOutline.Italic = true;
pdfOutline.Bold = true;
// Create a child bookmark object
OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.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.
pdfDocument.Outlines.Add(pdfOutline);
dataDir = dataDir + "AddChildBookmark_out.pdf";
// Save output
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document pdfDocument = new Document(dataDir + "DeleteAllBookmarks.pdf");
// Delete all bookmarks
pdfDocument.Outlines.Delete();
dataDir = dataDir + "DeleteAllBookmarks_out.pdf";
// Save updated file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document pdfDocument = new Document(dataDir + "DeleteParticularBookmark.pdf");
// Delete particular outline by Title
pdfDocument.Outlines.Delete("Child Outline");
dataDir = dataDir + "DeleteParticularBookmark_out.pdf";
// Save updated file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document doc = new Document(dataDir + "input.pdf");
// Set page view mode i.e. show thumbnails, full-screen, show attachment panel
doc.PageMode = PageMode.UseOutlines;
// Traverse through each Ouline item in outlines collection of PDF file
foreach (OutlineItemCollection item in doc.Outlines)
{
// Set open status for outline item
item.Open = true;
}
dataDir = dataDir + "ExpandBookmarks_out.pdf";
// Save output
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Create PdfBookmarkEditor
PdfBookmarkEditor bookmarkEditor = new PdfBookmarkEditor();
// Open PDF file
bookmarkEditor.BindPdf(dataDir + "GetBookmarks.pdf");
// Extract bookmarks
Aspose.Pdf.Facades.Bookmarks bookmarks = bookmarkEditor.ExtractBookmarks();
foreach (Aspose.Pdf.Facades.Bookmark bookmark in bookmarks)
{
string strLevelSeprator = string.Empty;
for (int i = 1; i < bookmark.Level; i++)
{
strLevelSeprator += "----";
}
Console.WriteLine("{0}Title: {1}", strLevelSeprator, bookmark.Title);
Console.WriteLine("{0}Page Number: {1}", strLevelSeprator, bookmark.PageNumber);
Console.WriteLine("{0}Page Action: {1}", strLevelSeprator, bookmark.Action);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document pdfDocument = new Document(dataDir + "GetBookmarks.pdf");
// Loop through all the bookmarks
foreach (OutlineItemCollection outlineItem in pdfDocument.Outlines)
{
Console.WriteLine(outlineItem.Title);
Console.WriteLine(outlineItem.Italic);
Console.WriteLine(outlineItem.Bold);
Console.WriteLine(outlineItem.Color);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document pdfDocument = new Document(dataDir + "GetChildBookmarks.pdf");
// Loop through all the bookmarks
foreach (OutlineItemCollection outlineItem in pdfDocument.Outlines)
{
Console.WriteLine(outlineItem.Title);
Console.WriteLine(outlineItem.Italic);
Console.WriteLine(outlineItem.Bold);
Console.WriteLine(outlineItem.Color);
if (outlineItem.Count > 0)
{
Console.WriteLine("Child Bookmarks");
// There are child bookmarks then loop through that as well
foreach (OutlineItemCollection childOutline in outlineItem)
{
Console.WriteLine(childOutline.Title);
Console.WriteLine(childOutline.Italic);
Console.WriteLine(childOutline.Bold);
Console.WriteLine(childOutline.Color);
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document doc = new Document(dataDir + "input.pdf");
// Get outlines/bookmarks collection of PDF file
OutlineItemCollection item = new OutlineItemCollection(doc.Outlines);
// Set zoom level as 0
XYZExplicitDestination dest = new XYZExplicitDestination(2, 100, 100, 0);
// Add XYZExplicitDestination as action to outlines collection of PDF
item.Action = new GoToAction(dest);
// Add item to outlines collection of PDF file
doc.Outlines.Add(item);
dataDir = dataDir + "InheritZoom_out.pdf";
// Save output
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document pdfDocument = new Document(dataDir + "UpdateBookmarks.pdf");
// Get a bookmark object
OutlineItemCollection pdfOutline = pdfDocument.Outlines[1];
pdfOutline.Title = "Updated Outline";
pdfOutline.Italic = true;
pdfOutline.Bold = true;
dataDir = dataDir + "UpdateBookmarks_out.pdf";
// Save output
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Bookmarks();
// Open document
Document pdfDocument = new Document(dataDir + "UpdateChildBookmarks.pdf");
// Get a bookmark object
OutlineItemCollection pdfOutline = pdfDocument.Outlines[1];
// Get child bookmark object
OutlineItemCollection childOutline = pdfOutline[1];
childOutline.Title = "Updated Outline";
childOutline.Italic = true;
childOutline.Bold = true;
dataDir = dataDir + "UpdateChildBookmarks_out.pdf";
// Save output
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate Document instance to load existing file
Aspose.Pdf.Document doc = new Document(dataDir + "input.pdf");
// Setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification(dataDir + "aspose-logo.jpg", "Large Image file");
// Add attachment to document's attachment collection
doc.EmbeddedFiles.Add(fileSpecification);
// Perform conversion to PDF/A_3a so attachment is included in resultnat file
doc.Convert(dataDir + "log.txt", Aspose.Pdf.PdfFormat.PDF_A_3A, ConvertErrorAction.Delete);
// Save resultant file
doc.Save(dataDir + "AddAttachmentToPDFA_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate LoadOption object using CGMLoadOption
Aspose.Pdf.CgmLoadOptions cgmload = new Aspose.Pdf.CgmLoadOptions();
// Instantiate Document object
Document doc = new Document(dataDir + "CGMToPDF.CGM", cgmload);
// Save the resultant PDF document
doc.Save(dataDir+ "TECHDRAW_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate LoadOption object using EPUB load option
EpubLoadOptions epubload = new EpubLoadOptions();
// Create Document object
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document(dataDir + "EPUBToPDF.epub", epubload);
// Save the resultant PDF document
pdf.Save(dataDir + "EPUBToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
var loadopt = new SvgLoadOptions();
loadopt.AdjustPageSize = true;
var svgDoc = new Document(dataDir + "GetSVGDimensions.svg", loadopt);
svgDoc.Pages[1].PageInfo.Margin.Top = 0;
svgDoc.Pages[1].PageInfo.Margin.Left = 0;
svgDoc.Pages[1].PageInfo.Margin.Bottom = 0;
svgDoc.Pages[1].PageInfo.Margin.Right = 0;
svgDoc.Save(dataDir + "GetSVGDimensions_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
HtmlLoadOptions options = new HtmlLoadOptions();
options.CustomLoaderOfExternalResources = new LoadOptions.ResourceLoadingStrategy(SamePictureLoader);
Document pdfDocument = new Document(dataDir + "HTMLToPDF.html", options);
pdfDocument.Save("HTMLToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static LoadOptions.ResourceLoadingResult SamePictureLoader(string resourceURI)
{
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
byte[] resultBytes = File.ReadAllBytes(dataDir + "aspose-logo.jpg");
LoadOptions.ResourceLoadingResult result = new LoadOptions.ResourceLoadingResult(resultBytes);
return result;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
MhtLoadOptions options = new MhtLoadOptions();
// Load document
Document document = new Document(dataDir + "test.mht", options);
// Save the output as PDF document
document.Save(dataDir + "MHTToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
// Retrieve names of all the JPG files in a particular Directory
string[] fileEntries = Directory.GetFiles(dataDir, "*.JPG");
int counter;
for (counter = 0; counter < fileEntries.Length - 1; counter++)
{
// Create a page object
Aspose.Pdf.Page page = doc.Pages.Add();
// Creat an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
image1.File = fileEntries[counter];
// Create a BitMap object in order to get the information of image file
Bitmap myimage = new Bitmap(fileEntries[counter]);
// Check if the width of the image file is greater than Page width or not
if (myimage.Width > page.PageInfo.Width)
// If the Image width is greater than page width, then set the page orientation to Landscape
page.PageInfo.IsLandscape = true;
else
// If the Image width is less than page width, then set the page orientation to Portrait
page.PageInfo.IsLandscape = false;
// Add the image to paragraphs collection of the PDF document
page.Paragraphs.Add(image1);
}
// Save the Pdf file
doc.Save(dataDir + "SetPageOrientation_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
using (FileStream fileStream = new FileStream(dataDir + "sample.pcl", FileMode.Open))
using (MemoryStream memoryStream = new MemoryStream())
{
fileStream.CopyTo(memoryStream);
memoryStream.Seek(0, SeekOrigin.Begin);
using (Document document = new Document(memoryStream, new PclLoadOptions()))
{
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate LoadOption object using PCL load option
Aspose.Pdf.LoadOptions loadopt = new Aspose.Pdf.PclLoadOptions();
// Create Document object
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "hidetext.pcl", loadopt);
// Save the resultant PDF document
doc.Save(dataDir + "PCLToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open document
Document doc = new Document(dataDir + "PDFAToPDF.pdf");
// Remove PDF/A compliance information
doc.RemovePdfaCompliance();
// Save updated document
doc.Save(dataDir + "PDFAToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open the source PDF document
Document pdfDocument = new Document(dataDir + "PDFToDOC.pdf");
// Instantiate DocSaveOptions object
DocSaveOptions saveOptions = new DocSaveOptions();
// Specify the output format as DOCX
saveOptions.Format = DocSaveOptions.DocFormat.DocX;
// Save document in docx format
pdfDocument.Save("ConvertToDOCX_out.docx", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open the source PDF document
Document pdfDocument = new Document(dataDir + "PDFToDOC.pdf");
// Save the file into MS document format
pdfDocument.Save(dataDir + "PDFToDOC_out.doc", SaveFormat.Doc);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open the source PDF document
Document pdfDocument = new Document(dataDir + "PDFToDOC.pdf");
// Save using save options
// Create DocSaveOptions object
DocSaveOptions saveOptions = new DocSaveOptions();
// Set the recognition mode as Flow
saveOptions.Mode = DocSaveOptions.RecognitionMode.Flow;
// Set the Horizontal proximity as 2.5
saveOptions.RelativeHorizontalProximity = 2.5f;
// Enable the value to recognize bullets during conversion process
saveOptions.RecognizeBullets = true;
// Save the resultant DOC file
pdfDocument.Save(dataDir + "saveOptionsOutput_out.doc", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Load PDF document
Document pdfDocument = new Document(dataDir + "PDFToEPUB.pdf");
// Instantiate Epub Save options
EpubSaveOptions options = new EpubSaveOptions();
// Specify the layout for contents
options.ContentRecognitionMode = EpubSaveOptions.RecognitionMode.Flow;
// Save the ePUB document
pdfDocument.Save(dataDir + "PDFToEPUB_out.epub", options);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// Create HtmlSaveOption with tested feature
HtmlSaveOptions newOptions = new HtmlSaveOptions();
// Compress the SVG images if there are any
newOptions.CompressSvgGraphicsIfAny = true;
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
Document doc = new Document(dataDir + "PDFToHTML.pdf");
HtmlSaveOptions options = new HtmlSaveOptions();
// This is the tested setting
options.HtmlMarkupGenerationMode = HtmlSaveOptions.HtmlMarkupGenerationModes.WriteOnlyBodyContent;
options.SplitIntoPages = true;
doc.Save(dataDir + "CreateSubsequentFiles_out.html", options);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
Document doc = new Document(dataDir + "PDFToHTML.pdf");
// Instantiate HTML SaveOptions object
HtmlSaveOptions htmlOptions = new HtmlSaveOptions();
// Specify to render PDF document layers separately in output HTML
htmlOptions.ConvertMarkedContentToLayers = true;
// Save the document
doc.Save(dataDir + "LayersRendering_out.html", htmlOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open the source PDF document
Document pdfDocument = new Document(dataDir + "PDFToHTML.pdf");
// Instantiate HTML SaveOptions object
HtmlSaveOptions htmlOptions = new HtmlSaveOptions();
// Specify to split the output into multiple pages
htmlOptions.SplitIntoPages = true;
// Save the document
pdfDocument.Save(@"MultiPageHTML_out.html", htmlOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open the source PDF document
Document pdfDocument = new Document(dataDir + "PDFToHTML.pdf");
// Save the file into MS document format
pdfDocument.Save(dataDir + "output_out.html", SaveFormat.Html);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Load the PDF file
Document doc = new Document(dataDir + "PDFToHTML.pdf");
// Instantiate HTML save options object
HtmlSaveOptions newOptions = new HtmlSaveOptions();
// Specify the folder where SVG images are saved during PDF to HTML conversion
newOptions.SpecialFolderForSvgImages = dataDir;
// Save the output file
doc.Save(dataDir + "SaveSVGFiles_out.html", newOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// Create HtmlSaveOption with tested feature
HtmlSaveOptions newOptions = new HtmlSaveOptions();
// Specify the separate folder to save images
newOptions.SpecialFolderForAllImages = dataDir;
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
Document doc = new Document(dataDir + "PDFToHTML.pdf");
HtmlSaveOptions htmlOptions = new HtmlSaveOptions();
htmlOptions.SaveShadowedTextsAsTransparentTexts = true;
htmlOptions.SaveTransparentTexts = true;
doc.Save(dataDir + "TransparentTextRendering_out.html", htmlOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
Document pdfDocument = new Document(dataDir + "input.pdf");
// Create HtmlSaveOption with tested feature
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.FixedLayout = true;
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
pdfDocument.Save(dataDir + "AvoidSavingImages_out.html", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
Document doc = new Document( dataDir + "input.pdf");
// Tune conversion params
HtmlSaveOptions newOptions = new HtmlSaveOptions();
newOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
newOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
newOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
newOptions.LettersPositioningMethod = HtmlSaveOptions.LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
newOptions.SplitIntoPages = false;// Force write HTMLs of all pages into one output document
newOptions.CustomHtmlSavingStrategy = new HtmlSaveOptions.HtmlPageMarkupSavingStrategy(SavingToStream);
// We can use some non-existing puth as result file name - all real saving will be done
// In our custom method SavingToStream() (it's follows this one)
doc.Save(dataDir + "OutPutToStream_out.html", newOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
static string _folderForReferencedResources_34748;
public static void PDFNEWNET_34748()
{
//-----------------------------------------------------
// 1) Tune paths and set license
//-----------------------------------------------------
(new Aspose.Pdf.License()).SetLicense(@"F:\_Sources\Aspose_5\trunk\testdata\License\Aspose.Total.lic");
Document pdfDocument = new Document(@"F:\ExternalTestsData\34748_36189.pdf");
string outHtmlFile = @"F:\ExternalTestsData\34748.html";
_folderForReferencedResources_34748 = @"F:\ExternalTestsData\out_34748\";
//-----------------------------------------------------
// 2) Clean results if they already present
//-----------------------------------------------------
if (Directory.Exists(_folderForReferencedResources_34748))
{
Directory.Delete(_folderForReferencedResources_34748, true);
}
File.Delete(outHtmlFile);
//-----------------------------------------------------
// Create HtmlSaveOption with tested feature
//-----------------------------------------------------
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.CustomResourceSavingStrategy = new HtmlSaveOptions.ResourceSavingStrategy(Strategy_11_CUSTOM_SAVE_OF_FONTS_AND_IMAGES);
saveOptions.CustomCssSavingStrategy = new HtmlSaveOptions.CssSavingStrategy(Strategy_11_CSS_WriteCssToPredefinedFolder);
saveOptions.CustomStrategyOfCssUrlCreation = new HtmlSaveOptions.CssUrlMakingStrategy(Strategy_11_CSS_ReturnResultPathInPredefinedTestFolder);
using (Stream outStream = File.OpenWrite(outHtmlFile))
{
pdfDocument.Save(outStream, saveOptions);
}
}
private static void Strategy_11_CSS_WriteCssToPredefinedFolder(HtmlSaveOptions.CssSavingInfo resourceInfo)
{
if (!Directory.Exists(_folderForReferencedResources_34748))
{
Directory.CreateDirectory(_folderForReferencedResources_34748);
}
string path = _folderForReferencedResources_34748 + Path.GetFileName(resourceInfo.SupposedURL);
System.IO.BinaryReader reader = new BinaryReader(resourceInfo.ContentStream);
System.IO.File.WriteAllBytes(path, reader.ReadBytes((int)resourceInfo.ContentStream.Length));
}
private static string Strategy_11_CSS_ReturnResultPathInPredefinedTestFolder(HtmlSaveOptions.CssUrlRequestInfo requestInfo)
{
return "file:///" + _folderForReferencedResources_34748.Replace(@"\", "/") + "css_style{0}.css";
}
private static string Strategy_11_CUSTOM_SAVE_OF_FONTS_AND_IMAGES(SaveOptions.ResourceSavingInfo resourceSavingInfo)
{
if (!Directory.Exists(_folderForReferencedResources_34748))
{
Directory.CreateDirectory(_folderForReferencedResources_34748);
}
string path = _folderForReferencedResources_34748 + Path.GetFileName(resourceSavingInfo.SupposedFileName);
// The first path of this method is for saving fonts
System.IO.BinaryReader contentReader = new BinaryReader(resourceSavingInfo.ContentStream);
System.IO.File.WriteAllBytes(path, contentReader.ReadBytes((int)resourceSavingInfo.ContentStream.Length));
string urlThatWillBeUsedInHtml = "file:///" + _folderForReferencedResources_34748.Replace(@"\", "/") + Path.GetFileName(resourceSavingInfo.SupposedFileName);
return urlThatWillBeUsedInHtml;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SavingToStream(HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo)
{
byte[] resultHtmlAsBytes = new byte[htmlSavingInfo.ContentStream.Length];
htmlSavingInfo.ContentStream.Read(resultHtmlAsBytes, 0, resultHtmlAsBytes.Length);
// Here You can use any writable stream, file stream is taken just as example
string fileName = "stream_out.html";
Stream outStream = File.OpenWrite(fileName);
outStream.Write(resultHtmlAsBytes, 0, resultHtmlAsBytes.Length);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
Document pdfDocument = new Document(dataDir + "input.pdf");
string outHtmlFile = dataDir + "PrefixCSSClassNames_out.html";
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.CssClassNamesPrefix = ".gDV__ .stl_";
pdfDocument.Save(outHtmlFile, saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
Document doc = new Document(dataDir + "input.pdf");
string outHtmlFile = dataDir + "PrefixForFonts_out.html";
_desiredFontDir = Path.GetDirectoryName(outHtmlFile) + @"\36296_files\";
if (!Directory.Exists(_desiredFontDir))
{
Directory.CreateDirectory(_desiredFontDir);
}
// Reset counter for font names - this counter will be used in our custom code
// To generate unigue font file names
_fontNumberForUniqueFontFileNames = 0;
// Create HtmlSaveOption with custom saving strategy that will do all the job
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.CustomResourceSavingStrategy = new HtmlSaveOptions.ResourceSavingStrategy(CustomResourcesProcessing);
doc.Save(outHtmlFile, saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static string CustomResourcesProcessing(SaveOptions.ResourceSavingInfo resourceSavingInfo)
{
//-----------------------------------------------------------------------------
// It's just example of possible realization of cusstom processing of resources
// Referenced in result HTML
//-----------------------------------------------------------------------------
// 1) In this case we need only do something special
// with fonts, so let's leave processing of all other resources
// to converter itself
if (resourceSavingInfo.ResourceType != SaveOptions.NodeLevelResourceType.Font)
{
resourceSavingInfo.CustomProcessingCancelled = true;
return "";
}
// If supplied font resource, process it ourselves
// 1) Write supplied font with short name to desired folder
// You can easily do anythings - it's just one of realizations
_fontNumberForUniqueFontFileNames++;
string shortFontFileName = (_fontNumberForUniqueFontFileNames.ToString() + Path.GetExtension(resourceSavingInfo.SupposedFileName));
string outFontPath = _desiredFontDir + "\\" + shortFontFileName;
System.IO.BinaryReader fontBinaryReader = new BinaryReader(resourceSavingInfo.ContentStream);
System.IO.File.WriteAllBytes(outFontPath, fontBinaryReader.ReadBytes((int)resourceSavingInfo.ContentStream.Length));
// 2) Return the desired URI with which font will be referenced in CSSes
string fontUrl = "http:// Localhost:255/document-viewer/GetFont/" + shortFontFileName;
return fontUrl;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
Document testDoc = new Document(dataDir + "input.pdf");
HtmlSaveOptions options = new HtmlSaveOptions();
// This is main setting that allows work and testing of tested feature
options.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsExternalPngFilesReferencedViaSvg;//
options.CustomResourceSavingStrategy = new HtmlSaveOptions.ResourceSavingStrategy(Custom_processor_of_embedded_images);
// Do conversion
testDoc.Save(dataDir + @"PrefixForURLs_out.html", options);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static string Custom_processor_of_embedded_images(SaveOptions.ResourceSavingInfo resourceSavingInfo)
{
// ____________________________________________________________________________
// This sample method saving strategy method saves image-files in some folder
// (including raster image files that are exctracted from that SVGs)
// Then it returns specific custom artificial path
// to be used as value of 'src' or 'data' relevant attribute in generated host-SVG(or HTML)
// ____________________________________________________________________________
//---------------------------------------------------------
// 1) All other files(f.e. fonts) will be processed with converter itself cause for them flag
// resourceSavingInfo.CustomProcessingCancelled is set to 'true'
//---------------------------------------------------------
if (!(resourceSavingInfo is HtmlSaveOptions.HtmlImageSavingInfo))
{
resourceSavingInfo.CustomProcessingCancelled = true;
return "";
}
//---------------------------------------------------------
// 1) Create target folder if not created yet
//---------------------------------------------------------
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
string outDir = dataDir + @"output\36297_files\";
string outPath = outDir + Path.GetFileName(resourceSavingInfo.SupposedFileName);
if (!Directory.Exists(outDir))
{
Directory.CreateDirectory(outDir);
}
//---------------------------------------------------------
// 3) Write supplied image to that folder
//---------------------------------------------------------
System.IO.BinaryReader reader = new BinaryReader(resourceSavingInfo.ContentStream);
System.IO.File.WriteAllBytes(dataDir, reader.ReadBytes((int)resourceSavingInfo.ContentStream.Length));
//---------------------------------------------------------
// 4) Return customized specific URL to be used to refer
// just created image in parent SVG (or HTML)
//---------------------------------------------------------
HtmlSaveOptions.HtmlImageSavingInfo asHtmlImageSavingInfo = resourceSavingInfo as HtmlSaveOptions.HtmlImageSavingInfo;
if (asHtmlImageSavingInfo.ParentType == HtmlSaveOptions.ImageParentTypes.SvgImage)
{
return "http:// Localhost:255/" + resourceSavingInfo.SupposedFileName;
}
else
{
return "http:// Localhost:GetImage/imageID=" + resourceSavingInfo.SupposedFileName;
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
string linceseFile = ""; // E.g @"F:\_Sources\Aspose.Total.lic"
(new Aspose.Pdf.License()).SetLicense(linceseFile);
Document pdfDocument = new Document(dataDir + "input.pdf");
string outHtmlFile = dataDir + "PrefixToImportDirectives_out.html";
_folderForReferencedResources_36435 = dataDir;
// Create HtmlSaveOption with tested feature
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.CustomStrategyOfCssUrlCreation = new HtmlSaveOptions.CssUrlMakingStrategy(Strategy_10_CSS_ReturnResultPathInPredefinedTestFolder);
saveOptions.CustomCssSavingStrategy = new HtmlSaveOptions.CssSavingStrategy(Strategy_10_CSS_WriteCssToResourceFolder);
//----------------------------------------------------------------------------
// Run converter
//----------------------------------------------------------------------------
pdfDocument.Save(outHtmlFile, saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void Strategy_10_CSS_WriteCssToResourceFolder(HtmlSaveOptions.CssSavingInfo resourceInfo)
{
// -------------------------------------------------------
// This is only one of possible implementation of saving
// You can write and use Your own implementation if You will
// -------------------------------------------------------
// Get CSS file name from requested file.
// Some trick required cause we get in parameters of this method
// Not pure file name but full URL that
// Created with usage of our template returned in Strategy_9_CSS_ReturnResultPathInPredefinedTestFolder()
// So, knowing of that template we must extract from it CSS file name itself
string guid = System.Guid.NewGuid().ToString();
string fullPathWithGuid = Strategy_10_CSS_ReturnResultPathInPredefinedTestFolder(new HtmlSaveOptions.CssUrlRequestInfo());
fullPathWithGuid = string.Format(fullPathWithGuid, guid);
int prefixLength = fullPathWithGuid.IndexOf(guid);
int suffixLength = fullPathWithGuid.Length - (fullPathWithGuid.IndexOf(guid) + guid.Length);
string fullPath = resourceInfo.SupposedURL;
fullPath = fullPath.Substring(prefixLength);
string cssFileNameCore = fullPath.Substring(0, fullPath.Length - suffixLength);
// Get final file name for saving
string cssFileName = "style" + cssFileNameCore + ".css";
string path = _folderForReferencedResources_36435 + cssFileName;
// Saving itself
System.IO.BinaryReader reader = new BinaryReader(resourceInfo.ContentStream);
System.IO.File.WriteAllBytes(path, reader.ReadBytes((int)resourceInfo.ContentStream.Length));
}
private static string Strategy_10_CSS_ReturnResultPathInPredefinedTestFolder(HtmlSaveOptions.CssUrlRequestInfo requestInfo)
{
string template = "http:// Localhost:24661/document-viewer/GetResourceForHtmlHandler?documentPath=Deutschland201207Arbeit.pdf&resourcePath=style{0}.css&fileNameOnly=false";
return template;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
string licenseFile = ""; // E.g F:\_Sources\Aspose_5\trunk\testdata\License\Aspose.Total.lic
(new Aspose.Pdf.License()).SetLicense(licenseFile);
Document doc = new Document(dataDir + "input.pdf");
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
// SaveOptions.CustomProgressHandler = new HtmlSaveOptions.ConversionProgessEventHandler(ShowProgressOnConsole);
saveOptions.SplitIntoPages = false;
doc.Save(dataDir + "ProgressDetails_out_.html", saveOptions);
Console.ReadLine();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
public static void ShowProgressOnConsole(HtmlSaveOptions.ProgressEventHandlerInfo eventInfo)
{
switch (eventInfo.EventType)
{
case HtmlSaveOptions.ProgressEventType.TotalProgress:
Console.WriteLine(String.Format("{0} - Conversion progress : {1}% .", DateTime.Now.TimeOfDay, eventInfo.Value.ToString()));
break;
case HtmlSaveOptions.ProgressEventType.SourcePageAnalized:
Console.WriteLine(String.Format("{0} - Source page {1} of {2} analyzed.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
break;
case HtmlSaveOptions.ProgressEventType.ResultPageCreated:
Console.WriteLine(String.Format("{0} - Result page's {1} of {2} layout created.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
break;
case HtmlSaveOptions.ProgressEventType.ResultPageSaved:
Console.WriteLine(String.Format("{0} - Result page {1} of {2} exported.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
break;
default:
break;
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
// Output HTML file path information
string outFile = Path.GetFullPath(dataDir + "36192_out.html");
// Source PDF document
Document doc = new Document(dataDir + "input.pdf");
// Create HtmlSaveOption with tested feature
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.FixedLayout = true;
saveOptions.SplitIntoPages = false;
// Save the fonts as TTF format
saveOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.AlwaysSaveAsTTF;
string htmlFile = Path.GetFullPath(outFile);
string linkedFilesFolder = Path.GetDirectoryName(htmlFile) + @"\36192_files";
if (Directory.Exists(linkedFilesFolder))
{
Directory.Delete(linkedFilesFolder, true);
}
// Save the output
doc.Save(outFile, saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
Document doc = new Document(dataDir + "input.pdf");
HtmlSaveOptions htmlOptions = new HtmlSaveOptions();
htmlOptions.FixedLayout = true;
htmlOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsExternalPngFilesReferencedViaSvg;
htmlOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
doc.Save(dataDir + "ThreeSetFonts_out.html", htmlOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
saveOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.AlwaysSaveAsWOFF;
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
Document doc = new Document(dataDir + "input.pdf");
// Pay attention that we put non-existing path here : since we use custon resource processing it won't be in use.
// If You forget implement some of required saving strategies(CustomHtmlSavingStrategy,CustomResourceSavingStrategy,CustomCssSavingStrategy), then saving will return "Path not found" exception
string outHtmlFile = dataDir + "SaveHTMLImageCSS_out.html";
// Create HtmlSaveOption with custom saving strategies that will do all the saving job
// In such approach You can split HTML in pages if You will
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.SplitIntoPages = true;
saveOptions.CustomHtmlSavingStrategy = new HtmlSaveOptions.HtmlPageMarkupSavingStrategy(StrategyOfSavingHtml);
saveOptions.CustomResourceSavingStrategy = new HtmlSaveOptions.ResourceSavingStrategy(CustomSaveOfFontsAndImages);
saveOptions.CustomStrategyOfCssUrlCreation = new HtmlSaveOptions.CssUrlMakingStrategy(CssUrlMakingStrategy);
saveOptions.CustomCssSavingStrategy = new HtmlSaveOptions.CssSavingStrategy(CustomSavingOfCss);
saveOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
doc.Save(outHtmlFile, saveOptions);
Console.WriteLine("Done");
Console.ReadLine();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void StrategyOfSavingHtml(HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo)
{
// Get target file name and write content to it
System.IO.BinaryReader reader = new BinaryReader(htmlSavingInfo.ContentStream);
byte[] htmlAsByte = reader.ReadBytes((int)htmlSavingInfo.ContentStream.Length);
Console.WriteLine("Html page processed with handler. Length of page's text in bytes is " + htmlAsByte.Length.ToString());
// Here You can put code that will save page's HTML to some storage, f.e database
MemoryStream targetStream = new MemoryStream();
targetStream.Write(htmlAsByte, 0, htmlAsByte.Length);
}
private static string CssUrlMakingStrategy(HtmlSaveOptions.CssUrlRequestInfo requestInfo)
{
string template = "style{0}.css";
// One more example of template :
// String template = "http:// Localhost:24661/document-viewer/GetResourceForHtmlHandler?documentPath=Deutschland201207Arbeit.pdf&resourcePath=style{0}.css&fileNameOnly=false";
return template;
}
private static void CustomSavingOfCss(HtmlSaveOptions.CssSavingInfo resourceInfo)
{
System.IO.BinaryReader reader = new BinaryReader(resourceInfo.ContentStream);
byte[] cssAsBytes = reader.ReadBytes((int)resourceInfo.ContentStream.Length);
Console.WriteLine("Css page processed with handler. Length of css in bytes is " + cssAsBytes.Length.ToString());
// Here You can put code that will save page's HTML to some storage, f.e database
MemoryStream targetStream = new MemoryStream();
targetStream.Write(cssAsBytes, 0, cssAsBytes.Length);
}
private static string CustomSaveOfFontsAndImages(SaveOptions.ResourceSavingInfo resourceSavingInfo)
{
System.IO.BinaryReader reader = new BinaryReader(resourceSavingInfo.ContentStream);
byte[] resourceAsBytes = reader.ReadBytes((int)resourceSavingInfo.ContentStream.Length);
if (resourceSavingInfo.ResourceType == SaveOptions.NodeLevelResourceType.Font)
{
Console.WriteLine("Font processed with handler. Length of content in bytes is " + resourceAsBytes.Length.ToString());
// Here You can put code that will save font to some storage, f.e database
MemoryStream targetStream = new MemoryStream();
targetStream.Write(resourceAsBytes, 0, resourceAsBytes.Length);
}
else if (resourceSavingInfo.ResourceType == SaveOptions.NodeLevelResourceType.Image)
{
Console.WriteLine("Image processed with handler. Length of content in bytes is " + resourceAsBytes.Length.ToString());
// Here You can put code that will save image to some storage, f.e database
MemoryStream targetStream = new MemoryStream();
targetStream.Write(resourceAsBytes, 0, resourceAsBytes.Length);
}
// We should return URI bt which resource will be referenced in CSS(for font)
// Or HTML(for images)
// This is very siplistic way - here we just return file name or resource.
// You can put here some URI that will include ID of resource in database etc.
// - this URI will be added into result CSS or HTML to refer the resource
return resourceSavingInfo.SupposedFileName;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
// Source PDF file
Document doc = new Document(dataDir + "input.pdf");
// Create HtmlSaveOption with tested feature
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.FixedLayout = true;
saveOptions.SplitIntoPages = false;
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsExternalPngFilesReferencedViaSvg;
// Save the output in HTML format
doc.Save( dataDir + "SaveImages_out.html", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
// Select desirable page size
float newPageWidth = 400f;
float newPageHeight = 400f;
// Tune PdfPageEditor class
Aspose.Pdf.Facades.PdfPageEditor pdfEditor = new Aspose.Pdf.Facades.PdfPageEditor();
// Bind source PDF file
pdfEditor.BindPdf(dataDir + "input.pdf");
// Set the page dimensions
pdfEditor.PageSize = new Aspose.Pdf.PageSize(newPageWidth, newPageHeight);
// Set vertical alignment for page as center aligned
pdfEditor.VerticalAlignmentType = Aspose.Pdf.VerticalAlignment.Center;
// Set Horizontal alignment for page as center aligned
pdfEditor.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
// This scales page content to fit width,
// Comment it out or set Zoom to 1.0F if You don't want to scale
// Content and only want to change page's size (i.e. crop it)
float zoom = Math.Min((float)newPageWidth / (float)pdfEditor.Document.Pages[1].Rect.Width,
(float)newPageHeight / (float)pdfEditor.Document.Pages[1].Rect.Height);
pdfEditor.Zoom = zoom;// (float)595;
// Create stream object to hold file with updated dimensions
MemoryStream output = new MemoryStream();
// Save file to stream object
pdfEditor.Save(output);
// Then reload scaled document and save it to HTML
Document exportDoc = new Document(output);
HtmlSaveOptions htmlOptions = new HtmlSaveOptions();
// This code shows page boreder in result - sometimes it comes in handy to see borders
SaveOptions.BorderPartStyle borderStyle = new SaveOptions.BorderPartStyle();
borderStyle.LineType = SaveOptions.HtmlBorderLineType.Dotted;
borderStyle.Color = System.Drawing.Color.Gray;
htmlOptions.PageBorderIfAny = new SaveOptions.BorderInfo(borderStyle);
// Conversion to HTML itself
exportDoc.Save(dataDir + "SetOutputFileDimensions_out.html", htmlOptions);
// Close the stream object
output.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
// Load source PDF file
Document doc = new Document(dataDir + "input.pdf");
// Instantiate HTML Save options object
HtmlSaveOptions newOptions = new HtmlSaveOptions();
// Enable option to embed all resources inside the HTML
newOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
// This is just optimization for IE and can be omitted
newOptions.LettersPositioningMethod = HtmlSaveOptions.LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
newOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
newOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.SaveInAllFormats;
// Output file path
string outHtmlFile = "SingleHTML_out.html";
doc.Save(outHtmlFile, newOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
string outFile = dataDir + "SpecifyImages_out.html";
Document doc = new Document(dataDir + "input.pdf");
// Create HtmlSaveOption with tested feature
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.SplitIntoPages = false;
saveOptions.CustomResourceSavingStrategy = new HtmlSaveOptions.ResourceSavingStrategy(SavingTestStrategy_1);
doc.Save(outFile, saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static string SavingTestStrategy_1(SaveOptions.ResourceSavingInfo resourceSavingInfo)
{
// This sample method saving strategy method saves only svg-files in some folder and returns specific path
// To be used as value of 'src' or 'data' relevant attribute in generated HTML
// All other files will be processed with converter itself cause for them flag
// ResourceSavingInfo.CustomProcessingCancelled is set to 'true'
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
if (!(resourceSavingInfo is HtmlSaveOptions.HtmlImageSavingInfo))
{
resourceSavingInfo.CustomProcessingCancelled = true;
return "";
}
HtmlSaveOptions.HtmlImageSavingInfo asHtmlImageSavingInfo = (HtmlSaveOptions.HtmlImageSavingInfo)resourceSavingInfo;
if ((asHtmlImageSavingInfo.ImageType != HtmlSaveOptions.HtmlImageType.Svg)
&& (asHtmlImageSavingInfo.ImageType != HtmlSaveOptions.HtmlImageType.ZippedSvg)
)
{
resourceSavingInfo.CustomProcessingCancelled = true;
return "";
}
string outFile = dataDir + "SpecifyImages_out.html";
string imageOutFolder = Path.GetFullPath(Path.GetDirectoryName(outFile)
+ @"\35956_svg_files\");
// ImageOutFolder="C:\AsposeImagesTests\";
if (!Directory.Exists(imageOutFolder))
{
Directory.CreateDirectory(imageOutFolder);
}
string outPath = imageOutFolder + Path.GetFileName(resourceSavingInfo.SupposedFileName);
System.IO.BinaryReader reader = new BinaryReader(resourceSavingInfo.ContentStream);
System.IO.File.WriteAllBytes(outPath, reader.ReadBytes((int)resourceSavingInfo.ContentStream.Length));
return "/document-viewer/GetImage?path=CRWU-NDWAC-Final-Report-12-09-10-2.pdf&name=" + resourceSavingInfo.SupposedFileName;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
// 1) Clean-up target folders
string htmlFile = Path.GetFullPath(dataDir + "resultant.html");
string imagesDir = Path.GetDirectoryName(htmlFile) + @"\35942_files";
string cssDir = Path.GetDirectoryName(htmlFile) + @"\35942_css_files";
if (Directory.Exists(imagesDir)) { Directory.Delete(imagesDir, true); };
if (Directory.Exists(cssDir)) { Directory.Delete(cssDir, true); };
// 2) Create document for conversion
Document pdfDocument = new Document(dataDir + "input.pdf");
// 3) Tune conversion options
HtmlSaveOptions options = new HtmlSaveOptions();
options.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsPngImagesEmbeddedIntoSvg;//<- to get compatibility with previous behavior and therefore same result of tests
// Split HTML output into pages
options.SplitIntoPages = true;
// Split css into pages
options.SplitCssIntoPages = true;
options.CustomCssSavingStrategy = new HtmlSaveOptions.CssSavingStrategy(Strategy_4_CSS_MULTIPAGE_SAVING_RIGHT_WAY);
options.CustomStrategyOfCssUrlCreation = new HtmlSaveOptions.CssUrlMakingStrategy(Strategy_5_CSS_MAKING_CUSTOM_URL_FOR_MULTIPAGING);
// 3) Do conversion
pdfDocument.Save(htmlFile, options);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void Strategy_4_CSS_MULTIPAGE_SAVING_RIGHT_WAY(HtmlSaveOptions.CssSavingInfo partSavingInfo)
{
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion_PDFToHTMLFormat();
string outPath = dataDir + "style_xyz_page" + partSavingInfo.CssNumber.ToString() + ".css";
System.IO.BinaryReader reader = new BinaryReader(partSavingInfo.ContentStream);
System.IO.File.WriteAllBytes(outPath, reader.ReadBytes((int)partSavingInfo.ContentStream.Length));
}
private static string Strategy_5_CSS_MAKING_CUSTOM_URL_FOR_MULTIPAGING(HtmlSaveOptions.CssUrlRequestInfo requestInfo)
{
return "/document-viewer/GetCss?cssId=4544554445_page{0}";
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open document
Document pdfDocument = new Document(dataDir + "PDFToPDFA.pdf");
// Convert to PDF/A compliant document
// During conversion process, the validation is also performed
pdfDocument.Convert(dataDir + "log.xml", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
dataDir = dataDir + "PDFToPDFA_out.pdf";
// Save output document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open document
Document pdfDocument = new Document(dataDir + "input.pdf");
pdfDocument.Convert(new MemoryStream(), PdfFormat.PDF_A_3B, ConvertErrorAction.Delete);
dataDir = dataDir + "PDFToPDFA3b_out.pdf";
// Save output document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Open document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Create Aspose.Pdf.RenderingOptions to enable font hinting
RenderingOptions opts = new RenderingOptions();
opts.UseFontHinting = true;
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + "_out" + ".png", FileMode.Create))
{
// Create PNG device with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
PngDevice pngDevice = new PngDevice(resolution);
// Set predefined rendering options
pngDevice.RenderingOptions = opts;
// Convert a particular page and save the image to stream
pngDevice.Process(pdfDocument.Pages[pageCount], imageStream);
// Close stream
imageStream.Close();
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Load PDF document
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "input.pdf");
// Instantiate PptxSaveOptions instance
Aspose.Pdf.PptxSaveOptions pptx_save = new Aspose.Pdf.PptxSaveOptions();
// Save the output in PPTX format
doc.Save(dataDir + "PDFToPPT_out.pptx", pptx_save);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Load PDF document
Document doc = new Document(dataDir + "input.pdf");
// Instantiate an object of SvgSaveOptions
SvgSaveOptions saveOptions = new SvgSaveOptions();
// Do not compress SVG image to Zip archive
saveOptions.CompressOutputToZipArchive = false;
// Save the output in SVG files
doc.Save(dataDir + "PDFToSVG_out.svg", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Create Document object
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "PDFToTeX.pdf");
// Instantiate LaTex save option
LaTeXSaveOptions saveOptions = new LaTeXSaveOptions();
// Specify the output directory
string pathToOutputDirectory = dataDir;
// Set the output directory path for save option object
saveOptions.OutDirectoryPath = pathToOutputDirectory;
// Save PDF file into LaTex format
doc.Save(dataDir + "PDFToTeX_out.tex", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// Instantiate ExcelSave Option object
Aspose.Pdf.ExcelSaveOptions excelsave = new ExcelSaveOptions();
excelsave.InsertBlankColumnAtFirst = false;
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// Instantiate ExcelSave Option object
Aspose.Pdf.ExcelSaveOptions excelsave = new ExcelSaveOptions();
// Set this property to true
excelsave.MinimizeTheNumberOfWorksheets = true;
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Load PDF document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Instantiate ExcelSave Option object
Aspose.Pdf.ExcelSaveOptions excelsave = new ExcelSaveOptions();
// Save the output in XLS format
pdfDocument.Save("PDFToXLS_out.xls", excelsave);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Load PDF document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Instantiate ExcelSave Option object
Aspose.Pdf.ExcelSaveOptions excelsave = new ExcelSaveOptions();
excelsave.Format = ExcelSaveOptions.ExcelFormat.XLSX;
// Save the output in XLS format
pdfDocument.Save("PDFToXLSX_out.xlsx", excelsave);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Load source PDF file
Document doc = new Document(dataDir + "input.pdf");
// Save output in XML format
doc.Save(dataDir + "PDFToXML_out.xml", SaveFormat.MobiXml);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Load PDF document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Instantiate XPS Save options
Aspose.Pdf.XpsSaveOptions saveOptions = new Aspose.Pdf.XpsSaveOptions();
// Save the XPS document
pdfDocument.Save("PDFToXPS_out.xps", saveOptions);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Create a new instance of PsLoadOptions
LoadOptions options = new PsLoadOptions();
// Open .ps document with created load options
Document pdfDocument = new Document(dataDir + "input.ps", options);
// Save document
pdfDocument.Save(dataDir + "PSToPDF.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Create a request for the URL.
WebRequest request = WebRequest.Create("http:// My.signchart.com/Report/PrintBook.asp?ProjectGuid=6FB9DBB0-");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseFromServer));
HtmlLoadOptions options = new HtmlLoadOptions("http:// My.signchart.com/");
options.ExternalResourcesCredentials = CredentialCache.DefaultCredentials;
// Load HTML file
Document pdfDocument = new Document(stream, options);
// Save resultant file
pdfDocument.Save("ProvideCredentialsDuringHTMLToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
Document doc = new Document(dataDir + "SampleHtmlFile.html", new HtmlLoadOptions());
doc.Save(new MemoryStream());
foreach (Annotation a in doc.Pages[1].Annotations)
{
if (a.AnnotationType == AnnotationType.Link)
{
LinkAnnotation la = (LinkAnnotation)a;
if (la.Action is GoToURIAction)
{
GoToURIAction gta = (GoToURIAction)la.Action;
gta.URI = "";
TextFragmentAbsorber tfa = new TextFragmentAbsorber();
tfa.TextSearchOptions = new TextSearchOptions(a.Rect);
doc.Pages[a.PageIndex].Accept(tfa);
foreach (TextFragment tf in tfa.TextFragments)
{
tf.TextState.Underline = false;
tf.TextState.ForegroundColor = Color.Black;
}
}
doc.Pages[a.PageIndex].Annotations.Delete(a);
}
}
doc.Save(dataDir + "RemoveHyperlinksFromText_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
Aspose.Pdf.Text.Font originalFont = null;
try
{
originalFont = FontRepository.FindFont("AgencyFB");
}
catch (Exception)
{
// Font is missing on destination machine
FontRepository.Substitutions.Add(new SimpleFontSubstitution("AgencyFB", "Arial"));
}
var fileNew = new FileInfo(dataDir + "newfile_out.pdf");
var pdf = new Document(dataDir + "input.pdf");
pdf.Convert( dataDir + "log.xml", PdfFormat.PDF_A_1B, ConvertErrorAction.Delete);
pdf.Save(fileNew.FullName);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate LoadOption object using SVG load option
Aspose.Pdf.LoadOptions loadopt = new Aspose.Pdf.SvgLoadOptions();
// Create Document object
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "SVGToPDF.svg", loadopt);
// Save the resultant PDF document
doc.Save(dataDir + "SVGToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate Latex Load option object
LatexLoadOptions Latexoptions = new LatexLoadOptions();
// Create Document object
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "samplefile.tex", Latexoptions);
// Save the output in PDF file
doc.Save(dataDir + "TeXToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Read the source text file
TextReader tr = new StreamReader(dataDir + "log.txt");
// Instantiate a Document object by calling its empty constructor
Document doc = new Document();
// Add a new page in Pages collection of Document
Page page = doc.Pages.Add();
// Create an instance of TextFragmet and pass the text from reader object to its constructor as argument
TextFragment text = new TextFragment(tr.ReadToEnd());
// Text.TextState.Font = FontRepository.FindFont("Arial Unicode MS");
// Add a new text paragraph in paragraphs collection and pass the TextFragment object
page.Paragraphs.Add(text);
// Save resultant PDF file
doc.Save(dataDir + "TexttoPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Get a list of tiff image files
string[] files = System.IO.Directory.GetFiles(dataDir, "*.tif");
// Instantiate a Document object
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
// Navigate through the files and them in the pdf file
foreach (string myFile in files)
{
// Load all tiff files in byte array
FileStream fs = new FileStream(myFile, FileMode.Open, FileAccess.Read);
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, Convert.ToInt32(fs.Length));
MemoryStream mystream = new MemoryStream(tmpBytes);
Bitmap b = new Bitmap(mystream);
// Create a new Page in the Pdf document
Aspose.Pdf.Page currpage = doc.Pages.Add();
// Set margins so image will fit, etc.
currpage.PageInfo.Margin.Top = 5;
currpage.PageInfo.Margin.Bottom = 5;
currpage.PageInfo.Margin.Left = 5;
currpage.PageInfo.Margin.Right = 5;
currpage.PageInfo.Width = (b.Width / b.HorizontalResolution) * 72;
currpage.PageInfo.Height = (b.Height / b.VerticalResolution) * 72;
// Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
// Add the image into paragraphs collection of the page
currpage.Paragraphs.Add(image1);
// Set IsBlackWhite property to true for performance improvement
image1.IsBlackWhite = true;
// Set the ImageStream to a MemoryStream object
image1.ImageStream = mystream;
// Set desired image scale
image1.ImageScale = 0.95F;
}
// Save the Pdf
doc.Save(dataDir + "PerformaceImprovement_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Create a request for the URL.
WebRequest request = WebRequest.Create("https:// En.wikipedia.org/wiki/Main_Page");
// If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials;
// Time out in miliseconds before the request times out
// Request.Timeout = 100;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(responseFromServer));
HtmlLoadOptions options = new HtmlLoadOptions("https:// En.wikipedia.org/wiki/");
// Load HTML file
Document pdfDocument = new Document(stream, options);
options.PageInfo.IsLandscape = true;
// Save output as PDF format
pdfDocument.Save(dataDir + "WebPageToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate Document object
Document doc = new Document();
// Bind source XML file
doc.BindXml( dataDir + "log.xml");
// Get reference of page object from XML
Page page = (Page)doc.GetObjectById("mainSection");
// Get reference of first TextSegment with ID boldHtml
TextSegment segment = (TextSegment)doc.GetObjectById("boldHtml");
// Get reference of second TextSegment with ID strongHtml
segment = (TextSegment)doc.GetObjectById("strongHtml");
// Save resultant PDF file
doc.Save(dataDir + "XMLToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
string inXml = dataDir + "input.xml";
string inFile = dataDir + "aspose-logo.jpg";
string outFile = dataDir + "output_out.pdf";
Document doc = new Document();
doc.BindXml(inXml);
Image image = (Image)doc.GetObjectById("testImg");
image.File = inFile;
doc.Save(outFile);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
// Instantiate LoadOption object using XPS load option
Aspose.Pdf.LoadOptions options = new XpsLoadOptions();
// Create document object
Aspose.Pdf.Document document = new Aspose.Pdf.Document(dataDir + "XPSToPDF.xps", options);
// Save the resultant PDF document
document.Save(dataDir + "XPSToPDF_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load source PDF form
Document doc = new Document(dataDir + "AddTooltipToField.pdf");
// Set the tooltip for textfield
(doc.Form["textbox1"] as Field).AlternateName = "Text box tool tip";
dataDir = dataDir + "AddTooltipToField_out.pdf";
// Save the updated document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load PDF form contents
FileStream fs = new FileStream(dataDir + "FillFormField.pdf", FileMode.Open, FileAccess.ReadWrite);
// Instantiate Document instance with stream holding form file
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs);
// Get referecne of particuarl TextBoxField
TextBoxField txtFld = pdfDocument.Form["textbox1"] as TextBoxField;
// Fill form field with arabic text
txtFld.Value = "يولد جميع الناس أحراراً متساوين في";
dataDir = dataDir + "ArabicTextFilling_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Create Document object
Document doc = new Document();
// Add page to document object
doc.Pages.Add();
// Instantiate ComboBox Field object
ComboBoxField combo = new ComboBoxField(doc.Pages[1], new Aspose.Pdf.Rectangle(100, 600, 150, 616));
// Add option to ComboBox
combo.AddOption("Red");
combo.AddOption("Yellow");
combo.AddOption("Green");
combo.AddOption("Blue");
// Add combo box object to form fields collection of document object
doc.Form.Add(combo);
dataDir = dataDir + "ComboBox_out.pdf";
// Save the PDF document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Create a new document
Document doc = new Document();
Page page = doc.Pages.Add();
// Add radio button field
RadioButtonField field = new RadioButtonField(page);
field.Rect = new Aspose.Pdf.Rectangle(40, 650, 100, 720);
field.PartialName = "NewField";
// Add radio button options. please note that these options are situated
// Neither horizontally nor vertically.
// You can try to set any coordinates (and even size) for them.
RadioButtonOptionField opt1 = new RadioButtonOptionField();
opt1.Rect = new Aspose.Pdf.Rectangle(40, 650, 60, 670);
opt1.OptionName = "Item1";
opt1.Border = new Border(opt1);
opt1.Border.Width = 1;
opt1.Characteristics.Border = System.Drawing.Color.Black;
RadioButtonOptionField opt2 = new RadioButtonOptionField();
opt2.Rect = new Aspose.Pdf.Rectangle(60, 670, 80, 690);
opt2.OptionName = "Item2";
opt2.Border = new Border(opt2);
opt2.Border.Width = 1;
opt2.Characteristics.Border = System.Drawing.Color.Black;
RadioButtonOptionField opt3 = new RadioButtonOptionField();
opt3.Rect = new Aspose.Pdf.Rectangle(80, 690, 100, 710);
opt3.OptionName = "Item3";
opt3.Border = new Border(opt3);
opt3.Border.Width = 1;
opt3.Characteristics.Border = System.Drawing.Color.Black;
field.Add(opt1);
field.Add(opt2);
field.Add(opt3);
doc.Form.Add(field);
dataDir = dataDir + "CreateDoc_out.pdf";
// Save the PDF document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "DeleteFormField.pdf");
// Delete a particular field by name
pdfDocument.Form.Delete("textbox1");
dataDir = dataDir + "DeleteFormField_out.pdf";
// Save modified document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load source PDF file
Document pdf = new Document(dataDir + "DetermineRequiredField.pdf");
// Instantiate Form object
Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form(pdf);
// Iterate through each field inside PDF form
foreach (Field field in pdf.Form.Fields)
{
// Determine if the field is marked as required or not
bool isRequired = pdfForm.IsRequiredField(field.FullName);
if (isRequired)
{
// Print either the field is marked as required or not
Console.WriteLine("The field named " + field.FullName + " is required");
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load dynamic XFA form
Document document = new Document(dataDir + "DynamicXFAToAcroForm.pdf");
// Set the form fields type as standard AcroForm
document.Form.Type = FormType.Standard;
dataDir = dataDir + "Standard_AcroForm_out.pdf";
// Save the resultant PDF
document.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "FillFormField.pdf");
// Get a field
TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField;
// Modify field value
textBoxField.Value = "Value to be filled in the field";
dataDir = dataDir + "FillFormField_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load XFA form
Document doc = new Document(dataDir + "FillXFAFields.pdf");
// Get names of XFA form fields
string[] names = doc.Form.XFA.FieldNames;
// Set field values
doc.Form.XFA[names[0]] = "Field 0";
doc.Form.XFA[names[1]] = "Field 1";
dataDir = dataDir + "Filled_XFA_out.pdf";
// Save the updated document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "FormFieldFont14.pdf");
// Get particular form field from document
Aspose.Pdf.Forms.Field field = pdfDocument.Form["textbox1"] as Aspose.Pdf.Forms.Field;
// Create font object
Aspose.Pdf.Text.Font font = FontRepository.FindFont("ComicSansMS");
// Set the font information for form field
// Field.DefaultAppearance = new Aspose.Pdf.Forms.in.DefaultAppearance(font, 10, System.Drawing.Color.Black);
dataDir = dataDir + "FormFieldFont14_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load the output document
Document doc1 = new Document( dataDir + "input.pdf");
// Find added fields
RadioButtonField field0 = doc1.Form["Item1"] as RadioButtonField;
RadioButtonField field1 = doc1.Form["Item2"] as RadioButtonField;
RadioButtonField field2 = doc1.Form["Item3"] as RadioButtonField;
// And show positions of sub items for each of them.
foreach (RadioButtonOptionField option in field0)
{
Console.WriteLine(option.Rect);
}
foreach (RadioButtonOptionField option in field1)
{
Console.WriteLine(option.Rect);
}
foreach (RadioButtonOptionField option in field2)
{
Console.WriteLine(option.Rect);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open pdf file
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "GetFieldsFromRegion.pdf");
// Create rectangle object to get fields in that area
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(35, 30, 500, 500);
// Get the PDF form
Aspose.Pdf.Forms.Form form = doc.Form;
// Get fields in the rectangular area
Aspose.Pdf.Forms.Field[] fields = form.GetFieldsInRect(rectangle);
// Display Field names and values
foreach (Field field in fields)
{
// Display image placement properties for all placements
Console.Out.WriteLine("Field Name: " + field.FullName + "-" + "Field Value: " + field.Value);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "GetValueFromField.pdf");
SubmitFormAction act = pdfDocument.Form[1].OnActivated as SubmitFormAction;
if(act != null)
Console.WriteLine(act.Url.Name);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "GetValueFromField.pdf");
// Get a field
TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField;
// Get field value
Console.WriteLine("PartialName : {0} ", textBoxField.PartialName);
Console.WriteLine("Value : {0} ", textBoxField.Value);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "GetValuesFromAllFields.pdf");
// Get values from all fields
foreach (Field formField in pdfDocument.Form)
{
Console.WriteLine("Field Name : {0} ", formField.PartialName);
Console.WriteLine("Value : {0} ", formField.Value);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load XFA form
Document doc = new Document(dataDir + "GetXFAProperties.pdf");
string[] names = doc.Form.XFA.FieldNames;
// Set field values
doc.Form.XFA[names[0]] = "Field 0";
doc.Form.XFA[names[1]] = "Field 1";
// Get field position
Console.WriteLine(doc.Form.XFA.GetFieldTemplate(names[0]).Attributes["x"].Value);
// Get field position
Console.WriteLine(doc.Form.XFA.GetFieldTemplate(names[0]).Attributes["y"].Value);
dataDir = dataDir + "Filled_XFA_out.pdf";
// Save the updated document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Instantiate Document object
Document pdfDocument = new Document();
// Add a page to PDF file
Page page = pdfDocument.Pages.Add();
// Instatiate RadioButtonField object with page number as argument
RadioButtonField radio = new RadioButtonField(pdfDocument.Pages[1]);
// Add first radio button option and also specify its origin using Rectangle object
RadioButtonOptionField opt1 = new RadioButtonOptionField(page, new Aspose.Pdf.Rectangle(0, 0, 20, 20));
RadioButtonOptionField opt2 = new RadioButtonOptionField(page, new Aspose.Pdf.Rectangle(100, 0, 120, 20));
opt1.OptionName = "Test1";
opt2.OptionName = "Test2";
radio.Add(opt1);
radio.Add(opt2);
opt1.Style = BoxStyle.Square;
opt2.Style = BoxStyle.Square;
opt1.Style = BoxStyle.Cross;
opt2.Style = BoxStyle.Cross;
opt1.Border = new Border(opt1);
opt1.Border.Style = BorderStyle.Solid;
opt1.Border.Width = 1;
opt1.Characteristics.Border = System.Drawing.Color.Black;
opt2.Border = new Border(opt2);
opt2.Border.Width = 1;
opt2.Border.Style = BorderStyle.Solid;
opt2.Characteristics.Border = System.Drawing.Color.Black;
// Add radio button to form object of Document object
pdfDocument.Form.Add(radio);
dataDir = dataDir + "GroupedCheckBoxes_out.pdf";
// Save the PDF document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load the previously saved document
FormEditor formEditor = new FormEditor();
formEditor.BindPdf(dataDir + "input.pdf");
// RadioGap is distance between two radio button options.
formEditor.RadioGap = 4;
// Add horizontal radio button
formEditor.RadioHoriz = true;
// RadioButtonItemSize if size of radio button item.
formEditor.RadioButtonItemSize = 20;
formEditor.Facade.BorderWidth = 1;
formEditor.Facade.BorderColor = System.Drawing.Color.Black;
formEditor.Items = new string[] { "First", "Second", "Third" };
formEditor.AddField(FieldType.Radio, "NewField1", 1, 40, 600, 120, 620);
// Add other radio button situated vertically
formEditor.RadioHoriz = false;
formEditor.Items = new string[] { "First", "Second", "Third" };
formEditor.AddField(FieldType.Radio, "NewField2", 1, 40, 500, 60, 550);
dataDir = dataDir + "HorizontallyAndVerticallyRadioButtons_out.pdf";
// Save the PDF document
formEditor.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "ModifyFormField.pdf");
// Get a field
TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField;
// Modify field value
textBoxField.Value = "New Value";
textBoxField.ReadOnly = true;
dataDir = dataDir + "ModifyFormField_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "MoveFormField.pdf");
// Get a field
TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField;
// Modify field location
textBoxField.Rect = new Aspose.Pdf.Rectangle(300, 400, 600, 500);
dataDir = dataDir + "MoveFormField_out.pdf";
// Save modified document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Read the source PDF form with FileAccess of Read and Write.
// We need ReadWrite permission because after modification,
// We need to save the updated contents in same document/file.
FileStream fs = new FileStream(dataDir + "input.pdf", FileMode.Open, FileAccess.ReadWrite);
// Instantiate Document instance
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(fs);
// Get values from all fields
foreach (Field formField in pdfDocument.Form)
{
// If the fullname of field contains A1, perform the operation
if (formField.FullName.Contains("A1"))
{
// Cast form field as TextBox
TextBoxField textBoxField = formField as TextBoxField;
// Modify field value
textBoxField.Value = "Testing";
}
}
// Save the updated document in save FileStream
pdfDocument.Save();
// Close the File Stream object
fs.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Input and output file paths are equal, this forces incremental update when form saved.
Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(dataDir + "input.pdf");
// Fill value in form field
form.FillField("topmostSubform[0].Page1[0].f1_29_0_[0]", "Nayyer");
// Save updated document
form.Save(dataDir + "PreserveRightsUsingFormClass_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Instantiate Document object
Document pdfDocument = new Document();
// Add a page to PDF file
pdfDocument.Pages.Add();
// Instatiate RadioButtonField object with page number as argument
RadioButtonField radio = new RadioButtonField(pdfDocument.Pages[1]);
// Add first radio button option and also specify its origin using Rectangle object
radio.AddOption("Test", new Rectangle(0, 0, 20, 20));
// Add second radio button option
radio.AddOption("Test1", new Rectangle(20, 20, 40, 40));
// Add radio button to form object of Document object
pdfDocument.Form.Add(radio);
dataDir = dataDir + "RadioButton_out.pdf";
// Save the PDF file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
Document doc = new Document();
Page page = doc.Pages.Add();
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.ColumnWidths = "120 120 120";
page.Paragraphs.Add(table);
Row r1 = table.Rows.Add();
Cell c1 = r1.Cells.Add();
Cell c2 = r1.Cells.Add();
Cell c3 = r1.Cells.Add();
RadioButtonField rf = new RadioButtonField(page);
rf.PartialName = "radio";
doc.Form.Add(rf, 1);
RadioButtonOptionField opt1 = new RadioButtonOptionField();
RadioButtonOptionField opt2 = new RadioButtonOptionField();
RadioButtonOptionField opt3 = new RadioButtonOptionField();
opt1.OptionName = "Item1";
opt2.OptionName = "Item2";
opt3.OptionName = "Item3";
opt1.Width = 15;
opt1.Height = 15;
opt2.Width = 15;
opt2.Height = 15;
opt3.Width = 15;
opt3.Height = 15;
rf.Add(opt1);
rf.Add(opt2);
rf.Add(opt3);
opt1.Border = new Border(opt1);
opt1.Border.Width = 1;
opt1.Border.Style = BorderStyle.Solid;
opt1.Characteristics.Border = System.Drawing.Color.Black;
opt1.DefaultAppearance.TextColor = System.Drawing.Color.Red;
opt1.Caption = new TextFragment("Item1");
opt2.Border = new Border(opt1);
opt2.Border.Width = 1;
opt2.Border.Style = BorderStyle.Solid;
opt2.Characteristics.Border = System.Drawing.Color.Black;
opt2.DefaultAppearance.TextColor = System.Drawing.Color.Red;
opt2.Caption = new TextFragment("Item2");
opt3.Border = new Border(opt1);
opt3.Border.Width = 1;
opt3.Border.Style = BorderStyle.Solid;
opt3.Characteristics.Border = System.Drawing.Color.Black;
opt3.DefaultAppearance.TextColor = System.Drawing.Color.Red;
opt3.Caption = new TextFragment("Item3");
c1.Paragraphs.Add(opt1);
c2.Paragraphs.Add(opt2);
c3.Paragraphs.Add(opt3);
dataDir = dataDir + "RadioButtonWithOptions_out.pdf";
// Save the PDF file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "RadioButton.pdf");
// Get a field
RadioButtonField radioField = pdfDocument.Form["radio"] as RadioButtonField;
// Specify the index of radio button from group
radioField.Selected = 2;
dataDir = dataDir + "SelectRadioButton_out.pdf";
// Save the PDF file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Getting maximum field limit using DOM
Document doc = new Document(dataDir + "FieldLimit.pdf");
Console.WriteLine("Limit: " + (doc.Form["textbox1"] as TextBoxField).MaxLen);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Getting maximum field limit using Facades
Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form();
form.BindPdf(dataDir + "FieldLimit.pdf");
Console.WriteLine("Limit: " + form.GetFieldLimit("textbox1"));
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Adding Field with limit
FormEditor form = new FormEditor();
form.BindPdf( dataDir + "input.pdf");
form.SetFieldLimit("textbox1", 15);
dataDir = dataDir + "SetFieldLimit_out.pdf";
form.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load input PDF file
Document doc = new Document(dataDir + "SetJavaScript.pdf");
TextBoxField field = (TextBoxField)doc.Form["textbox1"];
// 2 digits after point
// No separator
// Neg style = minus
// No currency
field.Actions.OnModifyCharacter = new JavascriptAction("AFNumber_Keystroke(2, 1, 1, 0, \"\", true)");
field.Actions.OnFormat = new JavascriptAction("AFNumber_Format(2, 1, 1, 0, \"\", true)");
// Set initial field value
field.Value = "123";
dataDir = dataDir + "Restricted_out.pdf";
// Save resultant PDF
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Load source PDF form
Aspose.Pdf.Facades.Form form1 = new Aspose.Pdf.Facades.Form(dataDir + "RadioButtonField.pdf");
Document PDF_Template_PDF_HTML = new Document(dataDir + "RadioButtonField.pdf");
foreach (var item in form1.FieldNames)
{
Console.WriteLine(item.ToString());
Dictionary<string, string> radioOptions = form1.GetButtonOptionValues(item);
if (item.Contains("radio1"))
{
Aspose.Pdf.Forms.RadioButtonField field0 = PDF_Template_PDF_HTML.Form[item] as Aspose.Pdf.Forms.RadioButtonField;
Aspose.Pdf.Forms.RadioButtonOptionField fieldoption = new Aspose.Pdf.Forms.RadioButtonOptionField();
fieldoption.OptionName = "Yes";
fieldoption.PartialName = "Yesname";
var updatedFragment = new Aspose.Pdf.Text.TextFragment("test123");
updatedFragment.TextState.Font = FontRepository.FindFont("Arial");
updatedFragment.TextState.FontSize = 10;
updatedFragment.TextState.LineSpacing = 6.32f;
// Create TextParagraph object
TextParagraph par = new TextParagraph();
// Set paragraph position
par.Position = new Position(field0.Rect.LLX, field0.Rect.LLY + updatedFragment.TextState.FontSize);
// Specify word wraping mode
par.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
// Add new TextFragment to paragraph
par.AppendLine(updatedFragment);
// Add the TextParagraph using TextBuilder
TextBuilder textBuilder = new TextBuilder(PDF_Template_PDF_HTML.Pages[1]);
textBuilder.AppendParagraph(par);
field0.DeleteOption("item1");
}
}
PDF_Template_PDF_HTML.Save(dataDir + "RadioButtonField_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();
// Open document
Document pdfDocument = new Document(dataDir + "TextField.pdf");
// Create a field
TextBoxField textBoxField = new TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 200, 300, 300));
textBoxField.PartialName = "textbox1";
textBoxField.Value = "Text Box";
// TextBoxField.Border = new Border(
Border border = new Border(textBoxField);
border.Width = 5;
border.Dash = new Dash(1, 1);
textBoxField.Border = border;
textBoxField.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green);
// Add field to the document
pdfDocument.Form.Add(textBoxField, 1);
dataDir = dataDir + "TextBox_out.pdf";
// Save modified PDF
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Graphs();
int alpha = 10;
int green = 0;
int red = 100;
int blue = 0;
// Create Color object using Alpha RGB
Aspose.Pdf.Color alphaColor = Aspose.Pdf.Color.FromArgb(alpha, red, green, blue); // Provide alpha channel
// Instantiate Document object
Document document = new Document();
// Add page to pages collection of PDF file
Page page = document.Pages.Add();
// Create Graph object with certain dimensions
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(300, 400);
// Set border for Drawing object
graph.Border = (new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Black));
// Add graph object to paragraphs collection of Page instance
page.Paragraphs.Add(graph);
// Create Rectangle object with certain dimensions
Aspose.Pdf.Drawing.Rectangle rectangle = new Aspose.Pdf.Drawing.Rectangle(0, 0, 100, 50);
// Create graphInfo object for Rectangle instance
Aspose.Pdf.GraphInfo graphInfo = rectangle.GraphInfo;
// Set color information for GraphInfo instance
graphInfo.Color = (Aspose.Pdf.Color.Red);
// Set fill color for GraphInfo
graphInfo.FillColor = (alphaColor);
// Add rectangle shape to shapes collection of graph object
graph.Shapes.Add(rectangle);
dataDir = dataDir + "AddDrawing_out.pdf";
// Save PDF file
document.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Graphs();
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.Pages.Add();
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(100, 400);
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph);
// Create Rectangle instance
Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[] { 100, 100, 200, 100 });
// Specify fill color for Graph object
line.GraphInfo.DashArray = new int[] { 0, 1, 0 };
line.GraphInfo.DashPhase = 1;
// Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(line);
dataDir = dataDir + "AddLineObject_out.pdf";
// Save PDF file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddRectangle(Aspose.Pdf.Page page, float x, float y, float width, float height, Aspose.Pdf.Color color, int zindex)
{
// Create graph object with dimensions same as specified for Rectangle object
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(width, height);
// Can we change the position of graph instance
graph.IsChangePosition = false;
// Set Left coordinate position for Graph instance
graph.Left = x;
// Set Top coordinate position for Graph object
graph.Top = y;
// Add a rectangle inside the "graph"
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(0, 0, width, height);
// Set rectangle fill color
rect.GraphInfo.FillColor = color;
// Color of graph object
rect.GraphInfo.Color = color;
// Add rectangle to shapes collection of graph instance
graph.Shapes.Add(rect);
// Set Z-Index for rectangle object
graph.ZIndex = zindex;
// Add graph to paragraphs collection of page object
page.Paragraphs.Add(graph);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Graphs();
// Instantiate Document class object
Document doc1 = new Document();
/// Add page to pages collection of PDF file
Aspose.Pdf.Page page1 = doc1.Pages.Add();
// Set size of PDF page
page1.SetPageSize(375, 300);
// Set left margin for page object as 0
page1.PageInfo.Margin.Left = 0;
// Set top margin of page object as 0
page1.PageInfo.Margin.Top = 0;
// Create a new rectangle with Color as Red, Z-Order as 0 and certain dimensions
AddRectangle(page1, 50, 40, 60, 40, Aspose.Pdf.Color.Red, 2);
// Create a new rectangle with Color as Blue, Z-Order as 0 and certain dimensions
AddRectangle(page1, 20, 20, 30, 30, Aspose.Pdf.Color.Blue, 1);
// Create a new rectangle with Color as Green, Z-Order as 0 and certain dimensions
AddRectangle(page1, 40, 40, 60, 30, Aspose.Pdf.Color.Green, 0);
dataDir = dataDir + "ControlRectangleZOrder_out.pdf";
// Save resultant PDF file
doc1.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Graphs();
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.Pages.Add();
// Create Graph instance
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph(100, 400);
// Add graph object to paragraphs collection of page instance
page.Paragraphs.Add(graph);
// Create Rectangle instance
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 200, 120);
// Specify fill color for Graph object
rect.GraphInfo.FillColor = Aspose.Pdf.Color.Red;
// Add rectangle object to shapes collection of Graph object
graph.Shapes.Add(rect);
dataDir = dataDir + "CreateFilledRectangle_out.pdf";
// Save PDF file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Graphs();
// Instantiate Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Aspose.Pdf.Page page = doc.Pages.Add();
// Create Graph instance
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
// Create rectangle object with specific dimensions
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 200, 100);
// Set graph fill color from System.Drawing.Color structure from a 32-bit ARGB value
rect.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(12957183)));
// Add rectangle object to shapes collection of Graph instance
canvas.Shapes.Add(rect);
// Create second rectangle object
Aspose.Pdf.Drawing.Rectangle rect1 = new Aspose.Pdf.Drawing.Rectangle(200, 150, 200, 100);
rect1.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(16118015)));
canvas.Shapes.Add(rect1);
// Add graph instance to paragraph collection of page object
page.Paragraphs.Add(canvas);
dataDir = dataDir + "CreateRectangleWithAlphaColor_out.pdf";
// Save PDF file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Graphs();
// Instantiate Document instance
Document doc = new Document();
// Add page to pages collection of Document object
Page page = doc.Pages.Add();
// Create Drawing object with certain dimensions
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
// Add drawing object to paragraphs collection of page instance
page.Paragraphs.Add(canvas);
// Create Line object
Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[] { 100, 100, 200, 100 });
// Set color for Line object
line.GraphInfo.Color = Aspose.Pdf.Color.Red;
// Specify dash array for line object
line.GraphInfo.DashArray = new int[] { 0, 1, 0 };
// Set the dash phase for Line instance
line.GraphInfo.DashPhase = 1;
// Add line to shapes collection of drawing object
canvas.Shapes.Add(line);
dataDir = dataDir + "DashLength_out.pdf";
// Save PDF document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Graphs();
// Create Document instance
Document pDoc = new Document();
// Add page to pages collection of PDF document
Page pg = pDoc.Pages.Add();
// Set page margin on all sides as 0
pg.PageInfo.Margin.Left = pg.PageInfo.Margin.Right = pg.PageInfo.Margin.Bottom = pg.PageInfo.Margin.Top = 0;
// Create Graph object with Width and Height equal to page dimensions
Aspose.Pdf.Drawing.Graph graph = new Aspose.Pdf.Drawing.Graph((float)pg.PageInfo.Width , (float)pg.PageInfo.Height);
// Create first line object starting from Lower-Left to Top-Right corner of page
Aspose.Pdf.Drawing.Line line = new Aspose.Pdf.Drawing.Line(new float[] { (float)pg.Rect.LLX, 0, (float)pg.PageInfo.Width, (float)pg.Rect.URY });
// Add line to shapes collection of Graph object
graph.Shapes.Add(line);
// Draw line from Top-Left corner of page to Bottom-Right corner of page
Aspose.Pdf.Drawing.Line line2 = new Aspose.Pdf.Drawing.Line(new float[] { 0, (float)pg.Rect.URY, (float)pg.PageInfo.Width, (float)pg.Rect.LLX });
// Add line to shapes collection of Graph object
graph.Shapes.Add(line2);
// Add Graph object to paragraphs collection of page
pg.Paragraphs.Add(graph);
dataDir = dataDir + "DrawingLine_out.pdf";
// Save PDF file
pDoc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Headings();
Document pdfDoc = new Document();
pdfDoc.PageInfo.Width = 612.0;
pdfDoc.PageInfo.Height = 792.0;
pdfDoc.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
pdfDoc.PageInfo.Margin.Left = 72;
pdfDoc.PageInfo.Margin.Right = 72;
pdfDoc.PageInfo.Margin.Top = 72;
pdfDoc.PageInfo.Margin.Bottom = 72;
Aspose.Pdf.Page pdfPage = pdfDoc.Pages.Add();
pdfPage.PageInfo.Width = 612.0;
pdfPage.PageInfo.Height = 792.0;
pdfPage.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
pdfPage.PageInfo.Margin.Left = 72;
pdfPage.PageInfo.Margin.Right = 72;
pdfPage.PageInfo.Margin.Top = 72;
pdfPage.PageInfo.Margin.Bottom = 72;
Aspose.Pdf.FloatingBox floatBox = new Aspose.Pdf.FloatingBox();
floatBox.Margin = pdfPage.PageInfo.Margin;
pdfPage.Paragraphs.Add(floatBox);
TextFragment textFragment = new TextFragment();
TextSegment segment = new TextSegment();
Aspose.Pdf.Heading heading = new Aspose.Pdf.Heading(1);
heading.IsInList = true;
heading.StartNumber = 1;
heading.Text = "List 1";
heading.Style = NumberingStyle.NumeralsRomanLowercase;
heading.IsAutoSequence = true;
floatBox.Paragraphs.Add(heading);
Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);
heading2.IsInList = true;
heading2.StartNumber = 13;
heading2.Text = "List 2";
heading2.Style = NumberingStyle.NumeralsRomanLowercase;
heading2.IsAutoSequence = true;
floatBox.Paragraphs.Add(heading2);
Aspose.Pdf.Heading heading3 = new Aspose.Pdf.Heading(2);
heading3.IsInList = true;
heading3.StartNumber = 1;
heading3.Text = "the value, as of the effective date of the plan, of property to be distributed under the plan onaccount of each allowed";
heading3.Style = NumberingStyle.LettersLowercase;
heading3.IsAutoSequence = true;
floatBox.Paragraphs.Add(heading3);
dataDir = dataDir + "ApplyNumberStyle_out.pdf";
pdfDoc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "AddImage.pdf");
// Set coordinates
int lowerLeftX = 100;
int lowerLeftY = 100;
int upperRightX = 200;
int upperRightY = 200;
// Get the page where image needs to be added
Page page = pdfDocument.Pages[1];
// Load image into stream
FileStream imageStream = new FileStream(dataDir + "aspose-logo.jpg", 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 });
// 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());
dataDir = dataDir + "AddImage_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "PageToTIFF.pdf");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.None;
tiffSettings.Depth = ColorDepth.Default;
tiffSettings.Shape = ShapeType.Landscape;
tiffSettings.SkipBlankPages = false;
// Create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
// Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, dataDir + "AllPagesToTIFF_out.tif");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "PageToTIFF.pdf");
string outputImageFile = dataDir + "resultant_out.tif";
string outputBinImageFile = dataDir + "37116-bin_out.tif";
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.LZW;
tiffSettings.Depth = Aspose.Pdf.Devices.ColorDepth.Format1bpp;
// Create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
// Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, outputImageFile);
using (FileStream inStream = new FileStream(outputImageFile, FileMode.Open))
{
using (FileStream outStream = new FileStream(outputBinImageFile, FileMode.Create))
{
tiffDevice.BinarizeBradley(inStream, outStream, 0.1);
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
string inputFile = dataDir + "corvette.cgm";
dataDir = dataDir + "CGMImageToPDF_out.pdf";
// Save CGM into PDF format
PdfProducer.Produce(inputFile, ImportFormat.Cgm, dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "ConvertAllPagesToEMF.pdf");
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + "_out" + ".emf", FileMode.Create))
{
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create PNG device with specified attributes
// Width, Height, Resolution
EmfDevice emfDevice = new EmfDevice(500, 700, resolution);
// Convert a particular page and save the image to stream
emfDevice.Process(pdfDocument.Pages[pageCount], imageStream);
// Close stream
imageStream.Close();
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir + "ConvertAllPagesToPNG.pdf");
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + "_out" + ".png", FileMode.Create))
{
// Create PNG device with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.Process(pdfDocument.Pages[pageCount], imageStream);
// Close stream
imageStream.Close();
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Instantiate Document instance by calling its empty constructor
Aspose.Pdf.Document pdf1 = new Aspose.Pdf.Document();
// Add a Page into the pdf document
Aspose.Pdf.Page sec = pdf1.Pages.Add();
// Create a FileStream object to read the imag file
FileStream fs = File.OpenRead(dataDir + "aspose.jpg");
// Read the image into Byte array
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
// Create a MemoryStream object from image Byte array
MemoryStream ms = new MemoryStream(data);
// Create an image object
Aspose.Pdf.Image imageht = new Aspose.Pdf.Image();
// Specify the image source as MemoryStream
imageht.ImageStream = ms;
// Add image object into the Paragraphs collection of the section
sec.Paragraphs.Add(imageht);
// Save the Pdf
pdf1.Save(dataDir + "ConvertMemoryStreamImageToPdf_out.pdf");
// Close the MemoryStream Object
ms.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document document = new Document( dataDir + "AddImage.pdf");
// Get rectangle of particular page region
Aspose.Pdf.Rectangle pageRect = new Aspose.Pdf.Rectangle(20, 671, 693, 1125);
// Set CropBox value as per rectangle of desired page region
document.Pages[1].CropBox = pageRect;
// Save cropped document into stream
MemoryStream ms = new MemoryStream();
document.Save(ms);
// Open cropped PDF document and convert to image
document = new Document(ms);
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create PNG device with specified attributes
PngDevice pngDevice = new PngDevice(resolution);
dataDir = dataDir + "ConvertPageRegionToDOM_out.png";
// Convert a particular page and save the image to stream
pngDevice.Process(document.Pages[1], dataDir);
ms.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir + "AddImage.pdf");
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream("image" + pageCount + "_out" + ".bmp", FileMode.Create))
{
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create BMP device with specified attributes
// Width, Height, Resolution, PageSize
BmpDevice bmpDevice = new BmpDevice(resolution);
// Convert a particular page and save the image to stream
bmpDevice.Process(pdfDocument.Pages[pageCount], imageStream);
// Close stream
imageStream.Close();
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "DeleteImages.pdf");
// Delete a particular image
pdfDocument.Pages[1].Resources.Images.Delete(1);
dataDir = dataDir + "DeleteImages_out.pdf";
// Save updated PDF file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "ExtractImages.pdf");
// Extract a particular image
XImage xImage = pdfDocument.Pages[1].Resources.Images[1];
FileStream outputImage = new FileStream(dataDir + "output.jpg", FileMode.Create);
// Save output image
xImage.Save(outputImage, ImageFormat.Jpeg);
outputImage.Close();
dataDir = dataDir + "ExtractImages_out.pdf";
// Save updated PDF file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Counter for grayscale images
int grayscaled = 0;
// Counter for RGB images
int rgd = 0;
using (Document document = new Document(dataDir + "ExtractImages.pdf"))
{
foreach (Page page in document.Pages)
{
Console.WriteLine("--------------------------------");
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();
page.Accept(abs);
// Get the count of images over specific page
Console.WriteLine("Total Images = {0} over page number {1}", abs.ImagePlacements.Count, page.Number);
// Document.Pages[29].Accept(abs);
int image_counter = 1;
foreach (ImagePlacement ia in abs.ImagePlacements)
{
ColorType colorType = ia.Image.GetColorType();
switch (colorType)
{
case ColorType.Grayscale:
++grayscaled;
Console.WriteLine("Image {0} is GrayScale...", image_counter);
break;
case ColorType.Rgb:
++rgd;
Console.WriteLine("Image {0} is RGB...", image_counter);
break;
}
image_counter += 1;
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Load the source PDF file
Document doc = new Document(dataDir+ "ImageInformation.pdf");
// Define the default resolution for image
int defaultResolution = 72;
System.Collections.Stack graphicsState = new System.Collections.Stack();
// Define array list object which will hold image names
System.Collections.ArrayList imageNames = new System.Collections.ArrayList(doc.Pages[1].Resources.Images.Names);
// Insert an object to stack
graphicsState.Push(new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0));
// Get all the operators on first page of document
foreach (Operator op in doc.Pages[1].Contents)
{
// Use GSave/GRestore operators to revert the transformations back to previously set
Aspose.Pdf.Operators.GSave opSaveState = op as Aspose.Pdf.Operators.GSave;
Aspose.Pdf.Operators.GRestore opRestoreState = op as Aspose.Pdf.Operators.GRestore;
// Instantiate ConcatenateMatrix object as it defines current transformation matrix.
Aspose.Pdf.Operators.ConcatenateMatrix opCtm = op as Aspose.Pdf.Operators.ConcatenateMatrix;
// Create Do operator which draws objects from resources. It draws Form objects and Image objects
Aspose.Pdf.Operators.Do opDo = op as Aspose.Pdf.Operators.Do;
if (opSaveState != null)
{
// Save previous state and push current state to the top of the stack
graphicsState.Push(((System.Drawing.Drawing2D.Matrix)graphicsState.Peek()).Clone());
}
else if (opRestoreState != null)
{
// Throw away current state and restore previous one
graphicsState.Pop();
}
else if (opCtm != null)
{
System.Drawing.Drawing2D.Matrix cm = new System.Drawing.Drawing2D.Matrix(
(float)opCtm.Matrix.A,
(float)opCtm.Matrix.B,
(float)opCtm.Matrix.C,
(float)opCtm.Matrix.D,
(float)opCtm.Matrix.E,
(float)opCtm.Matrix.F);
// Multiply current matrix with the state matrix
((System.Drawing.Drawing2D.Matrix)graphicsState.Peek()).Multiply(cm);
continue;
}
else if (opDo != null)
{
// In case this is an image drawing operator
if (imageNames.Contains(opDo.Name))
{
System.Drawing.Drawing2D.Matrix lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek();
// Create XImage object to hold images of first pdf page
XImage image = doc.Pages[1].Resources.Images[opDo.Name];
// Get image dimensions
double scaledWidth = Math.Sqrt(Math.Pow(lastCTM.Elements[0], 2) + Math.Pow(lastCTM.Elements[1], 2));
double scaledHeight = Math.Sqrt(Math.Pow(lastCTM.Elements[2], 2) + Math.Pow(lastCTM.Elements[3], 2));
// Get Height and Width information of image
double originalWidth = image.Width;
double originalHeight = image.Height;
// Compute resolution based on above information
double resHorizontal = originalWidth * defaultResolution / scaledWidth;
double resVertical = originalHeight * defaultResolution / scaledHeight;
// Display Dimension and Resolution information of each image
Console.Out.WriteLine(
string.Format(dataDir + "image {0} ({1:.##}:{2:.##}): res {3:.##} x {4:.##}",
opDo.Name, scaledWidth, scaledHeight, resHorizontal,
resVertical));
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
doc.Pages[1].Accept(abs);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Load the source PDF document
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir+ "ImagePlacement.pdf");
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();
// Load the contents of first page
doc.Pages[1].Accept(abs);
foreach (ImagePlacement imagePlacement in abs.ImagePlacements)
{
// Get image properties
Console.Out.WriteLine("image width:" + imagePlacement.Rectangle.Width);
Console.Out.WriteLine("image height:" + imagePlacement.Rectangle.Height);
Console.Out.WriteLine("image LLX:" + imagePlacement.Rectangle.LLX);
Console.Out.WriteLine("image LLY:" + imagePlacement.Rectangle.LLY);
Console.Out.WriteLine("image horizontal resolution:" + imagePlacement.Resolution.X);
Console.Out.WriteLine("image vertical resolution:" + imagePlacement.Resolution.Y);
// Retrieve image with visible dimensions
Bitmap scaledImage;
using (MemoryStream imageStream = new MemoryStream())
{
// Retrieve image from resources
imagePlacement.Image.Save(imageStream, System.Drawing.Imaging.ImageFormat.Png);
Bitmap resourceImage = (Bitmap)Bitmap.FromStream(imageStream);
// Create bitmap with actual dimensions
scaledImage = new Bitmap(resourceImage, (int)imagePlacement.Rectangle.Width, (int)imagePlacement.Rectangle.Height);
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Instantiate Document Object
Document doc = new Document();
// Add a page to pages collection of document
Page page = doc.Pages.Add();
// Load the source image file to Stream object
FileStream fs = new FileStream(dataDir + "aspose-logo.jpg", FileMode.Open, FileAccess.Read);
byte[] tmpBytes = new byte[fs.Length];
fs.Read(tmpBytes, 0, int.Parse(fs.Length.ToString()));
MemoryStream mystream = new MemoryStream(tmpBytes);
// Instantiate BitMap object with loaded image stream
Bitmap b = new Bitmap(mystream);
// Set margins so image will fit, etc.
page.PageInfo.Margin.Bottom = 0;
page.PageInfo.Margin.Top = 0;
page.PageInfo.Margin.Left = 0;
page.PageInfo.Margin.Right = 0;
page.CropBox = new Aspose.Pdf.Rectangle(0, 0, b.Width, b.Height);
// Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
// Add the image into paragraphs collection of the section
page.Paragraphs.Add(image1);
// Set the image file stream
image1.ImageStream = mystream;
dataDir = dataDir + "ImageToPDF_out.pdf";
// Save resultant PDF file
doc.Save(dataDir);
// Close memoryStream object
mystream.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
string inputFile = dataDir + "corvette.cgm";
dataDir = dataDir + "LargeCGMImageToPDF_out.pdf";
// Create an instance of CgmImportOptions
CgmImportOptions options = new CgmImportOptions();
// Specify the dimentions for page size import
options.PageSize = new SizeF(1000, 1000);
// Save CGM into PDF format
PdfProducer.Produce(inputFile, ImportFormat.Cgm, dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// Convert a particular page and save the image to stream
jpegDevice.Process(pdfDocument.Pages[1], imageStream);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir + "PagesToImages.pdf");
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
using (FileStream imageStream = new FileStream(dataDir + "image" + pageCount + "_out" + ".jpg", FileMode.Create))
{
// Create JPEG device with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(300);
// JpegDevice jpegDevice = new JpegDevice(500, 700, resolution, 100);
JpegDevice jpegDevice = new JpegDevice(resolution, 100);
// Convert a particular page and save the image to stream
jpegDevice.Process(pdfDocument.Pages[pageCount], imageStream);
// Close stream
imageStream.Close();
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "PageToEMF.pdf");
using (FileStream imageStream = new FileStream(dataDir + "image_out.emf", FileMode.Create))
{
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create EMF device with specified attributes
// Width, Height, Resolution
EmfDevice emfDevice = new EmfDevice(500, 700, resolution);
// Convert a particular page and save the image to stream
emfDevice.Process(pdfDocument.Pages[1], imageStream);
// Close stream
imageStream.Close();
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir + "PageToPNG.pdf");
using (FileStream imageStream = new FileStream(dataDir + "aspose-logo.png", FileMode.Create))
{
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create PNG device with specified attributes (Width, Height, Resolution)
PngDevice pngDevice = new PngDevice(resolution);
// Convert a particular page and save the image to stream
pngDevice.Process(pdfDocument.Pages[1], imageStream);
// Close stream
imageStream.Close();
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "PageToTIFF.pdf");
// Create Resolution object
Resolution resolution = new Resolution(300);
// Create TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
tiffSettings.Compression = CompressionType.None;
tiffSettings.Depth = ColorDepth.Default;
tiffSettings.Shape = ShapeType.Landscape;
tiffSettings.SkipBlankPages = false;
// Create TIFF device
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
// Convert a particular page and save the image to stream
tiffDevice.Process(pdfDocument, 1, 1, dataDir + "PageToTIFF_out.tif");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Document pdfDocument = new Document(dataDir+ "ReplaceImage.pdf");
// Replace a particular image
pdfDocument.Pages[1].Resources.Images.Replace(1, new FileStream(dataDir + "aspose-logo.jpg", FileMode.Open));
dataDir = dataDir + "ReplaceImage_out.pdf";
// Save updated PDF file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Images();
// Open document
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir+ "SearchAndGetImages.pdf");
// Create ImagePlacementAbsorber object to perform image placement search
ImagePlacementAbsorber abs = new ImagePlacementAbsorber();
// Accept the absorber for all the pages
doc.Pages.Accept(abs);
// Loop through all ImagePlacements, get image and ImagePlacement Properties
foreach (ImagePlacement imagePlacement in abs.ImagePlacements)
{
// Get the image using ImagePlacement object
XImage image = imagePlacement.Image;
// Display image placement properties for all placements
Console.Out.WriteLine("image width:" + imagePlacement.Rectangle.Width);
Console.Out.WriteLine("image height:" + imagePlacement.Rectangle.Height);
Console.Out.WriteLine("image LLX:" + imagePlacement.Rectangle.LLX);
Console.Out.WriteLine("image LLY:" + imagePlacement.Rectangle.LLY);
Console.Out.WriteLine("image horizontal resolution:" + imagePlacement.Resolution.X);
Console.Out.WriteLine("image vertical resolution:" + imagePlacement.Resolution.Y);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// Get version information
Console.WriteLine("Product : {0}", BuildVersionInfo.Product);
Console.WriteLine("File Version : {0}", BuildVersionInfo.FileVersion);
Console.WriteLine("Assembly Version : {0}", BuildVersionInfo.AssemblyVersion);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Miscellaneous();
Document doc = new Document(dataDir + "ReadMeasure.pdf");
Console.WriteLine((doc.Pages[1].Annotations[1] as LineAnnotation).Measure.ScaleRatio);
Console.WriteLine((doc.Pages[1].Annotations[1] as LineAnnotation).Measure.AreaFormat[1].UnitLabel);
Console.WriteLine((doc.Pages[1].Annotations[1] as LineAnnotation).Measure.AreaFormat[1].ConvresionFactor);
Console.WriteLine((doc.Pages[1].Annotations[1] as LineAnnotation).Measure.AreaFormat[1].FractionSeparator);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Miscellaneous();
Document doc = new Document( dataDir + "input.pdf");
Rectangle rect = new Rectangle(260, 630, 451, 662);
LineAnnotation line = new LineAnnotation(doc.Pages[1], rect, new Point(266, 657), new Point(446, 656));
line.Color = Color.Red;
// Set extension line parameters.
line.LeaderLine = -15;
line.LeaderLineExtension = 5;
// Set line endings
line.StartingStyle = LineEnding.OpenArrow;
line.EndingStyle = LineEnding.OpenArrow;
// Create Measure element
line.Measure = new Measure(line);
line.Measure.DistanceFormat = new Measure.NumberFormatList(line.Measure);
line.Measure.DistanceFormat.Add(new Measure.NumberFormat(line.Measure));
line.Measure.DistanceFormat[1].UnitLabel = "mm";
line.Measure.DistanceFormat[1].FractionSeparator = ".";
line.Measure.DistanceFormat[1].ConvresionFactor = 1;
// Text of measure line
line.Contents = "155 mm";
// This must be set to show the text.
line.ShowCaption = true;
line.CaptionPosition = CaptionPosition.Top;
doc.Pages[1].Annotations.Add(line);
doc.Save(dataDir + "UseMeasureWithLineAnnotation_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Miscellaneous();
Document doc = new Document( dataDir + "input.pdf");
Point[] vertices = new Point[]
{
new Point(100, 600),
new Point(500, 600),
new Point(500, 500),
new Point(400, 300),
new Point(100, 500),
new Point(100, 600)
};
Rectangle rect = new Rectangle(100, 500, 500, 600);
// Area or perimeter line
PolylineAnnotation area = new PolylineAnnotation(doc.Pages[1], rect, vertices);
area.Color = Color.Red;
// Line endings can be set for perimeter line.
area.StartingStyle = LineEnding.OpenArrow;
area.EndingStyle = LineEnding.OpenArrow;
area.Measure = new Measure(area);
area.Measure.DistanceFormat = new Measure.NumberFormatList(area.Measure);
area.Measure.DistanceFormat.Add(new Measure.NumberFormat(area.Measure));
area.Measure.DistanceFormat[1].UnitLabel = "mm";
doc.Pages[1].Annotations.Add(area);
doc.Save( dataDir + "UseMeasureWithPolylineAnnotation_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Operators();
string imageFile = dataDir+ "aspose-logo.jpg";
string inFile = dataDir + "DrawXFormOnPage.pdf";
string outFile = dataDir + "blank-sample2_out.pdf";
using (Document doc = new Document(inFile))
{
OperatorCollection pageContents = doc.Pages[1].Contents;
// The sample demonstrates
// GSave/GRestore operators usage
// ContatenateMatrix operator usage to position xForm
// Do operator usage to draw xForm on page
// Wrap existing contents with GSave/GRestore operators pair
// this is to get initial graphics state at the and of existing contents
// otherwise there might remain some undesirable transformations at the end of existing operators chain
pageContents.Insert(1, new Aspose.Pdf.Operators.GSave());
pageContents.Add(new Aspose.Pdf.Operators.GRestore());
// Add save graphics state operator to properly clear graphics state after new commands
pageContents.Add(new Aspose.Pdf.Operators.GSave());
#region create xForm
// Create xForm
XForm form = XForm.CreateNewForm(doc.Pages[1], doc);
doc.Pages[1].Resources.Forms.Add(form);
form.Contents.Add(new Aspose.Pdf.Operators.GSave());
// Define image width and heigh
form.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(200, 0, 0, 200, 0, 0));
// Load image into stream
Stream imageStream = new FileStream(imageFile, FileMode.Open);
// Add image to Images collection of the XForm Resources
form.Resources.Images.Add(imageStream);
XImage ximage = form.Resources.Images[form.Resources.Images.Count];
// Using Do operator: this operator draws image
form.Contents.Add(new Aspose.Pdf.Operators.Do(ximage.Name));
form.Contents.Add(new Aspose.Pdf.Operators.GRestore());
#endregion
pageContents.Add(new Aspose.Pdf.Operators.GSave());
// Place form to the x=100 y=500 coordinates
pageContents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(1, 0, 0, 1, 100, 500));
// Draw form with Do operator
pageContents.Add(new Aspose.Pdf.Operators.Do(form.Name));
pageContents.Add(new Aspose.Pdf.Operators.GRestore());
pageContents.Add(new Aspose.Pdf.Operators.GSave());
// Place form to the x=100 y=300 coordinates
pageContents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(1, 0, 0, 1, 100, 300));
// Draw form with Do operator
pageContents.Add(new Aspose.Pdf.Operators.Do(form.Name));
pageContents.Add(new Aspose.Pdf.Operators.GRestore());
// Restore grahics state with GRestore after the GSave
pageContents.Add(new Aspose.Pdf.Operators.GRestore());
doc.Save(outFile);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Operators();
// Open document
Document pdfDocument = new Document(dataDir+ "PDFOperators.pdf");
// Set coordinates
int lowerLeftX = 100;
int lowerLeftY = 100;
int upperRightX = 200;
int upperRightY = 200;
// Get the page where image needs to be added
Page page = pdfDocument.Pages[1];
// Load image into stream
FileStream imageStream = new FileStream(dataDir + "PDFOperators.jpg", 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 });
// 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());
dataDir = dataDir + "PDFOperators_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Operators();
Document doc = new Document(dataDir+ "RemoveGraphicsObjects.pdf");
Page page = doc.Pages[2];
OperatorCollection oc = page.Contents;
// Used path-painting operators
Operator[] operators = new Operator[] {
new Aspose.Pdf.Operators.Stroke(),
new Aspose.Pdf.Operators.ClosePathStroke(),
new Aspose.Pdf.Operators.Fill()
};
oc.Delete(operators);
doc.Save(dataDir+ "No_Graphics_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
Document doc = new Document(dataDir + "input.pdf");
foreach (Page page in doc.Pages)
{
Aspose.Pdf.Rectangle r = page.MediaBox;
double newHeight = r.Width;
double newWidth = r.Height;
double newLLX = r.LLX;
// We must to move page upper in order to compensate changing page size
// (lower edge of the page is 0,0 and information is usually placed from the
// Top of the page. That's why we move lover edge upper on difference between
// Old and new height.
double newLLY = r.LLY + (r.Height - newHeight);
page.MediaBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
// Sometimes we also need to set CropBox (if it was set in original file)
page.CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
// Setting Rotation angle of page
page.Rotate = Rotation.on90;
}
dataDir = dataDir + "ChangeOrientation_out.pdf";
// Save output file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open first document
Document pdfDocument1 = new Document(dataDir + "Concat1.pdf");
// Open second document
Document pdfDocument2 = new Document(dataDir + "Concat2.pdf");
// Add pages of second document to the first
pdfDocument1.Pages.Add(pdfDocument2.Pages);
dataDir = dataDir + "ConcatenatePdfFiles_out.pdf";
// Save concatenated output file
pdfDocument1.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument = new Document(dataDir + "DeleteParticularPage.pdf");
// Delete a particular page
pdfDocument.Pages.Delete(2);
dataDir = dataDir + "DeleteParticularPage_out.pdf";
// Save updated PDF
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open source PDF file
Document pdfDocument = new Document( dataDir + "input.pdf");
// Iterate through all the page of PDF file
for (int pageCount = 1; pageCount <= pdfDocument.Pages.Count; pageCount++)
{
// Get the color type information for particular PDF page
Aspose.Pdf.ColorType pageColorType = pdfDocument.Pages[pageCount].ColorType;
switch (pageColorType)
{
case ColorType.BlackAndWhite:
Console.WriteLine("Page # -" + pageCount + " is Black and white..");
break;
case ColorType.Grayscale:
Console.WriteLine("Page # -" + pageCount + " is Gray Scale...");
break;
case ColorType.Rgb:
Console.WriteLine("Page # -" + pageCount + " is RGB..", pageCount);
break;
case ColorType.Undefined:
Console.WriteLine("Page # -" + pageCount + " Color is undefined..");
break;
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
Document doc = new Document(dataDir + "input.pdf");
foreach (Page page in doc.Pages)
{
Rectangle r = page.MediaBox;
// New height the same
double newHeight = r.Height;
// New width is expanded proportionally to make orientation landscape
// (we assume that previous orientation is portrait)
double newWidth = r.Height * r.Height / r.Width;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument = new Document(dataDir + "UpdateDimensions.pdf");
// Adds a blank page to pdf document
Page page = pdfDocument.Pages.Count > 0 ? pdfDocument.Pages[1] : pdfDocument.Pages.Add();
// Get page height and width information
Console.WriteLine(page.GetPageRect(true).Width.ToString() + ":" + page.GetPageRect(true).Height);
// Rotate page at 90 degree angle
page.Rotate = Rotation.on90;
// Get page height and width information
Console.WriteLine(page.GetPageRect(true).Width.ToString() + ":" + page.GetPageRect(true).Height);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument = new Document(dataDir + "GetNumberofPages.pdf");
// Get page count
System.Console.WriteLine("Page Count : {0}", pdfDocument.Pages.Count);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// Instantiate Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page = doc.Pages.Add();
// Create loop instance
for (int i = 0; i < 300; i++)
// Add TextFragment to paragraphs collection of page object
page.Paragraphs.Add(new TextFragment("Pages count test"));
// Process the paragraphs in PDF file to get accurate page count
doc.ProcessParagraphs();
// Print number of pages in document
Console.WriteLine("Number of pages in document = " + doc.Pages.Count);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument = new Document(dataDir + "GetParticularPage.pdf");
// Get particular page
Page pdfPage = pdfDocument.Pages[2];
// Save the page as PDF file
Document newDocument = new Document();
newDocument.Pages.Add(pdfPage);
dataDir = dataDir + "GetParticularPage_out.pdf";
newDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument = new Document(dataDir + "GetProperties.pdf");
// Get page collection
PageCollection pageCollection = pdfDocument.Pages;
// Get particular page
Page pdfPage = pageCollection[1];
// Get page properties
System.Console.WriteLine("ArtBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.ArtBox.Height, pdfPage.ArtBox.Width, pdfPage.ArtBox.LLX, pdfPage.ArtBox.LLY, pdfPage.ArtBox.URX, pdfPage.ArtBox.URY);
System.Console.WriteLine("BleedBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.BleedBox.Height, pdfPage.BleedBox.Width, pdfPage.BleedBox.LLX, pdfPage.BleedBox.LLY, pdfPage.BleedBox.URX, pdfPage.BleedBox.URY);
System.Console.WriteLine("CropBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.CropBox.Height, pdfPage.CropBox.Width, pdfPage.CropBox.LLX, pdfPage.CropBox.LLY, pdfPage.CropBox.URX, pdfPage.CropBox.URY);
System.Console.WriteLine("MediaBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.MediaBox.Height, pdfPage.MediaBox.Width, pdfPage.MediaBox.LLX, pdfPage.MediaBox.LLY, pdfPage.MediaBox.URX, pdfPage.MediaBox.URY);
System.Console.WriteLine("TrimBox : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.TrimBox.Height, pdfPage.TrimBox.Width, pdfPage.TrimBox.LLX, pdfPage.TrimBox.LLY, pdfPage.TrimBox.URX, pdfPage.TrimBox.URY);
System.Console.WriteLine("Rect : Height={0},Width={1},LLX={2},LLY={3},URX={4},URY={5}", pdfPage.Rect.Height, pdfPage.Rect.Width, pdfPage.Rect.LLX, pdfPage.Rect.LLY, pdfPage.Rect.URX, pdfPage.Rect.URY);
System.Console.WriteLine("Page Number : {0}", pdfPage.Number);
System.Console.WriteLine("Rotate : {0}", pdfPage.Rotate);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Create a new Document object
Document doc = new Document();
// Add a new page to document object
Page page = doc.Pages.Add();
// Create Background Artifact object
BackgroundArtifact background = new BackgroundArtifact();
// Specify the image for backgroundartifact object
background.BackgroundImage = File.OpenRead(dataDir + "aspose-total-for-net.jpg");
// Add backgroundartifact to artifacts collection of page
page.Artifacts.Add(background);
dataDir = dataDir + "ImageAsBackground_out.pdf";
// Save the document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument1 = new Document(dataDir + "InsertEmptyPage.pdf");
// Insert a empty page in a PDF
pdfDocument1.Pages.Insert(2);
dataDir = dataDir + "InsertEmptyPage_out.pdf";
// Save output file
pdfDocument1.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument1 = new Document(dataDir + "InsertEmptyPageAtEnd.pdf");
// Insert an empty page at the end of a PDF file
pdfDocument1.Pages.Add();
dataDir = dataDir + "InsertEmptyPageAtEnd_out.pdf";
// Save output file
pdfDocument1.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument = new Document(dataDir + "SplitToPages.pdf");
int pageCount = 1;
// Loop through all the pages
foreach (Page pdfPage in pdfDocument.Pages)
{
Document newDocument = new Document();
newDocument.Pages.Add(pdfPage);
newDocument.Save(dataDir + "page_" + pageCount + "_out" + ".pdf");
pageCount++;
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Open document
Document pdfDocument = new Document(dataDir + "UpdateDimensions.pdf");
// Get page collection
PageCollection pageCollection = pdfDocument.Pages;
// Get particular page
Page pdfPage = pageCollection[1];
// Set the page size as A4 (11.7 x 8.3 in) and in Aspose.Pdf, 1 inch = 72 points
// So A4 dimensions in points will be (842.4, 597.6)
pdfPage.SetPageSize(597.6, 842.4);
dataDir = dataDir + "UpdateDimensions_out.pdf";
// Save the updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
// Load source PDF file
Document doc = new Document(dataDir + "input.pdf");
// Get rectangular region of first page of PDF
Aspose.Pdf.Rectangle rect = doc.Pages[1].Rect;
// Instantiate PdfPageEditor instance
PdfPageEditor ppe = new PdfPageEditor();
// Bind source PDF
ppe.BindPdf(dataDir + "input.pdf");
// Set zoom coefficient
ppe.Zoom = (float)(rect.Width / rect.Height);
// Update page size
ppe.PageSize = new Aspose.Pdf.PageSize((float)rect.Height, (float)rect.Width);
dataDir = dataDir + "ZoomToPageContents_out.pdf";
// Save output file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_QuickStart();
// set metered public and private keys
Aspose.Pdf.Metered metered = new Aspose.Pdf.Metered();
// Access the setMeteredKey property and pass public and private keys as parameters
metered.SetMeteredKey("*****", "*****");
// Load the document from disk.
Document doc = new Document(dataDir + "input.pdf");
//Get the page count of document
Console.WriteLine(doc.Pages.Count);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_QuickStart();
// Initialize document object
Document document = new Document();
// Add page
Page page = document.Pages.Add();
// Add text to new page
page.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello World!"));
// Save updated PDF
document.Save(dataDir + "HelloWorld_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_QuickStart();
// Initialize license object
Aspose.Pdf.License license = new Aspose.Pdf.License();
// Set license
license.SetLicense("Aspose.Pdf.lic");
Console.WriteLine("License set successfully.");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_QuickStart();
// Initialize license object
Aspose.Pdf.License license = new Aspose.Pdf.License();
// Load license in FileStream
FileStream myStream = new FileStream("Aspose.Pdf.lic", FileMode.Open);
// Set license
license.SetLicense(myStream);
Console.WriteLine("License set successfully.");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
using (Stream zip = new SecureLicense().GetType().Assembly.GetManifestResourceStream("Aspose.Total.lic.zip"))
{
using (ZipFile zf = ZipFile.Read(zip))
{
MemoryStream ms = new MemoryStream();
ZipEntry e = zf["Aspose.Total.lic"];
e.ExtractWithPassword(ms, "test");
ms.Position = 0;
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_QuickStart();
// Initialize license object
Aspose.Pdf.License license = new Aspose.Pdf.License();
// Set license
license.SetLicense("MergedAPI.Aspose.Total.lic");
// Set the value to indicate that license will be embedded in the application
license.Embedded = true;
Console.WriteLine("License set successfully.");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Open document
Document document = new Document(dataDir+ "ChangePassword.pdf", "owner");
// Change password
document.ChangePasswords("owner", "newuser", "newowner");
dataDir = dataDir + "ChangePassword_out.pdf";
// Save updated PDF
document.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Open document
Document document = new Document(dataDir+ "Decrypt.pdf", "password");
// Decrypt PDF
document.Decrypt();
dataDir = dataDir + "Decrypt_out.pdf";
// Save updated PDF
document.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Load source PDF file
PdfFileInfo info = new PdfFileInfo();
info.BindPdf(dataDir + "IsPasswordProtected.pdf");
// Determine if the source PDF is encrypted
Console.WriteLine("File is password protected " + info.IsEncrypted);
String[] passwords = new String[5] { "test", "test1", "test2", "test3", "sample" };
for (int passwordcount = 0; passwordcount < passwords.Length; passwordcount++)
{
try
{
Document doc = new Document(dataDir + "IsPasswordProtected.pdf", passwords[passwordcount]);
if (doc.Pages.Count > 0)
Console.WriteLine("Number of Page in document are = " + doc.Pages.Count);
}
catch (InvalidPasswordException)
{
Console.WriteLine("Password = " + passwords[passwordcount] + " is not correct");
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
string pbxFile = "";
string inFile = dataDir + @"DigitallySign.pdf";
string outFile = dataDir + @"DigitallySign_out.pdf";
using (Document document = new Document(inFile))
{
using (PdfFileSignature signature = new PdfFileSignature(document))
{
PKCS7 pkcs = new PKCS7(pbxFile, "WebSales"); // Use PKCS7/PKCS7Detached objects
DocMDPSignature docMdpSignature = new DocMDPSignature(pkcs, DocMDPAccessPermissions.FillingInForms);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
// Set signature appearance
signature.SignatureAppearance = dataDir + @"aspose-logo.jpg";
// Create any of the three signature types
signature.Certify(1, "Signature Reason", "Contact", "Location", true, rect, docMdpSignature);
// Save output PDF file
signature.Save(outFile);
}
}
using (Document document = new Document(outFile))
{
using (PdfFileSignature signature = new PdfFileSignature(document))
{
IList<string> sigNames = signature.GetSignNames();
if (sigNames.Count > 0) // Any signatures?
{
if (signature.VerifySigned(sigNames[0] as string)) // Verify first one
{
if (signature.IsCertified) // Certified?
{
if (signature.GetAccessPermissions() == DocMDPAccessPermissions.FillingInForms) // Get access permission
{
// Do something
}
}
}
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
string pfxFile = "";
using (Document document = new Document(dataDir + @"DigitallySign.pdf"))
{
using (PdfFileSignature signature = new PdfFileSignature(document))
{
PKCS7 pkcs = new PKCS7(pfxFile, "pfx_password");
TimestampSettings timestampSettings = new TimestampSettings("https:\\your_timestamp_settings", "user:password"); // User/Password can be omitted
pkcs.TimestampSettings = timestampSettings;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(100, 100, 200, 100);
// Create any of the three signature types
signature.Sign(1, "Signature Reason", "Contact", "Location", true, rect, pkcs);
// Save output PDF file
signature.Save(dataDir + "DigitallySignWithTimeStamp_out.pdf");
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Open document
Document document = new Document(dataDir+ "Encrypt.pdf");
// Encrypt PDF
document.Encrypt("user", "owner", 0, CryptoAlgorithm.RC4x128);
dataDir = dataDir + "Encrypt_out.pdf";
// Save updated PDF
document.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
string input = dataDir+ @"ExtractingImage.pdf";
using (Document pdfDocument = new Document(input))
{
foreach (Field field in pdfDocument.Form)
{
SignatureField sf = field as SignatureField;
if (sf != null)
{
string outFile = dataDir+ @"output_out.jpg";
using (Stream imageStream = sf.ExtractImage())
{
if (imageStream != null)
{
using (System.Drawing.Image image = Bitmap.FromStream(imageStream))
{
image.Save(outFile, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
}
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
string input = dataDir + "ExtractSignatureInfo.pdf";
using (Document pdfDocument = new Document(input))
{
foreach (Field field in pdfDocument.Form)
{
SignatureField sf = field as SignatureField;
if (sf != null)
{
Stream cerStream = sf.ExtractCertificate();
if (cerStream != null)
{
using (cerStream)
{
byte[] bytes = new byte[cerStream.Length];
using (FileStream fs = new FileStream(dataDir + @"input.cer", FileMode.CreateNew))
{
cerStream.Read(bytes, 0, bytes.Length);
fs.Write(bytes, 0, bytes.Length);
}
}
}
}
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Load the source PDF doucment
PdfFileInfo fileInfo = new PdfFileInfo(dataDir+ @"IsPasswordProtected.pdf");
// Determine that source PDF file is Encrypted with password
bool encrypted = fileInfo.IsEncrypted;
// MessageBox displays the current status related to PDf encryption
Console.WriteLine(encrypted.ToString());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_SecuritySignatures();
// Load a source PDF file
using (Document document = new Document(dataDir + "input.pdf"))
{
// Instantiate Document Privileges object
// Apply restrictions on all privileges
DocumentPrivilege documentPrivilege = DocumentPrivilege.ForbidAll;
// Only allow screen reading
documentPrivilege.AllowScreenReaders = true;
// Encrypt the file with User and Owner password.
// Need to set the password, so that once the user views the file with user password,
// Only screen reading option is enabled
document.Encrypt("user", "owner", documentPrivilege, CryptoAlgorithm.AESx128, false);
// Save updated document
document.Save(dataDir + "SetPrivileges_out.pdf");
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "AddTextStamp.pdf");
string annotationText = string.Empty;
annotationText = DateTime.Now.ToString("MM/dd/yy hh:mm:ss tt ");
// Create text stamp
TextStamp textStamp = new TextStamp(annotationText);
// Set properties of the stamp
textStamp.BottomMargin = 10;
textStamp.RightMargin = 20;
textStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;
textStamp.VerticalAlignment = VerticalAlignment.Bottom;
// Adding stamp on stamp collection
pdfDocument.Pages[1].AddStamp(textStamp);
DefaultAppearance default_appearance = new DefaultAppearance("Arial", 6, System.Drawing.Color.Black);
FreeTextAnnotation textAnnotation = new FreeTextAnnotation(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(0, 0, 0, 0), default_appearance);
textAnnotation.Name = "Stamp";
textAnnotation.Accept(new AnnotationSelector(textAnnotation));
textAnnotation.Contents = textStamp.Value;
// TextAnnotation.Open = true;
// TextAnnotation.Icon = Aspose.Pdf.InteractiveFeatures.Annotations.TextIcon.Key;
Border border = new Border(textAnnotation);
border.Width = 0;
border.Dash = new Dash(1, 1);
textAnnotation.Border = border;
textAnnotation.Rect = new Aspose.Pdf.Rectangle(0, 0, 0, 0);
pdfDocument.Pages[1].Annotations.Add(textAnnotation);
dataDir = dataDir + "AddDateTimeStamp_out.pdf";
// Save output document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "AddImageStamp.pdf");
// Create image stamp
ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");
imageStamp.Background = true;
imageStamp.XIndent = 100;
imageStamp.YIndent = 100;
imageStamp.Height = 300;
imageStamp.Width = 300;
imageStamp.Rotate = Rotation.on270;
imageStamp.Opacity = 0.5;
// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(imageStamp);
dataDir = dataDir + "AddImageStamp_out.pdf";
// Save output document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "AddImageStamp.pdf");
// Create image stamp
ImageStamp imageStamp = new ImageStamp(dataDir + "aspose-logo.jpg");
imageStamp.Quality = 10;
pdfDocument.Pages[1].AddStamp(imageStamp);
pdfDocument.Save(dataDir + "ControlImageQuality_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open source document
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir+ "AddingDifferentHeaders.pdf");
// Create three stamps
Aspose.Pdf.TextStamp stamp1 = new Aspose.Pdf.TextStamp("Header 1");
Aspose.Pdf.TextStamp stamp2 = new Aspose.Pdf.TextStamp("Header 2");
Aspose.Pdf.TextStamp stamp3 = new Aspose.Pdf.TextStamp("Header 3");
// Set stamp alignment (place stamp on page top, centered horiznotally)
stamp1.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
stamp1.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
// Specify the font style as Bold
stamp1.TextState.FontStyle = FontStyles.Bold;
// Set the text fore ground color information as red
stamp1.TextState.ForegroundColor = Color.Red;
// Specify the font size as 14
stamp1.TextState.FontSize = 14;
// Now we need to set the vertical alignment of 2nd stamp object as Top
stamp2.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
// Set Horizontal alignment information for stamp as Center aligned
stamp2.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
// Set the zooming factor for stamp object
stamp2.Zoom = 10;
// Set the formatting of 3rd stamp object
// Specify the Vertical alignment information for stamp object as TOP
stamp3.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
// Set the Horizontal alignment inforamtion for stamp object as Center aligned
stamp3.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
// Set the rotation angle for stamp object
stamp3.RotateAngle = 35;
// Set pink as background color for stamp
stamp3.TextState.BackgroundColor = Color.Pink;
// Change the font face information for stamp to Verdana
stamp3.TextState.Font = FontRepository.FindFont("Verdana");
// First stamp is added on first page;
doc.Pages[1].AddStamp(stamp1);
// Second stamp is added on second page;
doc.Pages[2].AddStamp(stamp2);
// Third stamp is added on third page.
doc.Pages[3].AddStamp(stamp3);
dataDir = dataDir + "multiheader_out.pdf";
// Save the updated document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "PDFPageStamp.pdf");
// Create page stamp
PdfPageStamp pageStamp = new PdfPageStamp(pdfDocument.Pages[1]);
pageStamp.Background = true;
pageStamp.XIndent = 100;
pageStamp.YIndent = 100;
pageStamp.Rotate = Rotation.on180;
// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(pageStamp);
dataDir = dataDir + "PDFPageStamp_out.pdf";
// Save output document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "AddTextStamp.pdf");
// Create text stamp
TextStamp textStamp = new TextStamp("Sample Stamp");
// Set whether stamp is background
textStamp.Background = true;
// Set origin
textStamp.XIndent = 100;
textStamp.YIndent = 100;
// Rotate stamp
textStamp.Rotate = Rotation.on90;
// Set text properties
textStamp.TextState.Font = FontRepository.FindFont("Arial");
textStamp.TextState.FontSize = 14.0F;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);
// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(textStamp);
dataDir = dataDir + "AddTextStamp_out.pdf";
// Save output document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document( dataDir + "watermark.pdf");
int count = 0;
foreach (Artifact artifact in pdfDocument.Pages[1].Artifacts)
{
// If artifact type is watermark, increate the counter
if (artifact.Subtype == Artifact.ArtifactSubtype.Watermark) count++;
}
Console.WriteLine("Page contains " + count + " watermarks");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Instantiate Document object with input file
Document doc = new Document(dataDir+ "DefineAlignment.pdf");
// Instantiate FormattedText object with sample string
FormattedText text = new FormattedText("This");
// Add new text line to FormattedText
text.AddNewLineText("is sample");
text.AddNewLineText("Center Aligned");
text.AddNewLineText("TextStamp");
text.AddNewLineText("Object");
// Create TextStamp object using FormattedText
TextStamp stamp = new TextStamp(text);
// Specify the Horizontal Alignment of text stamp as Center aligned
stamp.HorizontalAlignment = HorizontalAlignment.Center;
// Specify the Vertical Alignment of text stamp as Center aligned
stamp.VerticalAlignment = VerticalAlignment.Center;
// Specify the Text Horizontal Alignment of TextStamp as Center aligned
stamp.TextAlignment = HorizontalAlignment.Center;
// Set top margin for stamp object
stamp.TopMargin = 20;
// Add the stamp object over first page of document
doc.Pages[1].AddStamp(stamp);
dataDir = dataDir + "StampedPDF_out.pdf";
// Save the udpated document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Create TextState object to transfer advanced properties
TextState ts = new TextState();
// Set color for stroke
ts.StrokingColor = Color.Gray;
// Set text rendering mode
ts.RenderingMode = TextRenderingMode.StrokeText;
// Load an input PDF document
Facades.PdfFileStamp fileStamp = new Facades.PdfFileStamp(new Aspose.Pdf.Document(dataDir + "input.pdf"));
Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindLogo(new Facades.FormattedText("PAID IN FULL", System.Drawing.Color.Gray, "Arial", Facades.EncodingType.Winansi, true, 78));
// Bind TextState
stamp.BindTextState(ts);
// Set X,Y origin
stamp.SetOrigin(100, 100);
stamp.Opacity = 5;
stamp.BlendingSpace = Facades.BlendingColorSpace.DeviceRGB;
stamp.Rotation = 45.0F;
stamp.IsBackground = false;
// Add Stamp
fileStamp.AddStamp(stamp);
fileStamp.Save(dataDir + "ouput_out.pdf");
fileStamp.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document( dataDir + "watermark.pdf");
// Iterate through and get tub-type, text and location of artifact
foreach (Artifact artifact in pdfDocument.Pages[1].Artifacts)
{
Console.WriteLine(artifact.Subtype + " " + artifact.Text + " " + artifact.Rectangle);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
// Create a page in the document object
Aspose.Pdf.Page page = doc.Pages.Add();
// Create Header Section of the document
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
// Set the header for the PDF file
page.Header = header;
// Create an image object in the page
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
// Set the path of image file
image1.File = dataDir + "aspose-logo.jpg";
// Add image to Header page of the Pdf file
header.Paragraphs.Add(image1);
// Create a Footer Section of the document
Aspose.Pdf.HeaderFooter footer = new Aspose.Pdf.HeaderFooter();
// Set the footer of the PDF file
page.Footer = footer;
// Create a Text object
Aspose.Pdf.Text.TextFragment txt = new Aspose.Pdf.Text.TextFragment("Page: ($p of $P ) ");
// Add text to Header section of the Pdf file
footer.Paragraphs.Add(txt);
// Save the Pdf file
doc.Save(dataDir + "ImageAndPageNumberInHeaderFooter_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Instantiate a Document object by calling its empty constructor
Aspose.Pdf.Document pdf1 = new Aspose.Pdf.Document();
// Create a page in the Pdf object
Aspose.Pdf.Page page = pdf1.Pages.Add();
// Create Header Section of the document
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
// Set the header for the PDF file
page.Header = header;
// Create a Text object
Aspose.Pdf.Text.TextFragment txt1 = new Aspose.Pdf.Text.TextFragment("Aspose.Pdf is a Robust component by");
// Specify the color
txt1.TextState.ForegroundColor = Color.Blue;
txt1.IsInLineParagraph = true;
// Create an image object in the section
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
// Set the path of image file
image1.File = dataDir + "aspose-logo.jpg";
// Set the image width Information
image1.FixWidth = 50;
image1.FixHeight = 20;
// Indicate seg1's InlineParagraph is a image.
image1.IsInLineParagraph = true;
Aspose.Pdf.Text.TextFragment txt2 = new Aspose.Pdf.Text.TextFragment(" Pty Ltd.");
txt2.IsInLineParagraph = true;
txt2.TextState.ForegroundColor = Color.Maroon;
header.Paragraphs.Add(txt1);
header.Paragraphs.Add(image1);
header.Paragraphs.Add(txt2);
// Save the Pdf
pdf1.Save(dataDir + "ImageAndPageNumberInHeaderFooter_UsingInlineParagraph_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "ImageInFooter.pdf");
// Create footer
ImageStamp imageStamp = new ImageStamp(dataDir+ "aspose-logo.jpg");
// Set properties of the stamp
imageStamp.BottomMargin = 10;
imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
imageStamp.VerticalAlignment = VerticalAlignment.Bottom;
// Add footer on all pages
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(imageStamp);
}
dataDir = dataDir + "ImageInFooter_out.pdf";
// Save updated PDF file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "ImageinHeader.pdf");
// Create header
ImageStamp imageStamp = new ImageStamp(dataDir+ "aspose-logo.jpg");
// Set properties of the stamp
imageStamp.TopMargin = 10;
imageStamp.HorizontalAlignment = HorizontalAlignment.Center;
imageStamp.VerticalAlignment = VerticalAlignment.Top;
// Add header on all pages
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(imageStamp);
}
dataDir = dataDir + "ImageinHeader_out.pdf";
// Save updated document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Instantiate Document instance
Aspose.Pdf.Document pdf = new Aspose.Pdf.Document();
// Add a Page into the pdf document
Aspose.Pdf.Page page = pdf.Pages.Add();
// Initializes a new instance of the FloatingBox class
Aspose.Pdf.FloatingBox box1 = new Aspose.Pdf.FloatingBox(140, 80);
// Float value that indicates left position of the paragraph
box1.Left = 2;
// Float value that indicates top position of the paragraph
box1.Top = 10;
// Add the macros to the paragraphs collection of the FloatingBox
box1.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Page: ($p/ $P )"));
// Add a floatingBox to the page
page.Paragraphs.Add(box1);
// Save the document
pdf.Save(dataDir + "PageNumberinHeaderFooterUsingFloatingBox_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "PageNumberStamp.pdf");
// Create page number stamp
PageNumberStamp pageNumberStamp = new PageNumberStamp();
// Whether the stamp is background
pageNumberStamp.Background = false;
pageNumberStamp.Format = "Page # of " + pdfDocument.Pages.Count;
pageNumberStamp.BottomMargin = 10;
pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center;
pageNumberStamp.StartingNumber = 1;
// Set text properties
pageNumberStamp.TextState.Font = FontRepository.FindFont("Arial");
pageNumberStamp.TextState.FontSize = 14.0F;
pageNumberStamp.TextState.FontStyle = FontStyles.Bold;
pageNumberStamp.TextState.FontStyle = FontStyles.Italic;
pageNumberStamp.TextState.ForegroundColor = Color.Aqua;
// Add stamp to particular page
pdfDocument.Pages[1].AddStamp(pageNumberStamp);
dataDir = dataDir + "PageNumberStamp_out.pdf";
// Save output document
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Instantiate Document instance by calling empty constructor
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
// Create a page in the pdf document
Aspose.Pdf.Page page = pdfDocument.Pages.Add();
// Create a Header Section of the PDF file
Aspose.Pdf.HeaderFooter header = new Aspose.Pdf.HeaderFooter();
// Set the Odd Header for the PDF file
page.Header = header;
// Set the top margin for the header section
header.Margin.Top = 20;
// Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
// Add the table in paragraphs collection of the desired section
header.Paragraphs.Add(tab1);
// Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
// Set with column widths of the table
tab1.ColumnWidths = "60 300";
Aspose.Pdf.Image img = new Aspose.Pdf.Image();
img.File = dataDir + "aspose-logo.jpg";
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = tab1.Rows.Add();
row1.Cells.Add("Table in Header Section");
row1.BackgroundColor = Color.Gray;
// Set the row span value for first row as 2
tab1.Rows[0].Cells[0].ColSpan = 2;
tab1.Rows[0].Cells[0].DefaultCellTextState.ForegroundColor = Color.Cyan;
tab1.Rows[0].Cells[0].DefaultCellTextState.Font = FontRepository.FindFont("Helvetica");
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row2 = tab1.Rows.Add();
// Set the background color for Row2
row2.BackgroundColor = Color.White;
// Add the cell which holds the image
Aspose.Pdf.Cell cell2 = row2.Cells.Add();
// Set the image width to 60
img.FixWidth = 60;
// Add the image to the table cell
cell2.Paragraphs.Add(img);
row2.Cells.Add("Logo is looking fine !");
row2.Cells[1].DefaultCellTextState.Font = FontRepository.FindFont("Helvetica");
// Set the vertical allignment of the text as center alligned
row2.Cells[1].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;
row2.Cells[1].Alignment = Aspose.Pdf.HorizontalAlignment.Center;
// Save the Pdf file
pdfDocument.Save(dataDir + "TableInHeaderFooterSection_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "TextinFooter.pdf");
// Create footer
TextStamp textStamp = new TextStamp("Footer Text");
// Set properties of the stamp
textStamp.BottomMargin = 10;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Bottom;
// Add footer on all pages
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(textStamp);
}
dataDir = dataDir + "TextinFooter_out.pdf";
// Save updated PDF file
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_StampsWatermarks();
// Open document
Document pdfDocument = new Document(dataDir+ "TextinHeader.pdf");
// Create header
TextStamp textStamp = new TextStamp("Header Text");
// Set properties of the stamp
textStamp.TopMargin = 10;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.VerticalAlignment = VerticalAlignment.Top;
// Add header on all pages
foreach (Page page in pdfDocument.Pages)
{
page.AddStamp(textStamp);
}
// Save updated document
pdfDocument.Save(dataDir+ "TextinHeader_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Instantiate a Document object
Document pdfDocument = new Document();
// Create a page in the pdf document
Page sec1 = pdfDocument.Pages.Add();
// Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
// Add the table in paragraphs collection of the desired page
sec1.Paragraphs.Add(tab1);
// Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
// Set with column widths of the table
tab1.ColumnWidths = "100 100 120";
Aspose.Pdf.Image img = new Aspose.Pdf.Image();
img.File = dataDir + "aspose.jpg";
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = tab1.Rows.Add();
row1.Cells.Add("Sample text in cell");
// Add the cell which holds the image
Aspose.Pdf.Cell cell2 = row1.Cells.Add();
// Add the image to the table cell
cell2.Paragraphs.Add(img);
row1.Cells.Add("Previous cell with image");
row1.Cells[2].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center;
// Save the Document
pdfDocument.Save(dataDir + "AddImageInTableCell_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
string outFile = dataDir + "AddRepeatingColumn_out.pdf";
// Create a new document
Document doc = new Document();
Aspose.Pdf.Page page = doc.Pages.Add();
// Instantiate an outer table that takes up the entire page
Aspose.Pdf.Table outerTable = new Aspose.Pdf.Table();
outerTable.ColumnWidths = "100%";
outerTable.HorizontalAlignment = HorizontalAlignment.Left;
// Instantiate a table object that will be nested inside outerTable that will break inside the same page
Aspose.Pdf.Table mytable = new Aspose.Pdf.Table();
mytable.Broken = TableBroken.VerticalInSamePage;
mytable.ColumnAdjustment = ColumnAdjustment.AutoFitToContent;
// Add the outerTable to the page paragraphs
// Add mytable to outerTable
page.Paragraphs.Add(outerTable);
var bodyRow = outerTable.Rows.Add();
var bodyCell = bodyRow.Cells.Add();
bodyCell.Paragraphs.Add(mytable);
mytable.RepeatingColumnsCount = 5;
page.Paragraphs.Add(mytable);
// Add header Row
Aspose.Pdf.Row row = mytable.Rows.Add();
row.Cells.Add("header 1");
row.Cells.Add("header 2");
row.Cells.Add("header 3");
row.Cells.Add("header 4");
row.Cells.Add("header 5");
row.Cells.Add("header 6");
row.Cells.Add("header 7");
row.Cells.Add("header 11");
row.Cells.Add("header 12");
row.Cells.Add("header 13");
row.Cells.Add("header 14");
row.Cells.Add("header 15");
row.Cells.Add("header 16");
row.Cells.Add("header 17");
for (int RowCounter = 0; RowCounter <= 5; RowCounter++)
{
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = mytable.Rows.Add();
row1.Cells.Add("col " + RowCounter.ToString() + ", 1");
row1.Cells.Add("col " + RowCounter.ToString() + ", 2");
row1.Cells.Add("col " + RowCounter.ToString() + ", 3");
row1.Cells.Add("col " + RowCounter.ToString() + ", 4");
row1.Cells.Add("col " + RowCounter.ToString() + ", 5");
row1.Cells.Add("col " + RowCounter.ToString() + ", 6");
row1.Cells.Add("col " + RowCounter.ToString() + ", 7");
row1.Cells.Add("col " + RowCounter.ToString() + ", 11");
row1.Cells.Add("col " + RowCounter.ToString() + ", 12");
row1.Cells.Add("col " + RowCounter.ToString() + ", 13");
row1.Cells.Add("col " + RowCounter.ToString() + ", 14");
row1.Cells.Add("col " + RowCounter.ToString() + ", 15");
row1.Cells.Add("col " + RowCounter.ToString() + ", 16");
row1.Cells.Add("col " + RowCounter.ToString() + ", 17");
}
doc.Save(outFile);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Instantiate Document object
Document doc = new Document();
// Create an image instance
Aspose.Pdf.Image img = new Aspose.Pdf.Image();
// Set image type as SVG
img.FileType = Aspose.Pdf.ImageFileType.Svg;
// Path for source file
img.File = dataDir + "SVGToPDF.svg";
// Set width for image instance
img.FixWidth = 50;
// Set height for image instance
img.FixHeight = 50;
// Create table instance
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Set width for table cells
table.ColumnWidths = "100 100";
// Create row object and add it to table instance
Aspose.Pdf.Row row = table.Rows.Add();
// Create cell object and add it to row instance
Aspose.Pdf.Cell cell = row.Cells.Add();
// Add textfragment to paragraphs collection of cell object
cell.Paragraphs.Add(new TextFragment("First cell"));
// Add another cell to row object
cell = row.Cells.Add();
// Add SVG image to paragraphs collection of recently added cell instance
cell.Paragraphs.Add(img);
// Create page object and add it to pages collection of document instance
Page page = doc.Pages.Add();
// Add table to paragraphs collection of page object
page.Paragraphs.Add(table);
dataDir = dataDir + "AddSVGObject_out.pdf";
// Save PDF file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Load source PDF document
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir+ "AddTable.pdf");
// 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 object to first page of input document
doc.Pages[1].Paragraphs.Add(table);
dataDir = dataDir + "document_with_table_out.pdf";
// Save updated document containing table object
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Instntiate the Pdf object by calling its empty constructor
Document doc = new Document();
// Create the section in the Pdf object
Page sec1 = doc.Pages.Add();
// Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
// Add the table in paragraphs collection of the desired section
sec1.Paragraphs.Add(tab1);
// Set with column widths of the table
tab1.ColumnWidths = "50 50 50";
tab1.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;
// Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
// Set table border using another customized BorderInfo object
tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
// Create MarginInfo object and set its left, bottom, right and top margins
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
// Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = tab1.Rows.Add();
row1.Cells.Add("col1");
row1.Cells.Add("col2");
row1.Cells.Add("col3");
Aspose.Pdf.Row row2 = tab1.Rows.Add();
row2.Cells.Add("item1");
row2.Cells.Add("item2");
row2.Cells.Add("item3");
dataDir = dataDir + "AutoFitToWindow_out.pdf";
// Save updated document containing table object
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Instantiate an object PDF class
Document pdf = new Document();
// Add the section to PDF document sections collection
Aspose.Pdf.Page page = pdf.Pages.Add();
// Instantiate a table object
Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
table1.Margin.Top = 300;
// Add the table in paragraphs collection of the desired section
page.Paragraphs.Add(table1);
// Set with column widths of the table
table1.ColumnWidths = "100 100 100";
// Set default cell border using BorderInfo object
table1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
// Set table border using another customized BorderInfo object
table1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
// Create MarginInfo object and set its left, bottom, right and top margins
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
// Set the default cell padding to the MarginInfo object
table1.DefaultCellPadding = margin;
// If you increase the counter to 17, table will break
// Because it cannot be accommodated any more over this page
for (int RowCounter = 0; RowCounter <= 16; RowCounter++)
{
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = table1.Rows.Add();
row1.Cells.Add("col " + RowCounter.ToString() + ", 1");
row1.Cells.Add("col " + RowCounter.ToString() + ", 2");
row1.Cells.Add("col " + RowCounter.ToString() + ", 3");
}
// Get the Page Height information
float PageHeight = (float)pdf.PageInfo.Height;
// Get the total height information of Page Top & Bottom margin,
// Table Top margin and table height.
float TotalObjectsHeight = (float)page.PageInfo.Margin.Top + (float)page.PageInfo.Margin.Bottom + (float)table1.Margin.Top + (float)table1.GetHeight();
// Display Page Height, Table Height, table Top margin and Page Top
// And Bottom margin information
Console.WriteLine("PDF document Height = " + pdf.PageInfo.Height.ToString() + "\nTop Margin Info = " + page.PageInfo.Margin.Top.ToString() + "\nBottom Margin Info = " + page.PageInfo.Margin.Bottom.ToString() + "\n\nTable-Top Margin Info = " + table1.Margin.Top.ToString() + "\nAverage Row Height = " + table1.Rows[0].MinRowHeight.ToString() + " \nTable height " + table1.GetHeight().ToString() + "\n ----------------------------------------" + "\nTotal Page Height =" + PageHeight.ToString() + "\nCummulative height including Table =" + TotalObjectsHeight.ToString());
// Check if we deduct the sume of Page top margin + Page Bottom margin
// + Table Top margin and table height from Page height and its less
// Than 10 (an average row can be greater than 10)
if ((PageHeight - TotalObjectsHeight) <= 10)
// If the value is less than 10, then display the message.
// Which shows that another row can not be placed and if we add new
// Row, table will break. It depends upon the row height value.
Console.WriteLine("Page Height - Objects Height < 10, so table will break");
dataDir = dataDir + "DetermineTableBreak_out.pdf";
// Save the pdf document
pdf.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(new FileStream(dataDir + "newBook1.xlsx", FileMode.Open));
// Accessing the first worksheet in the Excel file
Aspose.Cells.Worksheet worksheet = workbook.Worksheets[0];
// Exporting the contents of 7 rows and 2 columns starting from 1st cell to DataTable
DataTable dataTable = worksheet.Cells.ExportDataTable(0, 0, worksheet.Cells.MaxRow + 1, worksheet.Cells.MaxColumn + 1, true);
// Instantiate a Document instanc
Aspose.Pdf.Document pdf1 = new Aspose.Pdf.Document();
// Create a page in the document instance
Aspose.Pdf.Page sec1 = pdf1.Pages.Add();
// Create a Table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
// Add the Table object in the paragraphs collection of the section
sec1.Paragraphs.Add(tab1);
// Set column widths of the table. We need to specify the ColumnCount manually.
// As the curent excel worksheet has three columsn, so we are specifying the same count
tab1.ColumnWidths = "40 100 100";
// Set default cell border of the table using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
// Import data into the Table object from the DataTable created above
tab1.ImportDataTable(dataTable, true, 0, 0, dataTable.Rows.Count + 1, dataTable.Columns.Count);
// Get 1st row from the table
Aspose.Pdf.Row row1 = tab1.Rows[0];
// Iterate through all cells in the 1st row and set their background color to blue
foreach (Aspose.Pdf.Cell curCell in row1.Cells)
{
// Set the background of all the cells in 1st row of the table.
curCell.BackgroundColor = Color.Blue;
// Set the font face for the cells of 1st row in the table.
curCell.DefaultCellTextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Helvetica-Oblique");
// Set the font Color of all the cells in 1st row of the table.
curCell.DefaultCellTextState.ForegroundColor = Color.Yellow;
// Set the text allignment for the cells of 1st row as Center.
curCell.DefaultCellTextState.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
}
for (int All_Rows = 1; All_Rows <= dataTable.Rows.Count; All_Rows++)
{
// Iterate through all cells in the 1st row and set their background color to blue
foreach (Aspose.Pdf.Cell curCell in tab1.Rows[All_Rows].Cells)
{
// Set the background color of all the cells except of the 1st row.
curCell.BackgroundColor = Color.Gray;
// Set the Text color of all the cells except the 1st row.
curCell.DefaultCellTextState.ForegroundColor = Color.White;
}
}
// Save the Pdf
pdf1.Save(dataDir + @"Exceldata_toPdf_table.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
Document doc = new Document(dataDir + "input.pdf");
Stack graphicsState = new Stack();
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap((int)doc.Pages[1].PageInfo.Width, (int)doc.Pages[1].PageInfo.Height);
System.Drawing.Drawing2D.GraphicsPath graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
// Default ctm matrix value is 1,0,0,1,0,0
System.Drawing.Drawing2D.Matrix lastCTM = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, 0);
// System.Drawing coordinate system is top left based, while pdf coordinate system is low left based, so we have to apply the inversion matrix
System.Drawing.Drawing2D.Matrix inversionMatrix = new System.Drawing.Drawing2D.Matrix(1, 0, 0, -1, 0, (float)doc.Pages[1].PageInfo.Height);
System.Drawing.PointF lastPoint = new System.Drawing.PointF(0, 0);
System.Drawing.Color fillColor = System.Drawing.Color.FromArgb(0, 0, 0);
System.Drawing.Color strokeColor = System.Drawing.Color.FromArgb(0, 0, 0);
using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bitmap))
{
gr.SmoothingMode = SmoothingMode.HighQuality;
graphicsState.Push(new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, 0, 0));
// Process all the contents commands
foreach (Operator op in doc.Pages[1].Contents)
{
Aspose.Pdf.Operators.GSave opSaveState = op as Aspose.Pdf.Operators.GSave;
Aspose.Pdf.Operators.GRestore opRestoreState = op as Aspose.Pdf.Operators.GRestore;
Aspose.Pdf.Operators.ConcatenateMatrix opCtm = op as Aspose.Pdf.Operators.ConcatenateMatrix;
Aspose.Pdf.Operators.MoveTo opMoveTo = op as Aspose.Pdf.Operators.MoveTo;
Aspose.Pdf.Operators.LineTo opLineTo = op as Aspose.Pdf.Operators.LineTo;
Aspose.Pdf.Operators.Re opRe = op as Aspose.Pdf.Operators.Re;
Aspose.Pdf.Operators.EndPath opEndPath = op as Aspose.Pdf.Operators.EndPath;
Aspose.Pdf.Operators.Stroke opStroke = op as Aspose.Pdf.Operators.Stroke;
Aspose.Pdf.Operators.Fill opFill = op as Aspose.Pdf.Operators.Fill;
Aspose.Pdf.Operators.EOFill opEOFill = op as Aspose.Pdf.Operators.EOFill;
Aspose.Pdf.Operators.SetRGBColor opRGBFillColor = op as Aspose.Pdf.Operators.SetRGBColor;
Aspose.Pdf.Operators.SetRGBColorStroke opRGBStrokeColor = op as Aspose.Pdf.Operators.SetRGBColorStroke;
if (opSaveState != null)
{
// Save previous state and push current state to the top of the stack
graphicsState.Push(((System.Drawing.Drawing2D.Matrix)graphicsState.Peek()).Clone());
lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek();
}
else if (opRestoreState != null)
{
// Throw away current state and restore previous one
graphicsState.Pop();
lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek();
}
else if (opCtm != null)
{
System.Drawing.Drawing2D.Matrix cm = new System.Drawing.Drawing2D.Matrix(
(float)opCtm.Matrix.A,
(float)opCtm.Matrix.B,
(float)opCtm.Matrix.C,
(float)opCtm.Matrix.D,
(float)opCtm.Matrix.E,
(float)opCtm.Matrix.F);
// Multiply current matrix with the state matrix
((System.Drawing.Drawing2D.Matrix)graphicsState.Peek()).Multiply(cm);
lastCTM = (System.Drawing.Drawing2D.Matrix)graphicsState.Peek();
}
else if (opMoveTo != null)
{
lastPoint = new System.Drawing.PointF((float)opMoveTo.X, (float)opMoveTo.Y);
}
else if (opLineTo != null)
{
System.Drawing.PointF linePoint = new System.Drawing.PointF((float)opLineTo.X, (float)opLineTo.Y);
graphicsPath.AddLine(lastPoint, linePoint);
lastPoint = linePoint;
}
else if (opRe != null)
{
System.Drawing.RectangleF re = new System.Drawing.RectangleF((float)opRe.X, (float)opRe.Y, (float)opRe.Width, (float)opRe.Height);
graphicsPath.AddRectangle(re);
}
else if (opEndPath != null)
{
graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
}
else if (opRGBFillColor != null)
{
fillColor = opRGBFillColor.getColor();
}
else if (opRGBStrokeColor != null)
{
strokeColor = opRGBStrokeColor.getColor();
}
else if (opStroke != null)
{
graphicsPath.Transform(lastCTM);
graphicsPath.Transform(inversionMatrix);
gr.DrawPath(new System.Drawing.Pen(strokeColor), graphicsPath);
graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
}
else if (opFill != null)
{
graphicsPath.FillMode = FillMode.Winding;
graphicsPath.Transform(lastCTM);
graphicsPath.Transform(inversionMatrix);
gr.FillPath(new System.Drawing.SolidBrush(fillColor), graphicsPath);
graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
}
else if (opEOFill != null)
{
graphicsPath.FillMode = FillMode.Alternate;
graphicsPath.Transform(lastCTM);
graphicsPath.Transform(inversionMatrix);
gr.FillPath(new System.Drawing.SolidBrush(fillColor), graphicsPath);
graphicsPath = new System.Drawing.Drawing2D.GraphicsPath();
}
}
}
dataDir = dataDir + "ExtractBorder_out.png";
bitmap.Save(dataDir, ImageFormat.Png);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
DataTable dt = new DataTable("Employee");
dt.Columns.Add("data", System.Type.GetType("System.String"));
DataRow dr = dt.NewRow();
dr[0] = "<li>Department of Emergency Medicine: 3400 Spruce Street Ground Silverstein Bldg Philadelphia PA 19104-4206</li>";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "<li>Penn Observation Medicine Service: 3400 Spruce Street Ground Floor Donner Philadelphia PA 19104-4206</li>";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "<li>UPHS/Presbyterian - Dept. of Emergency Medicine: 51 N. 39th Street . Philadelphia PA 19104-2640</li>";
dt.Rows.Add(dr);
Document doc = new Document();
doc.Pages.Add();
// Initializes a new instance of the Table
Aspose.Pdf.Table tableProvider = new Aspose.Pdf.Table();
//Set column widths of the table
tableProvider.ColumnWidths = "400 50 ";
// Set the table border color as LightGray
tableProvider.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Set the border for table cells
tableProvider.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Top = 2.5F;
margin.Left = 2.5F;
margin.Bottom = 1.0F;
tableProvider.DefaultCellPadding = margin;
tableProvider.ImportDataTable(dt, false, 0, 0, 3, 1, true);
doc.Pages[1].Paragraphs.Add(tableProvider);
doc.Save(dataDir + "HTMLInsideTableCell_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Instantiate Document instance
Document doc = new Document();
// Add page to pages collection of PDF file
doc.Pages.Add();
// Create table instance
Aspose.Pdf.Table tab = new Aspose.Pdf.Table();
// Set border style for table
tab.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red);
// Set default border style for table with border color as Red
tab.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, Aspose.Pdf.Color.Red);
// Specify table columsn widht
tab.ColumnWidths = "100 100";
// Create a loop to add 200 rows for table
for (int counter = 0; counter <= 200; counter++)
{
Aspose.Pdf.Row row = new Aspose.Pdf.Row();
tab.Rows.Add(row);
Aspose.Pdf.Cell cell1 = new Aspose.Pdf.Cell();
cell1.Paragraphs.Add(new TextFragment("Cell " + counter + ", 0"));
row.Cells.Add(cell1); Aspose.Pdf.Cell cell2 = new Aspose.Pdf.Cell();
cell2.Paragraphs.Add(new TextFragment("Cell " + counter + ", 1"));
row.Cells.Add(cell2);
// When 10 rows are added, render new row in new page
if (counter % 10 == 0 && counter != 0) row.IsInNewPage = true;
}
// Add table to paragraphs collection of PDF file
doc.Pages[1].Paragraphs.Add(tab);
dataDir = dataDir + "InsertPageBreak_out.pdf";
// Save the PDF document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
DataTable dt = new DataTable("Employee");
dt.Columns.Add("Employee_ID", typeof(Int32));
dt.Columns.Add("Employee_Name", typeof(string));
dt.Columns.Add("Gender", typeof(string));
// Add 2 rows into the DataTable object programmatically
DataRow dr = dt.NewRow();
dr[0] = 1;
dr[1] = "John Smith";
dr[2] = "Male";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 2;
dr[1] = "Mary Miller";
dr[2] = "Female";
dt.Rows.Add(dr);
// Create Document instance
Document doc = new Document();
doc.Pages.Add();
// Initializes a new instance of the Table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Set column widths of the table
table.ColumnWidths = "40 100 100 100";
// 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));
table.ImportDataTable(dt, true, 0, 1, 3, 3);
// Add table object to first page of input document
doc.Pages[1].Paragraphs.Add(table);
dataDir = dataDir + "DataIntegrated_out.pdf";
// Save updated document containing table object
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Load existing PDF file
Document pdfDocument = new Document(dataDir + "input.pdf");
// Create TableAbsorber object to find tables
TableAbsorber absorber = new TableAbsorber();
// Visit first page with absorber
absorber.Visit(pdfDocument.Pages[1]);
// Get access to first table on page, their first cell and text fragments in it
TextFragment fragment = absorber.TableList[0].RowList[0].CellList[0].TextFragments[1];
// Change text of the first text fragment in the cell
fragment.Text = "hi world";
dataDir = dataDir + "ManipulateTable_out.pdf";
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Instntiate the Document object by calling its empty constructor
Document doc = new Document();
Page page = doc.Pages.Add();
// Instantiate a table object
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
// Add the table in paragraphs collection of the desired section
page.Paragraphs.Add(tab1);
// Set with column widths of the table
tab1.ColumnWidths = "50 50 50";
// Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.1F);
// Set table border using another customized BorderInfo object
tab1.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1F);
// Create MarginInfo object and set its left, bottom, right and top margins
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
// Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = tab1.Rows.Add();
row1.Cells.Add("col1");
row1.Cells.Add("col2");
row1.Cells.Add();
TextFragment mytext = new TextFragment("col3 with large text string");
// Row1.Cells.Add("col3 with large text string to be placed inside cell");
row1.Cells[2].Paragraphs.Add(mytext);
row1.Cells[2].IsWordWrapped = false;
// Row1.Cells[2].Paragraphs[0].FixedWidth= 80;
Aspose.Pdf.Row row2 = tab1.Rows.Add();
row2.Cells.Add("item1");
row2.Cells.Add("item2");
row2.Cells.Add("item3");
dataDir = dataDir + "MarginsOrPadding_out.pdf";
// Save the Pdf
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Load existing PDF document
Document pdfDocument = new Document(dataDir + "Table_input2.pdf");
// Create TableAbsorber object to find tables
TableAbsorber absorber = new TableAbsorber();
// Visit second page with absorber
absorber.Visit(pdfDocument.Pages[1]);
// Get copy of table collection
AbsorbedTable[] tables = new AbsorbedTable[absorber.TableList.Count];
absorber.TableList.CopyTo(tables, 0);
// Loop through the copy of collection and removing tables
foreach (AbsorbedTable table in tables)
absorber.Remove(table);
// Save document
pdfDocument.Save(dataDir + "Table2_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Load existing PDF document
Document pdfDocument = new Document(dataDir + "Table_input.pdf");
// Create TableAbsorber object to find tables
TableAbsorber absorber = new TableAbsorber();
// Visit first page with absorber
absorber.Visit(pdfDocument.Pages[1]);
// Get first table on the page
AbsorbedTable table = absorber.TableList[0];
// Remove the table
absorber.Remove(table);
// Save PDF
pdfDocument.Save(dataDir + "Table_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
Document doc = new Document();
PageInfo pageInfo = doc.PageInfo;
Aspose.Pdf.MarginInfo marginInfo = pageInfo.Margin;
marginInfo.Left = 37;
marginInfo.Right = 37;
marginInfo.Top = 37;
marginInfo.Bottom = 37;
pageInfo.IsLandscape = true;
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.ColumnWidths = "50 100";
// Added page.
Page curPage = doc.Pages.Add();
for (int i = 1; i <= 120; i++)
{
Aspose.Pdf.Row row = table.Rows.Add();
row.FixedRowHeight = 15;
Aspose.Pdf.Cell cell1 = row.Cells.Add();
cell1.Paragraphs.Add(new TextFragment("Content 1"));
Aspose.Pdf.Cell cell2 = row.Cells.Add();
cell2.Paragraphs.Add(new TextFragment("HHHHH"));
}
Aspose.Pdf.Paragraphs paragraphs = curPage.Paragraphs;
paragraphs.Add(table);
/********************************************/
Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
table.ColumnWidths = "100 100";
for (int i = 1; i <= 10; i++)
{
Aspose.Pdf.Row row = table1.Rows.Add();
Aspose.Pdf.Cell cell1 = row.Cells.Add();
cell1.Paragraphs.Add(new TextFragment("LAAAAAAA"));
Aspose.Pdf.Cell cell2 = row.Cells.Add();
cell2.Paragraphs.Add(new TextFragment("LAAGGGGGG"));
}
table1.IsInNewPage = true;
// I want to keep table 1 to next page please...
paragraphs.Add(table1);
dataDir = dataDir + "IsNewPageProperty_Test_out.pdf";
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Load existing PDF document
Document pdfDocument = new Document(dataDir + @"Table_input2.pdf");
// Create TableAbsorber object to find tables
TableAbsorber absorber = new TableAbsorber();
// Visit first page with absorber
absorber.Visit(pdfDocument.Pages[1]);
// Get first table on the page
AbsorbedTable table = absorber.TableList[0];
// Create new table
Table newTable = new Table();
newTable.ColumnWidths = "100 100 100";
newTable.DefaultCellBorder = new BorderInfo(BorderSide.All, 1F);
Row row = newTable.Rows.Add();
row.Cells.Add("Col 1");
row.Cells.Add("Col 2");
row.Cells.Add("Col 3");
// Replace the table with new one
absorber.Replace(pdfDocument.Pages[1], table, newTable);
// Save document
pdfDocument.Save(dataDir + "TableReplaced_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
Aspose.Pdf.Table tab1 = new Aspose.Pdf.Table();
GraphInfo graph = new GraphInfo();
graph.Color = Aspose.Pdf.Color.Red;
// Create a blank BorderInfo object
BorderInfo bInfo = new BorderInfo(BorderSide.All, graph);
// Set the border a rounder border where radius of round is 15
bInfo.RoundedBorderRadius = 15;
// Set the table Corner style as Round.
tab1.CornerStyle = Aspose.Pdf.BorderCornerStyle.Round;
// Set the table border information
tab1.Border = bInfo;
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Tables();
// Instantiate Document object
Document doc = new Document();
// Add page to PDF document
Page page = doc.Pages.Add();
// Create BorderInfo object
Aspose.Pdf.BorderInfo border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All);
// Specify that Top border will be double
border.Top.IsDoubled = true;
// Specify that bottom border will be double
border.Bottom.IsDoubled = true;
// Instantiate Table object
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Specify Columns width information
table.ColumnWidths = "100";
// Create Row object
Aspose.Pdf.Row row = table.Rows.Add();
// Add a Table cell to cells collection of row
Aspose.Pdf.Cell cell = row.Cells.Add("some text");
// Set the border for cell object (double border)
cell.Border = border;
// Add table to paragraphs collection of Page
page.Paragraphs.Add(table);
dataDir = dataDir + "TableBorderTest_out.pdf";
// Save the PDF document
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_TechnicalArticles();
// Instantiate Document Object
Document doc = new Document();
// Instantiate document Collection object
doc.Collection = new Collection();
// Get Files to add to Portfolio
FileSpecification excel = new FileSpecification( dataDir + "HelloWorld.xlsx");
FileSpecification word = new FileSpecification( dataDir + "HelloWorld.docx");
FileSpecification image = new FileSpecification(dataDir + "aspose-logo.jpg");
// Provide description of the files
excel.Description = "Excel File";
word.Description = "Word File";
image.Description = "Image File";
// Add files to document collection
doc.Collection.Add(excel);
doc.Collection.Add(word);
doc.Collection.Add(image);
// Save Portfolio document
doc.Save(dataDir + "CreatePDFPortfolio_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_TechnicalArticles();
// Load source PDF Portfolio
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(dataDir + "PDFPortfolio.pdf");
// Get collection of embedded files
EmbeddedFileCollection embeddedFiles = pdfDocument.EmbeddedFiles;
// Itterate through individual file of Portfolio
foreach (FileSpecification fileSpecification in embeddedFiles)
{
// Get the attachment and write to file or stream
byte[] fileContent = new byte[fileSpecification.Contents.Length];
fileSpecification.Contents.Read(fileContent, 0, fileContent.Length);
string filename = Path.GetFileName(fileSpecification.Name);
// Save the extracted file to some location
FileStream fileStream = new FileStream(dataDir + "_out" + filename, FileMode.Create);
fileStream.Write(fileContent, 0, fileContent.Length);
// Close the stream object
fileStream.Close();
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_TechnicalArticles();
// Load source PDF Portfolio
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(dataDir + "PDFPortfolio.pdf");
pdfDocument.Collection.Delete();
pdfDocument.Save(dataDir + "No_PortFolio_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Instantiate Document object
Document doc = new Document();
// Add a page to pages collection of PDF file
Page page = doc.Pages.Add();
// Instantiate HtmlFragment with HTML contnets
HtmlFragment titel = new HtmlFragment("<fontsize=10><b><i>Table</i></b></fontsize>");
// Set bottom margin information
titel.Margin.Bottom = 10;
// Set top margin information
titel.Margin.Top = 200;
// Add HTML Fragment to paragraphs collection of page
page.Paragraphs.Add(titel);
dataDir = dataDir + "AddHTMLUsingDOM_out.pdf";
// Save PDF file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
Document doc = new Document();
Page page = doc.Pages.Add();
HtmlFragment html = new HtmlFragment("<fontsize=10><b><i>Aspose.PDF</i></b></fontsize>");
page.Paragraphs.Add(html);
dataDir = dataDir + "HTMLfragmentRectangle_out.pdf";
doc.Save(dataDir);
Console.WriteLine(html.Rectangle.Width);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create new document object
Aspose.Pdf.Document document = new Aspose.Pdf.Document();
Aspose.Pdf.Page page = document.Pages.Add();
Aspose.Pdf.Text.TextFragment text = new Aspose.Pdf.Text.TextFragment("A quick brown fox jumped over the lazy dog. A quick brown fox jumped over the lazy dog. A quick brown fox jumped over the lazy dog. A quick brown fox jumped over the lazy dog. A quick brown fox jumped over the lazy dog. A quick brown fox jumped over the lazy dog. A quick brown fox jumped over the lazy dog. A quick brown fox jumped over the lazy dog.");
// Initilize TextFormattingOptions for the text fragment and specify SubsequentLinesIndent value
text.TextState.FormattingOptions = new Aspose.Pdf.Text.TextFormattingOptions()
{
SubsequentLinesIndent = 20
};
page.Paragraphs.Add(text);
text = new Aspose.Pdf.Text.TextFragment("Line2");
page.Paragraphs.Add(text);
text = new Aspose.Pdf.Text.TextFragment("Line3");
page.Paragraphs.Add(text);
text = new Aspose.Pdf.Text.TextFragment("Line4");
page.Paragraphs.Add(text);
text = new Aspose.Pdf.Text.TextFragment("Line5");
page.Paragraphs.Add(text);
document.Save(dataDir + "SubsequentIndent_out.pdf", Aspose.Pdf.SaveFormat.Pdf);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create document instance
Document doc = new Document();
// Add page to pages collection of PDF file
Page page1 = doc.Pages.Add();
// Create TextFragment instance
TextFragment tf = new TextFragment("Sample Text Fragment");
// Set horizontal alignment for TextFragment
tf.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;
// Create a textsegment with sample text
TextSegment segment = new TextSegment(" ... Text Segment 1...");
// Add segment to segments collection of TextFragment
tf.Segments.Add(segment);
// Create a new TextSegment
segment = new TextSegment("Link to Google");
// Add segment to segments collection of TextFragment
tf.Segments.Add(segment);
// Set hyperlink for TextSegment
segment.Hyperlink = new Aspose.Pdf.WebHyperlink("www.google.com");
// Set forground color for text segment
segment.TextState.ForegroundColor = Aspose.Pdf.Color.Blue;
// Set text formatting as italic
segment.TextState.FontStyle = FontStyles.Italic;
// Create another TextSegment object
segment = new TextSegment("TextSegment without hyperlink");
// Add segment to segments collection of TextFragment
tf.Segments.Add(segment);
// Add TextFragment to paragraphs collection of page object
page1.Paragraphs.Add(tf);
dataDir = dataDir + "AddHyperlinkToTextSegment_out.pdf";
// Save resulting PDF document.
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
PdfContentEditor editor = new PdfContentEditor();
editor.BindPdf(dataDir + "input.pdf");
LineInfo lineInfo = new LineInfo();
lineInfo.LineWidth = 2;
lineInfo.VerticeCoordinate = new float[] { 0, 0, 100, 100, 50, 100 };
lineInfo.Visibility = true;
editor.CreatePolygon(lineInfo, 1, new System.Drawing.Rectangle(0, 0, 0, 0), "");
dataDir = dataDir + "AddingBorderAroundAddedText_out.pdf";
// Save resulting PDF document.
editor.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
Aspose.Pdf.Document pdfApplicationDoc = new Aspose.Pdf.Document();
Aspose.Pdf.Page applicationFirstPage = (Aspose.Pdf.Page)pdfApplicationDoc.Pages.Add();
// Initialize new TextFragment with text containing required newline markers
Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("Applicant Name: " + Environment.NewLine + " Joe Smoe");
// Set text fragment properties if necessary
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("TimesNewRoman");
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
// Create TextParagraph object
TextParagraph par = new TextParagraph();
// Add new TextFragment to paragraph
par.AppendLine(textFragment);
// Set paragraph position
par.Position = new Aspose.Pdf.Text.Position(100, 600);
// Create TextBuilder object
TextBuilder textBuilder = new TextBuilder(applicationFirstPage);
// Add the TextParagraph using TextBuilder
textBuilder.AppendParagraph(par);
dataDir = dataDir + "AddNewLineFeed_out.pdf";
// Save resulting PDF document.
pdfApplicationDoc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document pdfDocument = new Document();
// Get particular page
Page pdfPage = (Page)pdfDocument.Pages.Add();
// Create text fragment
TextFragment textFragment = new TextFragment("main text");
textFragment.Position = new Position(100, 600);
// Set text properties
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman");
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
// Set StrikeOut property
textFragment.TextState.StrikeOut = true;
// Mark text as Bold
textFragment.TextState.FontStyle = FontStyles.Bold;
// Create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// Append the text fragment to the PDF page
textBuilder.AppendText(textFragment);
dataDir = dataDir + "AddStrikeOutText_out.pdf";
// Save resulting PDF document.
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Get particular page
Page pdfPage = (Page)pdfDocument.Pages[1];
// Create text fragment
TextFragment textFragment = new TextFragment("main text");
textFragment.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);
// Create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// Append the text fragment to the PDF page
textBuilder.AppendText(textFragment);
dataDir = dataDir + "AddText_out.pdf";
// Save resulting PDF document.
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document doc = new Document();
// Add page to pages collection of Document object
Page page = doc.Pages.Add();
TextBuilder builder = new TextBuilder(page);
// Create text paragraph
TextParagraph paragraph = new TextParagraph();
// Set subsequent lines indent
paragraph.SubsequentLinesIndent = 20;
// Specify the location to add TextParagraph
paragraph.Rectangle = new Aspose.Pdf.Rectangle(100, 300, 200, 700);
// Specify word wraping mode
paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;
// Create text fragment
TextFragment fragment1 = new TextFragment("the quick brown fox jumps over the lazy dog");
fragment1.TextState.Font = FontRepository.FindFont("Times New Roman");
fragment1.TextState.FontSize = 12;
// Add fragment to paragraph
paragraph.AppendLine(fragment1);
// Add paragraph
builder.AppendParagraph(paragraph);
dataDir = dataDir + "AddTextUsingTextParagraph_out.pdf";
// Save resulting PDF document.
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create documentation object
Document pdfDocument = new Document();
// Add age page to PDF document
pdfDocument.Pages.Add();
// Create TextBuilder for first page
TextBuilder tb = new TextBuilder(pdfDocument.Pages[1]);
// TextFragment with sample text
TextFragment fragment = new TextFragment("Test message");
// Set the font for TextFragment
fragment.TextState.Font = FontRepository.FindFont("Arial");
fragment.TextState.FontSize = 10;
// Set the formatting of text as Underline
fragment.TextState.Underline = true;
// Specify the position where TextFragment needs to be placed
fragment.Position = new Position(10, 800);
// Append TextFragment to PDF file
tb.AppendText(fragment);
dataDir = dataDir + "AddUnderlineText_out.pdf";
// Save resulting PDF document.
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
string fontFile = "";
// Load input PDF file
Document doc = new Document( dataDir + "input.pdf");
// Create text builder object for first page of document
TextBuilder textBuilder = new TextBuilder(doc.Pages[1]);
// Create text fragment with sample string
TextFragment textFragment = new TextFragment("Hello world");
if (fontFile != "")
{
// Load the TrueType font into stream object
using (FileStream fontStream = File.OpenRead(fontFile))
{
// Set the font name for text string
textFragment.TextState.Font = FontRepository.OpenFont(fontStream, FontTypes.TTF);
// Specify the position for Text Fragment
textFragment.Position = new Position(10, 10);
// Add the text to TextBuilder so that it can be placed over the PDF file
textBuilder.AppendText(textFragment);
}
dataDir = dataDir + "LoadingFontFromStream_out.pdf";
// Save resulting PDF document.
doc.Save(dataDir);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create new document instance
Document pdfDocument = new Document();
// Add page to pages collection of PDF file
Aspose.Pdf.Page page = pdfDocument.Pages.Add();
// Create TextFragment instnace with sample text
TextFragment fragment = new TextFragment("Sample Text in OTF font");
// Find font inside system font directory
// Fragment.TextState.Font = FontRepository.FindFont("HelveticaNeueLT Pro 45 Lt");
// Or you can even specify the path of OTF font in system directory
fragment.TextState.Font = FontRepository.OpenFont(dataDir + "space age.otf");
// Specify to emend font inside PDF file, so that its displayed properly,
// Even if specific font is not installed/present over target machine
fragment.TextState.Font.IsEmbedded = true;
// Add TextFragment to paragraphs collection of Page instance
page.Paragraphs.Add(fragment);
dataDir = dataDir + "OTFFont_out.pdf";
// Save resulting PDF document.
pdfDocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create new document object
Document pdfDocument = new Document();
// Get particular page
Page pdfPage = (Page)pdfDocument.Pages.Add();
// Create text fragment
TextFragment textFragment = new TextFragment("main text");
textFragment.Position = new Position(100, 600);
// Set text properties
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman");
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.LightGray;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
// Set StrokingColor property for drawing border (stroking) around text rectangle
textFragment.TextState.StrokingColor = Aspose.Pdf.Color.DarkRed;
// Set DrawTextRectangleBorder property value to true
textFragment.TextState.DrawTextRectangleBorder = true;
TextBuilder tb = new TextBuilder(pdfPage);
tb.AppendText(textFragment);
// Save the document
pdfDocument.Save(dataDir + "PDFWithTextBorder_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
using (Document pdfDocument = new Document(dataDir + "text_sample4.pdf"))
{
TextFragmentAbsorber absorber = new TextFragmentAbsorber("Lorem ipsum");
pdfDocument.Pages.Accept(absorber);
TextFragment textFragment = absorber.TextFragments[1];
// Create new color with pattern colorspace
textFragment.TextState.ForegroundColor = new Aspose.Pdf.Color()
{
PatternColorSpace = new Aspose.Pdf.Drawing.GradientAxialShading(Color.Red, Color.Blue)
};
textFragment.TextState.Underline = true;
pdfDocument.Save(dataDir + "text_out.pdf");
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
string outputFile = dataDir + "Tooltip_out.pdf";
// Create sample document with text
Document doc = new Document();
doc.Pages.Add().Paragraphs.Add(new TextFragment("Move the mouse cursor here to display a tooltip"));
doc.Pages[1].Paragraphs.Add(new TextFragment("Move the mouse cursor here to display a very long tooltip"));
doc.Save(outputFile);
// Open document with text
Document document = new Document(outputFile);
// Create TextAbsorber object to find all the phrases matching the regular expression
TextFragmentAbsorber absorber = new TextFragmentAbsorber("Move the mouse cursor here to display a tooltip");
// Accept the absorber for the document pages
document.Pages.Accept(absorber);
// Get the extracted text fragments
TextFragmentCollection textFragments = absorber.TextFragments;
// Loop through the fragments
foreach (TextFragment fragment in textFragments)
{
// Create invisible button on text fragment position
ButtonField field = new ButtonField(fragment.Page, fragment.Rectangle);
// AlternateName value will be displayed as tooltip by a viewer application
field.AlternateName = "Tooltip for text.";
// Add button field to the document
document.Form.Add(field);
}
// Next will be sapmle of very long tooltip
absorber = new TextFragmentAbsorber("Move the mouse cursor here to display a very long tooltip");
document.Pages.Accept(absorber);
textFragments = absorber.TextFragments;
foreach (TextFragment fragment in textFragments)
{
ButtonField field = new ButtonField(fragment.Page, fragment.Rectangle);
// Set very long text
field.AlternateName = "Lorem ipsum dolor sit amet, consectetur adipiscing elit," +
" sed do eiusmod tempor incididunt ut labore et dolore magna" +
" aliqua. Ut enim ad minim veniam, quis nostrud exercitation" +
" ullamco laboris nisi ut aliquip ex ea commodo consequat." +
" Duis aute irure dolor in reprehenderit in voluptate velit" +
" esse cillum dolore eu fugiat nulla pariatur. Excepteur sint" +
" occaecat cupidatat non proident, sunt in culpa qui officia" +
" deserunt mollit anim id est laborum.";
document.Form.Add(field);
}
// Save document
document.Save(outputFile);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create Document instance
Document doc = new Document();
// Create page to pages collection of PDF file
Aspose.Pdf.Page page = doc.Pages.Add();
// Create Graph object
Aspose.Pdf.Drawing.Graph canvas = new Aspose.Pdf.Drawing.Graph(100, 400);
// Create rectangle instance with certain dimensions
Aspose.Pdf.Drawing.Rectangle rect = new Aspose.Pdf.Drawing.Rectangle(100, 100, 400, 400);
// Create color object from Alpha color channel
rect.GraphInfo.FillColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(128, System.Drawing.Color.FromArgb(12957183)));
// Add rectanlge to shapes collection of Graph object
canvas.Shapes.Add(rect);
// Add graph object to paragraphs collection of page object
page.Paragraphs.Add(canvas);
// Set value to not change position for graph object
canvas.IsChangePosition = false;
// Create TextFragment instance with sample value
TextFragment text = new TextFragment("transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text transparent text ");
// Create color object from Alpha channel
Aspose.Pdf.Color color = Aspose.Pdf.Color.FromArgb(30, 0, 255, 0);
// Set color information for text instance
text.TextState.ForegroundColor = color;
// Add text to paragraphs collection of page instance
page.Paragraphs.Add(text);
dataDir = dataDir + "AddTransparentText_out.pdf";
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
Document doc = new Document();
// Specify the left margin info for the PDF file
doc.PageInfo.Margin.Left = 40;
// Specify the Right margin info for the PDF file
doc.PageInfo.Margin.Right = 40;
Page page = doc.Pages.Add();
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);
// 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";
box.ColumnInfo.ColumnWidths = "105 105";
TextFragment text1 = new TextFragment("By A Googler (The Official Google Blog)");
text1.TextState.FontSize = 8;
text1.TextState.LineSpacing = 2;
box.Paragraphs.Add(text1);
text1.TextState.FontSize = 10;
text1.TextState.FontStyle = FontStyles.Italic;
// Create a graphs object to draw a line
Aspose.Pdf.Drawing.Graph graph2 = new Aspose.Pdf.Drawing.Graph(50, 10);
// Specify the coordinates for the line
float[] posArr2 = new float[] { 1, 10, 100, 10 };
Aspose.Pdf.Drawing.Line l2 = new Aspose.Pdf.Drawing.Line(posArr2);
graph2.Shapes.Add(l2);
// Add the line to paragraphs collection of section object
box.Paragraphs.Add(graph2);
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.");
box.Paragraphs.Add(text2);
page.Paragraphs.Add(box);
dataDir = dataDir + "CreateMultiColumnPdf_out.pdf";
// Save PDF file
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
Document _pdfdocument = new Document();
Page page = _pdfdocument.Pages.Add();
Aspose.Pdf.Text.TabStops ts = new Aspose.Pdf.Text.TabStops();
Aspose.Pdf.Text.TabStop ts1 = ts.Add(100);
ts1.AlignmentType = TabAlignmentType.Right;
ts1.LeaderType = TabLeaderType.Solid;
Aspose.Pdf.Text.TabStop ts2 = ts.Add(200);
ts2.AlignmentType = TabAlignmentType.Center;
ts2.LeaderType = TabLeaderType.Dash;
Aspose.Pdf.Text.TabStop ts3 = ts.Add(300);
ts3.AlignmentType = TabAlignmentType.Left;
ts3.LeaderType = TabLeaderType.Dot;
TextFragment header = new TextFragment("This is a example of forming table with TAB stops", ts);
TextFragment text0 = new TextFragment("#$TABHead1 #$TABHead2 #$TABHead3", ts);
TextFragment text1 = new TextFragment("#$TABdata11 #$TABdata12 #$TABdata13", ts);
TextFragment text2 = new TextFragment("#$TABdata21 ", ts);
text2.Segments.Add(new TextSegment("#$TAB"));
text2.Segments.Add(new TextSegment("data22 "));
text2.Segments.Add(new TextSegment("#$TAB"));
text2.Segments.Add(new TextSegment("data23"));
page.Paragraphs.Add(header);
page.Paragraphs.Add(text0);
page.Paragraphs.Add(text1);
page.Paragraphs.Add(text2);
dataDir = dataDir + "CustomTabStops_out.pdf";
_pdfdocument.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
Document doc = new Document();
Page page = doc.Pages.Add();
for (int i = 0; i < 4; i++)
{
TextFragment text = new TextFragment("Lorem ipsum \r\ndolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
text.TextState.FontSize = 20;
page.Paragraphs.Add(text);
}
doc.Save(dataDir + "DetermineLineBreak_out.pdf");
string notifications = doc.Pages[1].GetNotifications();
File.WriteAllText(dataDir + "notifications_out.txt", notifications);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Load an existing PDF Document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Set EmbedStandardFonts property of document
pdfDocument.EmbedStandardFonts = true;
foreach (Aspose.Pdf.Page page in pdfDocument.Pages)
{
if (page.Resources.Fonts != null)
{
foreach (Aspose.Pdf.Text.Font pageFont in page.Resources.Fonts)
{
// Check if font is already embedded
if (!pageFont.IsEmbedded)
{
pageFont.IsEmbedded = true;
}
}
}
}
pdfDocument.Save(dataDir + "EmbeddedFonts-updated_out.pdf");
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document pdfDocument = new Document(dataDir + "ExtractTextPage.pdf");
TextFragmentAbsorber tfa = new TextFragmentAbsorber();
pdfDocument.Pages.Accept(tfa);
TextFragmentCollection tfc = tfa.TextFragments;
foreach (TextFragment tf in tfc)
{
// Need to reduce font size at least for 70%
tf.TextState.FontSize = tf.TextState.FontSize * 0.7f;
}
Stream st = new MemoryStream();
pdfDocument.Save(st);
pdfDocument = new Document(st);
TextAbsorber textAbsorber = new TextAbsorber();
pdfDocument.Pages.Accept(textAbsorber);
String extractedText = textAbsorber.Text;
textAbsorber.Visit(pdfDocument);
dataDir = dataDir + "ExtractColumnsText_out.txt";
System.IO.File.WriteAllText(dataDir, extractedText);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document pdfDocument = new Document(dataDir + "ExtractTextPage.pdf");
TextAbsorber textAbsorber = new TextAbsorber();
textAbsorber.ExtractionOptions = new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Pure);
// Setting scale factor to 0.5 is enough to split columns in the majority of documents
// Setting of zero allows to algorithm choose scale factor automatically
textAbsorber.ExtractionOptions.ScaleFactor = 0.5; /* 0; */
pdfDocument.Pages.Accept(textAbsorber);
String extractedText = textAbsorber.Text;
System.IO.File.WriteAllText( dataDir + "ExtractTextUsingScaleFactor_out.text", extractedText);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open an existing PDF file
Document doc = new Document(dataDir + "input.pdf");
// Instantiate ParagraphAbsorber
ParagraphAbsorber absorber = new ParagraphAbsorber();
absorber.Visit(doc);
foreach (PageMarkup markup in absorber.PageMarkups)
{
int i = 1;
foreach (MarkupSection section in markup.Sections)
{
int j = 1;
foreach (MarkupParagraph paragraph in section.Paragraphs)
{
StringBuilder paragraphText = new StringBuilder();
foreach (List<TextFragment> line in paragraph.Lines)
{
foreach (TextFragment fragment in line)
{
paragraphText.Append(fragment.Text);
}
paragraphText.Append("\r\n");
}
paragraphText.Append("\r\n");
Console.WriteLine("Paragraph {0} of section {1} on page {2}:", j, i, markup.Number);
Console.WriteLine(paragraphText.ToString());
j++;
}
i++;
}
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ExtractParagraph()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
Document doc = new Document(dataDir + "input.pdf");
Page page = doc.Pages[2];
ParagraphAbsorber absorber = new ParagraphAbsorber();
absorber.Visit(page);
PageMarkup markup = absorber.PageMarkups[0];
foreach (MarkupSection section in markup.Sections)
{
DrawRectangleOnPage(section.Rectangle, page);
foreach (MarkupParagraph paragraph in section.Paragraphs)
{
DrawPolygonOnPage(paragraph.Points, page);
}
}
doc.Save(dataDir + "output_out.pdf");
}
private static void DrawRectangleOnPage(Rectangle rectangle, Page page)
{
page.Contents.Add(new Aspose.Pdf.Operators.GSave());
page.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(1, 0, 0, 1, 0, 0));
page.Contents.Add(new Aspose.Pdf.Operators.SetRGBColorStroke(0, 1, 0));
page.Contents.Add(new Aspose.Pdf.Operators.SetLineWidth(2));
page.Contents.Add(
new Aspose.Pdf.Operators.Re(rectangle.LLX,
rectangle.LLY,
rectangle.Width,
rectangle.Height));
page.Contents.Add(new Aspose.Pdf.Operators.ClosePathStroke());
page.Contents.Add(new Aspose.Pdf.Operators.GRestore());
}
private static void DrawPolygonOnPage(Point[] polygon, Page page)
{
page.Contents.Add(new Aspose.Pdf.Operators.GSave());
page.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(1, 0, 0, 1, 0, 0));
page.Contents.Add(new Aspose.Pdf.Operators.SetRGBColorStroke(0, 0, 1));
page.Contents.Add(new Aspose.Pdf.Operators.SetLineWidth(1));
page.Contents.Add(new Aspose.Pdf.Operators.MoveTo(polygon[0].X, polygon[0].Y));
for (int i = 1; i < polygon.Length; i++)
{
page.Contents.Add(new Aspose.Pdf.Operators.LineTo(polygon[i].X, polygon[i].Y));
}
page.Contents.Add(new Aspose.Pdf.Operators.LineTo(polygon[0].X, polygon[0].Y));
page.Contents.Add(new Aspose.Pdf.Operators.ClosePathStroke());
page.Contents.Add(new Aspose.Pdf.Operators.GRestore());
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document pdfDocument = new Document(dataDir + "ExtractTextAll.pdf");
// Create TextAbsorber object to extract text
TextAbsorber textAbsorber = new TextAbsorber();
// Accept the absorber for all the pages
pdfDocument.Pages.Accept(textAbsorber);
// Get the extracted text
string extractedText = textAbsorber.Text;
// Create a writer and open the file
TextWriter tw = new StreamWriter(dataDir + "extracted-text.txt");
// Write a line of text to the file
tw.WriteLine(extractedText);
// Close the stream
tw.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document pdfDocument = new Document(dataDir + "ExtractTextAll.pdf");
// Create TextAbsorber object to extract text
TextAbsorber absorber = new TextAbsorber();
absorber.TextSearchOptions.LimitToPageBounds = true;
absorber.TextSearchOptions.Rectangle = new Aspose.Pdf.Rectangle(100, 200, 250, 350);
// Accept the absorber for first page
pdfDocument.Pages[1].Accept(absorber);
// Get the extracted text
string extractedText = absorber.Text;
// Create a writer and open the file
TextWriter tw = new StreamWriter(dataDir + "extracted-text.txt");
// Write a line of text to the file
tw.WriteLine(extractedText);
// Close the stream
tw.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document pdfDocument = new Document(dataDir + "ExtractTextPage.pdf");
// Create TextAbsorber object to extract text
TextAbsorber textAbsorber = new TextAbsorber();
// Accept the absorber for a particular page
pdfDocument.Pages[1].Accept(textAbsorber);
// Get the extracted text
string extractedText = textAbsorber.Text;
dataDir = dataDir + "extracted-text_out.txt";
// Create a writer and open the file
TextWriter tw = new StreamWriter(dataDir);
// Write a line of text to the file
tw.WriteLine(extractedText);
// Close the stream
tw.Close();
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Open document
Document pdfDocument = new Document( dataDir + "input.pdf");
System.Text.StringBuilder builder = new System.Text.StringBuilder();
// String to hold extracted text
string extractedText = "";
foreach (Page pdfPage in pdfDocument.Pages)
{
using (MemoryStream textStream = new MemoryStream())
{
// Create text device
TextDevice textDevice = new TextDevice();
// Set text extraction options - set text extraction mode (Raw or Pure)
TextExtractionOptions textExtOptions = new
TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Pure);
textDevice.ExtractionOptions = textExtOptions;
// Convert a particular page and save text to the stream
textDevice.Process(pdfPage, textStream);
// Convert a particular page and save text to the stream
textDevice.Process(pdfDocument.Pages[1], textStream);
// Close memory stream
textStream.Close();
// Get text from memory stream
extractedText = Encoding.Unicode.GetString(textStream.ToArray());
}
builder.Append(extractedText);
}
dataDir = dataDir + "input_Text_Extracted_out.txt";
// Save the extracted text in text file
File.WriteAllText(dataDir, builder.ToString());
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// Convert a particular page and save text to the stream
textDevice.Process(pdfDocument.Pages[1], textStream);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF
Page page = doc.Pages.Add();
// Create GraphInfo object
Aspose.Pdf.GraphInfo graph = new Aspose.Pdf.GraphInfo();
// Set line width as 2
graph.LineWidth = 2;
// Set the color for graph object
graph.Color = Aspose.Pdf.Color.Red;
// Set dash array value as 3
graph.DashArray = new int[] { 3 };
// Set dash phase value as 1
graph.DashPhase = 1;
// Set footnote line style for page as graph
page.NoteLineStyle = graph;
// Create TextFragment instance
TextFragment text = new TextFragment("Hello World");
// Set FootNote value for TextFragment
text.FootNote = new Note("foot note for test text 1");
// Add TextFragment to paragraphs collection of first page of document
page.Paragraphs.Add(text);
// Create second TextFragment
text = new TextFragment("Aspose.Pdf for .NET");
// Set FootNote for second text fragment
text.FootNote = new Note("foot note for test text 2");
// Add second text fragment to paragraphs collection of PDF file
page.Paragraphs.Add(text);
dataDir = dataDir + "AddFootNote_out.pdf";
// Save resulting PDF document.
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
Document doc = new Document();
Page page = doc.Pages.Add();
TextFragment text = new TextFragment("some text");
page.Paragraphs.Add(text);
text.FootNote = new Note();
Aspose.Pdf.Image image = new Aspose.Pdf.Image();
image.File = dataDir + "aspose-logo.jpg";
image.FixHeight = 20;
text.FootNote.Paragraphs.Add(image);
TextFragment footNote = new TextFragment("footnote text");
footNote.TextState.FontSize = 20;
footNote.IsInLineParagraph = true;
text.FootNote.Paragraphs.Add(footNote);
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
table.Rows.Add().Cells.Add().Paragraphs.Add(new TextFragment("Row 1 Cell 1"));
text.FootNote.Paragraphs.Add(table);
dataDir = dataDir + "AddImageAndTable_out.pdf";
// Save resulting PDF document.
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF
Page page = doc.Pages.Add();
// Create TextFragment instance
TextFragment text = new TextFragment("Hello World");
// Set FootNote value for TextFragment
text.EndNote = new Note("sample End note");
// Specify custom label for FootNote
text.EndNote.Text = " Aspose(2015)";
// Add TextFragment to paragraphs collection of first page of document
page.Paragraphs.Add(text);
dataDir = dataDir + "CreateEndNotes_out.pdf";
// Save resulting PDF document.
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF
Page page = doc.Pages.Add();
// Create GraphInfo object
Aspose.Pdf.GraphInfo graph = new Aspose.Pdf.GraphInfo();
// Set line width as 2
graph.LineWidth = 2;
// Set the color for graph object
graph.Color = Aspose.Pdf.Color.Red;
// Set dash array value as 3
graph.DashArray = new int[] { 3 };
// Set dash phase value as 1
graph.DashPhase = 1;
// Set footnote line style for page as graph
page.NoteLineStyle = graph;
// Create TextFragment instance
TextFragment text = new TextFragment("Hello World");
// Set FootNote value for TextFragment
text.FootNote = new Note("foot note for test text 1");
// Specify custom label for FootNote
text.FootNote.Text = " Aspose(2015)";
// Add TextFragment to paragraphs collection of first page of document
page.Paragraphs.Add(text);
dataDir = dataDir + "CustomizeFootNoteLabel_out.pdf";
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Create Document instance
Document doc = new Document();
// Add page to pages collection of PDF
Page page = doc.Pages.Add();
// Create GraphInfo object
Aspose.Pdf.GraphInfo graph = new Aspose.Pdf.GraphInfo();
// Set line width as 2
graph.LineWidth = 2;
// Set the color for graph object
graph.Color = Aspose.Pdf.Color.Red;
// Set dash array value as 3
graph.DashArray = new int[] { 3 };
// Set dash phase value as 1
graph.DashPhase = 1;
// Set footnote line style for page as graph
page.NoteLineStyle = graph;
// Create TextFragment instance
TextFragment text = new TextFragment("Hello World");
// Set FootNote value for TextFragment
text.FootNote = new Note("foot note for test text 1");
// Add TextFragment to paragraphs collection of first page of document
page.Paragraphs.Add(text);
// Create second TextFragment
text = new TextFragment("Aspose.Pdf for .NET");
// Set FootNote for second text fragment
text.FootNote = new Note("foot note for test text 2");
// Add second text fragment to paragraphs collection of PDF file
page.Paragraphs.Add(text);
dataDir = dataDir + "CustomLineStyleForFootNote_out.pdf";
// Save resulting PDF document.
doc.Save(dataDir);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
string outputFile = dataDir + "TextBlock_HideShow_MouseOverOut_out.pdf";
// Create sample document with text
Document doc = new Document();
doc.Pages.Add().Paragraphs.Add(new TextFragment("Move the mouse cursor here to display floating text"));
doc.Save(outputFile);
// Open document with text
Document document = new Document(outputFile);
// Create TextAbsorber object to find all the phrases matching the regular expression
TextFragmentAbsorber absorber = new TextFragmentAbsorber("Move the mouse cursor here to display floating text");
// Accept the absorber for the document pages
document.Pages.Accept(absorber);
// Get the first extracted text fragment
TextFragmentCollection textFragments = absorber.TextFragments;
TextFragment fragment = textFragments[1];
// Create hidden text field for floating text in the specified rectangle of the page
TextBoxField floatingField = new TextBoxField(fragment.Page, new Rectangle(100, 700, 220, 740));
// Set text to be displayed as field value
floatingField.Value = "This is the \"floating text field\".";
// We recommend to make field 'readonly' for this scenario
floatingField.ReadOnly = true;
// Set 'hidden' flag to make field invisible on document opening
floatingField.Flags |= AnnotationFlags.Hidden;
// Setting a unique field name isn't necessary but allowed
floatingField.PartialName = "FloatingField_1";
// Setting characteristics of field appearance isn't necessary but makes it better
floatingField.DefaultAppearance = new DefaultAppearance("Helv", 10, System.Drawing.Color.Blue);
floatingField.Characteristics.Background = System.Drawing.Color.LightBlue;
floatingField.Characteristics.Border = System.Drawing.Color.DarkBlue;
floatingField.Border = new Border(floatingField);
floatingField.Border.Width = 1;
floatingField.Multiline = true;
// Add text field to the document
document.Form.Add(floatingField);
// Create invisible button on text fragment position
ButtonField buttonField = new ButtonField(fragment.Page, fragment.Rectangle);
// Create new hide action for specified field (annotation) and invisibility flag.
// (You also may reffer floating field by the name if you specified it above.)
// Add actions on mouse enter/exit at the invisible button field
buttonField.Actions.OnEnter = new HideAction(floatingField, false);
buttonField.Actions.OnExit = new HideAction(floatingField);
// Add button field to the document
document.Form.Add(buttonField);
// Save document
document.Save(outputFile);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
int resolution = 150;
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(dataDir + "input.pdf");
using (MemoryStream ms = new MemoryStream())
{
PdfConverter conv = new PdfConverter(pdfDocument);
conv.Resolution = new Resolution(resolution, resolution);
conv.GetNextImage(ms, System.Drawing.Imaging.ImageFormat.Png);
Bitmap bmp = (Bitmap)Bitmap.FromStream(ms);
using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp))
{
float scale = resolution / 72f;
gr.Transform = new System.Drawing.Drawing2D.Matrix(scale, 0, 0, -scale, 0, bmp.Height);
for (int i = 0; i < pdfDocument.Pages.Count; i++)
{
Page page = pdfDocument.Pages[1];
// Create TextAbsorber object to find all words
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@"[\S]+");
textFragmentAbsorber.TextSearchOptions.IsRegularExpressionUsed = true;
page.Accept(textFragmentAbsorber);
// Get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
// Loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
if (i == 0)
{
gr.DrawRectangle(
Pens.Yellow,
(float)textFragment.Position.XIndent,
(float)textFragment.Position.YIndent,
(float)textFragment.Rectangle.Width,
(float)textFragment.Rectangle.Height);
for (int segNum = 1; segNum <= textFragment.Segments.Count; segNum++)
{
TextSegment segment = textFragment.Segments[segNum];
for (int charNum = 1; charNum <= segment.Characters.Count; charNum++)
{
CharInfo characterInfo = segment.Characters[charNum];
Aspose.Pdf.Rectangle rect = page.GetPageRect(true);
Console.WriteLine("TextFragment = " + textFragment.Text + " Page URY = " + rect.URY +
" TextFragment URY = " + textFragment.Rectangle.URY);
gr.DrawRectangle(
Pens.Black,
(float)characterInfo.Rectangle.LLX,
(float)characterInfo.Rectangle.LLY,
(float)characterInfo.Rectangle.Width,
(float)characterInfo.Rectangle.Height);
}
gr.DrawRectangle(
Pens.Green,
(float)segment.Rectangle.LLX,
(float)segment.Rectangle.LLY,
(float)segment.Rectangle.Width,
(float)segment.Rectangle.Height);
}
}
}
}
}
dataDir = dataDir + "HighlightCharacterInPDF_out.png";
bmp.Save(dataDir, System.Drawing.Imaging.ImageFormat.Png);
}
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
Document doc = new Document(dataDir + "MultiColumnPdf.pdf");
ParagraphAbsorber absorber = new ParagraphAbsorber();
absorber.Visit(doc);
PageMarkup markup = absorber.PageMarkups[0];
Console.WriteLine("IsMulticolumnParagraphsAllowed == false\r\n");
MarkupSection section = markup.Sections[2];
MarkupParagraph paragraph = section.Paragraphs[section.Paragraphs.Count - 1];
Console.WriteLine("Section at {0} last paragraph text:\r\n", section.Rectangle.ToString());
Console.WriteLine(paragraph.Text);
section = markup.Sections[1];
paragraph = section.Paragraphs[0];
Console.WriteLine("\r\nSection at {0} first paragraph text:\r\n", section.Rectangle.ToString());
Console.WriteLine(paragraph.Text);
markup.IsMulticolumnParagraphsAllowed = true;
Console.WriteLine("\r\nIsMulticolumnParagraphsAllowed == true\r\n");
section = markup.Sections[2];
paragraph = section.Paragraphs[section.Paragraphs.Count - 1];
Console.WriteLine("Section at {0} last paragraph text:\r\n", section.Rectangle.ToString());
Console.WriteLine(paragraph.Text);
section = markup.Sections[1];
paragraph = section.Paragraphs[0];
Console.WriteLine("\r\nSection at {0} first paragraph text:\r\n", section.Rectangle.ToString());
Console.WriteLine(paragraph.Text);
// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_AsposePdf_Text();
// Instantiate document object
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
// Create a page in the Pdf
Aspose.Pdf.Page page = doc.Pages.Add();
// Instantiate a table object
Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();
// Add the table in paragraphs collection of the desired section
page.Paragraphs.Add(table1);
// Set with column widths of the table
table1.ColumnWidths = "120 270";
// Create MarginInfo object and set its left, bottom, right and top margins
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
// Set the default cell padding to the MarginInfo object
table1.DefaultCellPadding = margin;
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row row1 = table1.Rows.Add();
// Create an image object
Aspose.Pdf.Image logo = new Aspose.Pdf.Image();
// Specify the image file path
logo.File = dataDir + "aspose-logo.jpg";
// Specify the image Fixed Height
logo.FixHeight = 120;
// Specify the image Fixed Width
logo.FixWidth = 110;
row1.Cells.Add();
// Add the image to paragraphs collection of the table cell
row1.Cells[0].Paragraphs.Add(logo);
// Create string variables with text containing html tags
string TitleString = "<font face=\"Arial\" size=6 color=\"#101090\"><b> Aspose.Pdf for .NET</b></font>";
string BodyString1 = "<font face=\"Arial\" size=2><br/>Aspose.Pdf for .NET is a non-graphical PDF� document reporting component that enables .NET applications to <b> create PDF documents from scratch </b> without utilizing Adobe Acrobat�. Aspose.Pdf for .NET is very affordably priced and offers a wealth of strong features including: compression, tables, graphs, images, hyperlinks, security and custom fonts. </font>";
// Create a text object to be added to the right of image
Aspose.Pdf.HtmlFragment TitleText = new Aspose.Pdf.HtmlFragment(TitleString + BodyString1);
row1.Cells.Add();
// Add the text paragraphs containing HTML text to the table cell
row1.Cells[1].Paragraphs.Add(TitleText);
// Set the vertical alignment of the row contents as Top
row1.Cells[1].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
// Create rows in the table and then cells in the rows
Aspose.Pdf.Row SecondRow = table1.Rows.Add();
SecondRow.Cells.Add();
// Set the row span value for Second row as 2
SecondRow.Cells[0].ColSpan = 2;
// Set the vertical alignment of the second row as Top
SecondRow.Cells[0].VerticalAlignment = Aspose.Pdf.VerticalAlignment.Top;
string SecondRowString = "<font face=\"Arial\" size=2>Aspose.Pdf for .NET supports the creation of PDF files through API and XML or XSL-FO templates. Aspose.Pdf for .NET is very easy to use and is provided with 14 fully featured demos written in both C# and Visual Basic.</font>";
Aspose.Pdf.HtmlFragment SecondRowText = new Aspose.Pdf.HtmlFragment(SecondRowString);
// Add the text paragraphs containing HTML text to the table cell
SecondRow.Cells[0].Paragraphs.Add(SecondRowText);
// Save the Pdf file
doc.Save(dataDir + "PlacingTextAroundImage_out.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment