public ActionResult ReplaceFonts(string Browser, string submit1) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("ReplaceFont.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument ldoc = new PdfLoadedDocument(file2); return(ldoc.ExportAsActionResult("InputTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } //Load an existing PDF. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(ResolveApplicationDataPath("ReplaceFont.pdf")); //Replace font loadedDocument.UsedFonts[0].Replace(new PdfTrueTypeFont(new Font("Monotype Corsiva", 12, FontStyle.Regular), false)); //Stream the output to the browser. if (Browser == "Browser") { return(loadedDocument.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(loadedDocument.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
public ActionResult RearrangePages(string Browser, string submit1) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("SyncfusionBrochure.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument loadedDocument = new PdfLoadedDocument(file2); return(loadedDocument.ExportAsActionResult("InputTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } //Load the input PDF document PdfLoadedDocument ldoc = new PdfLoadedDocument(ResolveApplicationDataPath("SyncfusionBrochure.pdf")); //Rearrange the page by index ldoc.Pages.ReArrange(new int[] { 2, 0, 1 }); //Stream the output to the browser. if (Browser == "Browser") { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
public ActionResult PdfA1bConverter(string Browser, HttpPostedFileBase file = null) { if (file != null && file.ContentLength > 0) { //Load an existing PDF. PdfLoadedDocument doc = new PdfLoadedDocument(file.InputStream); //Set the conformance for PDF/A-1b conversion. doc.Conformance = PdfConformanceLevel.Pdf_A1B; string[] fileName = file.FileName.Split(new string[] { ".pdf" }, StringSplitOptions.RemoveEmptyEntries); //Stream the output to the browser. if (Browser == "Browser") { return(doc.ExportAsActionResult(fileName[0] + "_A1b.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(doc.ExportAsActionResult(fileName[0] + "_A1b.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } else { ViewBag.lab = "Choose a valid PDF file."; return(View()); } }
public ActionResult ImageExtraction(string Browser, string submit1) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("Brochure.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument ldoc = new PdfLoadedDocument(file2); return(ldoc.ExportAsActionResult("InputTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } //Load an existing PDF. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(ResolveApplicationDataPath("Brochure.pdf")); //Load first page. PdfPageBase pageBase = loadedDocument.Pages[0]; //Extract images from first page. System.Drawing.Image[] extractedImages = pageBase.ExtractImages(); //Stream the output to the browser. if (Browser == "Browser") { ExportAsImage(extractedImages[0], "sample.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response, HttpReadType.Open); } else { ExportAsImage(extractedImages[0], "sample.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response, HttpReadType.Save); } return(View()); }
public ActionResult ExportasImage(string Browser, string submit1) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("MultiColumnReports.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument ldoc = new PdfLoadedDocument(file2); return(ldoc.ExportAsActionResult("InputTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } //Loaded input pdf file. loadedDocument = new PdfLoadedDocument(ResolveApplicationDataPath("MultiColumnReports.pdf")); //Exporting specify page index as image. Bitmap image = loadedDocument.ExportAsImage(0); //Stream the output to the browser. if (Browser == "Browser") { ExportAsImage(image, "sample.jpeg", ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response, HttpReadType.Open); } else { ExportAsImage(image, "sample.jpeg", ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response, HttpReadType.Save); } return(View()); }
public ActionResult RemoveImages(string viewTemplate, string removeImage, HttpPostedFileBase file) { if (viewTemplate == "View Template") { string dataPath = ResolveApplicationDataPath("RemoveImage.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument doc = new PdfLoadedDocument(file2); return(doc.ExportAsActionResult("RemoveImageTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else if (removeImage == "Remove Images") { string dataPath = ResolveApplicationDataPath("RemoveImage.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument doc = new PdfLoadedDocument(file2); PdfImageInfo[] imagesInfo = doc.Pages[0].ImagesInfo; foreach (PdfImageInfo imgInfo in imagesInfo) { //Removing Image doc.Pages[0].RemoveImage(imgInfo); } return(doc.ExportAsActionResult("RemoveImage.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }
public ActionResult Redaction(string Browser, string x, string y, string width, string height, HttpPostedFileBase file) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); float x1; float y1; float width1; float height1; if (x != null && x.Length > 0 && float.TryParse(x.ToString(), out x1) && y != null && y.Length > 0 && float.TryParse(y.ToString(), out y1) && width != null && width.Length > 0 && float.TryParse(width.ToString(), out width1) && height != null && height.Length > 0 && float.TryParse(height.ToString(), out height1)) { //Load a PDF document PdfLoadedDocument ldoc = new PdfLoadedDocument(file.InputStream); //Get first page from document PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage; //Create PDF redaction for the page PdfRedaction redaction = new PdfRedaction(new RectangleF(x1, y1, width1, height1), Color.Black); //Adds the redaction to loaded page lpage.Redactions.Add(redaction); //Save to disk if (Browser == "Browser") { return(ldoc.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(ldoc.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } else { ViewBag.lab = "Fill proper redaction bounds to redact"; } } else { ViewBag.lab = "Choose PDF document to redact"; } return(View()); }
public ActionResult PdfToPdfAConverter(string Browser, string conformance, HttpPostedFileBase file = null) { if (file != null && file.ContentLength > 0) { //Load an existing PDF. PdfLoadedDocument doc = new PdfLoadedDocument(file.InputStream); if (conformance == "PDF/A-1b") { //Create a new document with PDF/A standard. doc.Conformance = PdfConformanceLevel.Pdf_A1B; } else if (conformance == "PDF/A-2b") { //Create a new document with PDF/A standard. doc.Conformance = PdfConformanceLevel.Pdf_A2B; } else if (conformance == "PDF/A-3b") { //Create a new document with PDF/A standard. doc.Conformance = PdfConformanceLevel.Pdf_A3B; } string[] fileName = file.FileName.Split(new string[] { ".pdf" }, StringSplitOptions.RemoveEmptyEntries); //Stream the output to the browser. if (Browser == "Browser") { return(doc.ExportAsActionResult(fileName[0] + "_A.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(doc.ExportAsActionResult(fileName[0] + "_A.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } else { ViewBag.lab = "Choose a valid PDF file."; ViewData.Add("conformance", new SelectList(new string[] { "PDF/A-1b", "PDF/A-2b", "PDF/A-3b" })); return(View()); } }
public ActionResult ReplaceImages(string Browser, string submit1) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("imageDoc.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument ldoc = new PdfLoadedDocument(file2); return(ldoc.ExportAsActionResult("InputTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } //Load the PDF document PdfLoadedDocument doc = new PdfLoadedDocument(ResolveApplicationDataPath("imageDoc.pdf")); //Create an image instance PdfBitmap bmp = new PdfBitmap(ResolveApplicationImagePath("Essen PDF.gif")); //Replace the first image in the page. doc.Pages[0].ReplaceImage(2, bmp); bmp = new PdfBitmap(ResolveApplicationImagePath("Essen DocIO.gif")); doc.Pages[1].ReplaceImage(0, bmp); bmp = new PdfBitmap(ResolveApplicationImagePath("Essen XlsIO.gif")); doc.Pages[1].ReplaceImage(1, bmp); //Stream the output to the browser. if (Browser == "Browser") { return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
public ActionResult AnnotationFlatten(string InsideBrowser, string checkboxFlatten) { //Creates a new PDF document. PdfDocument document = new PdfDocument(); //Creates a new page PdfPage page = document.Pages.Add(); document.PageSettings.SetMargins(0); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f); PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.Black); string text = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base."; page.Graphics.DrawString("Annotation with Comments and Reviews", font, brush, new PointF(30, 10)); page.Graphics.DrawString(text, font, brush, new RectangleF(30, 40, page.GetClientSize().Width - 60, 60)); string markupText = "North American, European and Asian commercial markets"; PdfTextMarkupAnnotation textMarkupAnnot = new PdfTextMarkupAnnotation("sample", "Highlight", markupText, new PointF(147, 63.5f), font); textMarkupAnnot.Author = "Annotation"; textMarkupAnnot.Opacity = 1.0f; textMarkupAnnot.Subject = "Comments and Reviews"; textMarkupAnnot.ModifiedDate = new DateTime(2015, 1, 18); textMarkupAnnot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.Highlight; textMarkupAnnot.TextMarkupColor = new PdfColor(Color.Yellow); textMarkupAnnot.InnerColor = new PdfColor(Color.Red); textMarkupAnnot.Color = new PdfColor(Color.Yellow); if (checkboxFlatten == "Flatten") { textMarkupAnnot.Flatten = true; } //Create a new comment. PdfPopupAnnotation userQuery = new PdfPopupAnnotation(); userQuery.Author = "John"; userQuery.Text = "Can you please change South Asian to Asian?"; userQuery.ModifiedDate = new DateTime(2015, 1, 18); //Add comment to the annotation textMarkupAnnot.Comments.Add(userQuery); //Creates a new comment PdfPopupAnnotation userAnswer = new PdfPopupAnnotation(); userAnswer.Author = "Smith"; userAnswer.Text = "South Asian has changed as Asian"; userAnswer.ModifiedDate = new DateTime(2015, 1, 18); //Add comment to the annotation textMarkupAnnot.Comments.Add(userAnswer); //Creates a new review PdfPopupAnnotation userAnswerReview = new PdfPopupAnnotation(); userAnswerReview.Author = "Smith"; userAnswerReview.State = PdfAnnotationState.Completed; userAnswerReview.StateModel = PdfAnnotationStateModel.Review; userAnswerReview.ModifiedDate = new DateTime(2015, 1, 18); //Add review to the comment userAnswer.ReviewHistory.Add(userAnswerReview); //Creates a new review PdfPopupAnnotation userAnswerReviewJohn = new PdfPopupAnnotation(); userAnswerReviewJohn.Author = "John"; userAnswerReviewJohn.State = PdfAnnotationState.Accepted; userAnswerReviewJohn.StateModel = PdfAnnotationStateModel.Review; userAnswerReviewJohn.ModifiedDate = new DateTime(2015, 1, 18); //Add review to the comment userAnswer.ReviewHistory.Add(userAnswerReviewJohn); //Add annotation to the page page.Annotations.Add(textMarkupAnnot); RectangleF bounds = new RectangleF(350, 170, 80, 80); //Creates a new Circle annotation. PdfCircleAnnotation circleannotation = new PdfCircleAnnotation(bounds); circleannotation.InnerColor = new PdfColor(Color.Yellow); circleannotation.Color = new PdfColor(Color.Red); circleannotation.AnnotationFlags = PdfAnnotationFlags.Default; circleannotation.Author = "Syncfusion"; circleannotation.Subject = "CircleAnnotation"; circleannotation.ModifiedDate = new DateTime(2015, 1, 18); page.Annotations.Add(circleannotation); page.Graphics.DrawString("Circle Annotation", font, brush, new PointF(350, 130)); //Creates a new Ellipse annotation. PdfEllipseAnnotation ellipseannotation = new PdfEllipseAnnotation(new RectangleF(30, 150, 50, 100), "Ellipse Annotation"); ellipseannotation.Color = new PdfColor(Color.Red); ellipseannotation.InnerColor = new PdfColor(Color.Yellow); page.Graphics.DrawString("Ellipse Annotation", font, brush, new PointF(30, 130)); page.Annotations.Add(ellipseannotation); //Creates a new Square annotation. PdfSquareAnnotation squareannotation = new PdfSquareAnnotation(new RectangleF(30, 300, 80, 80)); squareannotation.Text = "SquareAnnotation"; squareannotation.InnerColor = new PdfColor(Color.Red); squareannotation.Color = new PdfColor(Color.Yellow); page.Graphics.DrawString("Square Annotation", font, brush, new PointF(30, 280)); page.Annotations.Add(squareannotation); //Creates a new Rectangle annotation. RectangleF rectannot = new RectangleF(350, 320, 100, 50); PdfRectangleAnnotation rectangleannotation = new PdfRectangleAnnotation(rectannot, "RectangleAnnotation"); rectangleannotation.InnerColor = new PdfColor(Color.Red); rectangleannotation.Color = new PdfColor(Color.Yellow); page.Graphics.DrawString("Rectangle Annotation", font, brush, new PointF(350, 280)); page.Annotations.Add(rectangleannotation); //Creates a new Line annotation. int[] points = new int[] { 400, 350, 550, 350 }; PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annoation is the one of the annotation type..."); lineAnnotation.Author = "Syncfusion"; lineAnnotation.Subject = "LineAnnotation"; lineAnnotation.ModifiedDate = new DateTime(2015, 1, 18); lineAnnotation.Text = "PdfLineAnnotation"; lineAnnotation.BackColor = new PdfColor(Color.Red); page.Graphics.DrawString("Line Annotation", font, brush, new PointF(400, 420)); page.Annotations.Add(lineAnnotation); //Creates a new Polygon annotation. int[] polypoints = new int[] { 50, 298, 100, 325, 200, 355, 300, 230, 180, 230 }; PdfPolygonAnnotation polygonannotation = new PdfPolygonAnnotation(polypoints, "PolygonAnnotation"); polygonannotation.Bounds = new RectangleF(30, 210, 300, 200); PdfPen pen = new PdfPen(Color.Red); polygonannotation.Text = "polygon"; polygonannotation.Color = new PdfColor(Color.Red); polygonannotation.InnerColor = new PdfColor(Color.LightPink); page.Graphics.DrawString("Polygon Annotation", font, brush, new PointF(50, 420)); page.Annotations.Add(polygonannotation); //Creates a new Freetext annotation. RectangleF freetextrect = new RectangleF(405, 645, 80, 30); PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(freetextrect); freeText.MarkupText = "Free Text with Callouts"; freeText.TextMarkupColor = new PdfColor(Color.Green); freeText.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); freeText.BorderColor = new PdfColor(Color.Blue); freeText.Border = new PdfAnnotationBorder(.5f); freeText.AnnotationFlags = PdfAnnotationFlags.Default; freeText.Text = "Free Text"; freeText.Color = new PdfColor(Color.Yellow); PointF[] Freetextpoints = { new PointF(365, 700), new PointF(379, 654), new PointF(405, 654) }; freeText.CalloutLines = Freetextpoints; page.Graphics.DrawString("FreeText Annotation", font, brush, new PointF(400, 610)); page.Annotations.Add(freeText); //Creates a new Ink annotation. List <float> linePoints = new List <float> { 72.919f, 136.376f, 72.264f, 136.376f, 62.446f, 142.922f, 61.137f, 142.922f, 55.901f, 139.649f, 55.246f, 138.34f, 54.592f, 132.449f, 54.592f, 127.867f, 55.901f, 125.904f, 59.828f, 121.976f, 63.101f, 121.322f, 65.719f, 122.631f, 68.992f, 125.249f, 70.301f, 130.485f, 71.61f, 133.104f, 72.264f, 136.376f, 72.919f, 140.304f, 74.883f, 144.885f, 76.192f, 150.776f, 76.192f, 151.431f, 76.192f, 152.085f, 76.192f, 158.631f, 76.192f, 159.94f, 75.537f, 155.358f, 74.228f, 150.122f, 74.228f, 146.195f, 73.574f, 141.613f, 73.574f, 137.685f, 74.228f, 132.449f, 74.883f, 128.522f, 75.537f, 124.594f, 76.192f, 123.285f, 76.846f, 122.631f, 80.774f, 122.631f, 82.737f, 123.285f, 85.355f, 125.249f, 88.628f, 129.831f, 89.283f, 133.104f, 89.937f, 137.031f, 90.592f, 140.958f, 89.937f, 142.267f, 86.665f, 141.613f, 85.355f, 140.304f, 84.701f, 138.34f, 84.701f, 137.685f, 85.355f, 137.031f, 87.974f, 135.722f, 90.592f, 136.376f, 92.555f, 137.031f, 96.483f, 139.649f, 98.446f, 140.958f, 101.719f, 142.922f, 103.028f, 142.922f, 100.41f, 138.34f, 99.756f, 134.413f, 99.101f, 131.14f, 99.101f, 128.522f, 99.756f, 127.213f, 101.065f, 125.904f, 102.374f, 123.94f, 103.683f, 123.94f, 107.61f, 125.904f, 110.228f, 129.831f, 114.156f, 135.067f, 117.428f, 140.304f, 119.392f, 143.576f, 121.356f, 144.231f, 122.665f, 144.231f, 123.974f, 142.267f, 126.592f, 139.649f, 127.247f, 140.304f, 126.592f, 142.922f, 124.628f, 143.576f, 122.01f, 142.922f, 118.083f, 141.613f, 114.81f, 136.376f, 114.81f, 131.14f, 113.501f, 127.213f, 114.156f, 125.904f, 118.083f, 125.904f, 120.701f, 126.558f, 123.319f, 130.485f, 125.283f, 136.376f, 125.937f, 140.304f, 125.937f, 142.922f, 126.592f, 143.576f, 125.937f, 135.722f, 125.937f, 131.794f, 125.937f, 131.14f, 127.247f, 129.176f, 129.21f, 127.213f, 131.828f, 127.213f, 134.447f, 128.522f, 136.41f, 136.376f, 139.028f, 150.122f, 141.647f, 162.558f, 140.992f, 163.213f, 138.374f, 160.595f, 135.756f, 153.395f, 135.101f, 148.158f, 134.447f, 140.304f, 134.447f, 130.485f, 133.792f, 124.594f, 133.792f, 115.431f, 133.792f, 110.194f, 133.792f, 105.612f, 134.447f, 105.612f, 137.065f, 110.194f, 137.719f, 116.74f, 139.028f, 120.013f, 139.028f, 123.94f, 137.719f, 127.213f, 135.756f, 130.485f, 134.447f, 130.485f, 133.792f, 130.485f, 137.719f, 131.794f, 141.647f, 135.722f, 146.883f, 142.922f, 152.774f, 153.395f, 153.428f, 159.286f, 150.156f, 159.94f, 147.537f, 156.667f, 146.883f, 148.813f, 146.883f, 140.958f, 146.883f, 134.413f, 146.883f, 125.904f, 145.574f, 118.703f, 145.574f, 114.776f, 145.574f, 112.158f, 146.228f, 111.503f, 147.537f, 111.503f, 148.192f, 112.158f, 150.156f, 112.812f, 150.81f, 113.467f, 152.119f, 114.776f, 154.083f, 117.394f, 155.392f, 119.358f, 156.701f, 120.667f, 157.356f, 121.976f, 156.701f, 121.322f, 156.047f, 120.013f, 155.392f, 119.358f, 154.083f, 117.394f, 154.083f, 116.74f, 152.774f, 114.776f, 152.119f, 114.121f, 150.81f, 113.467f, 149.501f, 113.467f, 147.537f, 112.158f, 146.883f, 112.158f, 145.574f, 111.503f, 144.919f, 112.158f, 144.265f, 114.121f, 144.265f, 115.431f, 144.265f, 116.74f, 144.265f, 117.394f, 144.265f, 118.049f, 144.919f, 118.703f, 145.574f, 120.667f, 146.228f, 122.631f, 147.537f, 123.285f, 147.537f, 124.594f, 148.192f, 125.904f, 147.537f, 128.522f, 147.537f, 129.176f, 147.537f, 130.485f, 147.537f, 132.449f, 147.537f, 134.413f, 147.537f, 136.376f, 147.537f, 138.34f, 147.537f, 138.994f, 145.574f, 138.994f, 142.956f, 138.252f }; RectangleF rectangle = new RectangleF(30, 580, 300, 400); PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints); inkAnnotation.Bounds = rectangle; inkAnnotation.Color = new PdfColor(Color.Red); page.Graphics.DrawString("Ink Annotation", font, brush, new PointF(30, 610)); page.Annotations.Add(inkAnnotation); PdfPage secondPage = document.Pages.Add(); //Creates a new TextMarkup annotation. string s = "This is TextMarkup annotation!!!"; secondPage.Graphics.DrawString(s, font, brush, new PointF(30, 70)); PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation("sample", "Strikeout", s, new PointF(30, 70), font); textannot.Author = "Annotation"; textannot.Opacity = 1.0f; textannot.Subject = "pdftextmarkupannotation"; textannot.ModifiedDate = new DateTime(2015, 1, 18); textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.StrikeOut; textannot.TextMarkupColor = new PdfColor(Color.Yellow); textannot.InnerColor = new PdfColor(Color.Red); textannot.Color = new PdfColor(Color.Yellow); if (checkboxFlatten == "Flatten") { textannot.Flatten = true; } secondPage.Graphics.DrawString("TextMarkup Annotation", font, brush, new PointF(30, 40)); secondPage.Annotations.Add(textannot); //Creates a new popup annotation. RectangleF popupRect = new RectangleF(430, 70, 30, 30); PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(); popupAnnotation.Border.Width = 4; popupAnnotation.Border.HorizontalRadius = 20; popupAnnotation.Border.VerticalRadius = 30; popupAnnotation.Opacity = 1; popupAnnotation.Open = true; popupAnnotation.Text = "Popup Annotation"; popupAnnotation.Color = Color.Green; popupAnnotation.InnerColor = Color.Blue; popupAnnotation.Bounds = popupRect; if (checkboxFlatten == "Flatten") { popupAnnotation.FlattenPopUps = true; popupAnnotation.Flatten = true; } secondPage.Graphics.DrawString("Popup Annotation", font, brush, new PointF(400, 40)); secondPage.Annotations.Add(popupAnnotation); //Creates a new Line measurement annotation. points = new int[] { 400, 630, 550, 630 }; PdfLineMeasurementAnnotation lineMeasureAnnot = new PdfLineMeasurementAnnotation(points); lineMeasureAnnot.Author = "Syncfusion"; lineMeasureAnnot.Subject = "LineAnnotation"; lineMeasureAnnot.ModifiedDate = new DateTime(2015, 1, 18); lineMeasureAnnot.Unit = PdfMeasurementUnit.Inch; lineMeasureAnnot.lineBorder.BorderWidth = 2; lineMeasureAnnot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular); lineMeasureAnnot.Color = new PdfColor(Color.Red); if (checkboxFlatten == "Flatten") { lineMeasureAnnot.Flatten = true; } secondPage.Graphics.DrawString("Line Measurement Annotation", font, brush, new PointF(370, 130)); secondPage.Annotations.Add(lineMeasureAnnot); //Creates a new Freetext annotation. RectangleF freetextrect0 = new RectangleF(80, 160, 100, 50); PdfFreeTextAnnotation freeText0 = new PdfFreeTextAnnotation(freetextrect0); freeText0.MarkupText = "Free Text with Callouts"; freeText0.TextMarkupColor = new PdfColor(Color.Green); freeText0.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); freeText0.BorderColor = new PdfColor(Color.Blue); freeText0.Border = new PdfAnnotationBorder(.5f); freeText0.AnnotationFlags = PdfAnnotationFlags.Default; freeText0.Text = "Free Text"; freeText0.Rotate = PdfAnnotationRotateAngle.RotateAngle90; freeText0.Color = new PdfColor(Color.Yellow); PointF[] Freetextpoints0 = { new PointF(45, 220), new PointF(60, 175), new PointF(80, 175) }; freeText0.CalloutLines = Freetextpoints0; secondPage.Graphics.DrawString("Rotated FreeText Annotation", font, brush, new PointF(40, 130)); if (checkboxFlatten == "Flatten") { freeText0.Flatten = true; } secondPage.Annotations.Add(freeText0); MemoryStream SourceStream = new MemoryStream(); document.Save(SourceStream); document.Close(true); //Creates a new Loaded document. PdfLoadedDocument lDoc = new PdfLoadedDocument(SourceStream); PdfLoadedPage lpage1 = lDoc.Pages[0] as PdfLoadedPage; PdfLoadedPage lpage2 = lDoc.Pages[1] as PdfLoadedPage; if (checkboxFlatten == "Flatten") { lpage1.Annotations.Flatten = true; lpage2.Annotations.Flatten = true; } //Save to disk if (InsideBrowser == "Browser") { return(lDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(lDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }
public ActionResult FormFilling(string submit1, string submit, string InsideBrowser, string flatten) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("Form.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument doc = new PdfLoadedDocument(file2); return(doc.ExportAsActionResult("FormTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else if (submit == "Generate PDF") { string dataPath = ResolveApplicationDataPath("Form.pdf"); Stream file1 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument doc = new PdfLoadedDocument(file1); PdfLoadedForm form = doc.Form; // fill the fields from the first page (form.Fields["f1-1"] as PdfLoadedTextBoxField).Text = "1"; (form.Fields["f1-2"] as PdfLoadedTextBoxField).Text = "1"; (form.Fields["f1-3"] as PdfLoadedTextBoxField).Text = "1"; (form.Fields["f1-4"] as PdfLoadedTextBoxField).Text = "3"; (form.Fields["f1-5"] as PdfLoadedTextBoxField).Text = "1"; (form.Fields["f1-6"] as PdfLoadedTextBoxField).Text = "1"; (form.Fields["f1-7"] as PdfLoadedTextBoxField).Text = "22"; (form.Fields["f1-8"] as PdfLoadedTextBoxField).Text = "30"; (form.Fields["f1-9"] as PdfLoadedTextBoxField).Text = "John"; (form.Fields["f1-10"] as PdfLoadedTextBoxField).Text = "Doe"; (form.Fields["f1-11"] as PdfLoadedTextBoxField).Text = "3233 Spring Rd."; (form.Fields["f1-12"] as PdfLoadedTextBoxField).Text = "Atlanta, GA 30339"; (form.Fields["f1-13"] as PdfLoadedTextBoxField).Text = "332"; (form.Fields["f1-14"] as PdfLoadedTextBoxField).Text = "43"; (form.Fields["f1-15"] as PdfLoadedTextBoxField).Text = "4556"; (form.Fields["f1-16"] as PdfLoadedTextBoxField).Text = "3"; (form.Fields["f1-17"] as PdfLoadedTextBoxField).Text = "2000"; (form.Fields["f1-18"] as PdfLoadedTextBoxField).Text = "Exempt"; (form.Fields["f1-19"] as PdfLoadedTextBoxField).Text = "Syncfusion, Inc"; (form.Fields["f1-20"] as PdfLoadedTextBoxField).Text = "200"; (form.Fields["f1-21"] as PdfLoadedTextBoxField).Text = "22"; (form.Fields["f1-22"] as PdfLoadedTextBoxField).Text = "56654"; (form.Fields["c1-1[0]"] as PdfLoadedCheckBoxField).Items[0].Checked = true; (form.Fields["c1-1[1]"] as PdfLoadedCheckBoxField).Items[0].Checked = true; // fill the fields from the second page (form.Fields["f2-1"] as PdfLoadedTextBoxField).Text = "3200"; (form.Fields["f2-2"] as PdfLoadedTextBoxField).Text = "4850"; (form.Fields["f2-3"] as PdfLoadedTextBoxField).Text = "0"; (form.Fields["f2-4"] as PdfLoadedTextBoxField).Text = "500"; (form.Fields["f2-5"] as PdfLoadedTextBoxField).Text = "500"; (form.Fields["f2-6"] as PdfLoadedTextBoxField).Text = "800"; (form.Fields["f2-7"] as PdfLoadedTextBoxField).Text = "0"; (form.Fields["f2-8"] as PdfLoadedTextBoxField).Text = "0"; (form.Fields["f2-9"] as PdfLoadedTextBoxField).Text = "3"; (form.Fields["f2-10"] as PdfLoadedTextBoxField).Text = "3"; (form.Fields["f2-11"] as PdfLoadedTextBoxField).Text = "3"; (form.Fields["f2-12"] as PdfLoadedTextBoxField).Text = "2"; (form.Fields["f2-13"] as PdfLoadedTextBoxField).Text = "3"; (form.Fields["f2-14"] as PdfLoadedTextBoxField).Text = "3"; (form.Fields["f2-15"] as PdfLoadedTextBoxField).Text = "2"; (form.Fields["f2-16"] as PdfLoadedTextBoxField).Text = "1"; (form.Fields["f2-17"] as PdfLoadedTextBoxField).Text = "200"; (form.Fields["f2-18"] as PdfLoadedTextBoxField).Text = "600"; (form.Fields["f2-19"] as PdfLoadedTextBoxField).Text = "250"; if (flatten == "From Flatten") { doc.Form.Flatten = true; } //Save to disk if (InsideBrowser == "Browser") { return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } return(View()); }
public ActionResult XFAFormFilling(string submit1, string submit, string InsideBrowser, string Flatten) { if (submit1 == "View Template") { string dataPath = ResolveApplicationDataPath("xfaTemplate.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument doc = new PdfLoadedDocument(file2); return(doc.ExportAsActionResult("XfaFormTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else if (submit == "Create PDF") { string dataPath = ResolveApplicationDataPath("xfaTemplate.pdf"); Stream file1 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the existing XFA document. PdfLoadedXfaDocument ldoc = new PdfLoadedXfaDocument(file1); //Loaded the existing XFA form. PdfLoadedXfaForm lform = ldoc.XfaForm; //Fill the XFA form fields. (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["title[0]"] as PdfLoadedXfaComboBoxField).SelectedIndex = 0; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["fn[0]"] as PdfLoadedXfaTextBoxField).Text = "Simons"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["ln[0]"] as PdfLoadedXfaTextBoxField).Text = "Bistro"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["dob[0]"] as PdfLoadedXfaDateTimeField).Value = new DateTime(1989, 5, 21); (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["company[0]"] as PdfLoadedXfaTextBoxField).Text = "XYZ Pvt Ltd"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["jt[0]"] as PdfLoadedXfaTextBoxField).Text = "Developer"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["jd[0]"] as PdfLoadedXfaTextBoxField).Text = "Develop and maintain components and applications for the web, desktop and mobile platforms. \nWork with some of the best UI/UX designers in the world to craft Stunning user interfaces. \nRegular appraisals to ensure quick growth if you deliver on the job."; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["st[0]"] as PdfLoadedXfaTextBoxField).Text = "Vinbaeltet 34"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["ad1[0]"] as PdfLoadedXfaTextBoxField).Text = "Kobenhaven"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["city[0]"] as PdfLoadedXfaTextBoxField).Text = "Denmark"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["state[0]"] as PdfLoadedXfaComboBoxField).SelectedIndex = 1; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["zip[0]"] as PdfLoadedXfaNumericField).NumericValue = 24534; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["country[0]"] as PdfLoadedXfaTextBoxField).Text = "US"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["em[0]"] as PdfLoadedXfaTextBoxField).Text = "*****@*****.**"; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["phone[0]"] as PdfLoadedXfaNumericField).NumericValue = 8765456789; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["sdn[0]"] as PdfLoadedXfaListBoxField).SelectedItems = new string[] { "Vegan", "Diary Free" }; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["san[0]"] as PdfLoadedXfaListBoxField).SelectedIndex = 0; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["email[0]"] as PdfLoadedXfaCheckBoxField).IsChecked = true; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["phone[1]"] as PdfLoadedXfaCheckBoxField).IsChecked = true; (((lform.Fields["subform1[0]"] as PdfLoadedXfaForm).Fields["subform3[0]"] as PdfLoadedXfaForm).Fields["group1[0]"] as PdfLoadedXfaRadioButtonGroup).Fields[1].IsChecked = true; if (Flatten == "Flatten") { //Flatten the XFA form ldoc.Flatten = true; } //Save to disk if (InsideBrowser == "Browser") { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open, true)); } else { return(ldoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save, true)); } } return(View()); }
public ActionResult CompressExistingPDF(bool compressImage = false, bool optPageContents = false, bool removeMetaData = false, bool optFont = false, string imageQuality = "50", string Browser = "null", HttpPostedFileBase file = null) { if (file != null && file.ContentLength > 0) { //Load a existing PDF document PdfLoadedDocument ldoc = new PdfLoadedDocument(file.InputStream); //Create a new PDF compression options PdfCompressionOptions options = new PdfCompressionOptions(); if (compressImage) { //Compress image. options.CompressImages = true; options.ImageQuality = int.Parse((imageQuality)); } else { options.CompressImages = false; } //Compress the font data if (optFont) { options.OptimizeFont = true; } else { options.OptimizeFont = false; } //Compress the page contents if (optPageContents) { options.OptimizePageContents = true; } else { options.OptimizePageContents = false; } //Remove the metadata information. if (removeMetaData) { options.RemoveMetadata = true; } else { options.RemoveMetadata = false; } //Set the options to loaded PDF document ldoc.CompressionOptions = options; string inputFileSize = ""; inputFileSize = GetActualSize(file.ContentLength); Session["inputFileSize"] = inputFileSize; MemoryStream ms = new MemoryStream(); ldoc.Save(ms); string outputFileSize = ""; outputFileSize = GetActualSize(ms.Length); Session["outputFileSize"] = outputFileSize; string[] fileName = file.FileName.Split(new string[] { ".pdf" }, StringSplitOptions.RemoveEmptyEntries); //Save to disk //Stream the output to the browser. if (Browser == "Browser") { return(ldoc.ExportAsActionResult(fileName[0] + "_compressed.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(ldoc.ExportAsActionResult(fileName[0] + "_compressed.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } else { ViewBag.lab = "Choose a valid PDF file."; ViewData.Add("imageQuality", new SelectList(new string[] { "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" }, "50")); return(View()); } }
public ActionResult Redaction(string viewTemplate, string RedactPdf, string Browser, string x, string y, string width, string height, HttpPostedFileBase file) { if (viewTemplate == "View Template") { string dataPath = ResolveApplicationDataPath("Redaction.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument doc = new PdfLoadedDocument(file2); return(doc.ExportAsActionResult("RedactionTemplate.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else if (RedactPdf == "Redact PDF") { string dataPath = ResolveApplicationDataPath("Redaction.pdf"); Stream file2 = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read); //Load the template document PdfLoadedDocument doc = new PdfLoadedDocument(file2); PdfLoadedPage lpage = doc.Pages[0] as PdfLoadedPage; PdfRedaction textRedaction = new PdfRedaction(new RectangleF(86.998f, 39.565f, 62.709f, 20.802f), System.Drawing.Color.Black); //Create PDF redaction for the page to redact text PdfRedaction pathRedaction = new PdfRedaction(new RectangleF(83.7744f, 576.066f, 210.0746f, 104.155f), System.Drawing.Color.Black); //Create PDF redaction for the page to redact text PdfRedaction imageRedation = new PdfRedaction(new RectangleF(327.848f, 63.97198f, 232.179f, 223.429f), System.Drawing.Color.Black); lpage.Redactions.Add(textRedaction); lpage.Redactions.Add(pathRedaction); lpage.Redactions.Add(imageRedation); return(doc.ExportAsActionResult("Redaction.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } else { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); float x1; float y1; float width1; float height1; if (x != null && x.Length > 0 && float.TryParse(x.ToString(), out x1) && y != null && y.Length > 0 && float.TryParse(y.ToString(), out y1) && width != null && width.Length > 0 && float.TryParse(width.ToString(), out width1) && height != null && height.Length > 0 && float.TryParse(height.ToString(), out height1)) { //Load a PDF document PdfLoadedDocument ldoc = new PdfLoadedDocument(file.InputStream); //Get first page from document PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage; //Create PDF redaction for the page PdfRedaction redaction = new PdfRedaction(new RectangleF(x1, y1, width1, height1), Color.Black); //Adds the redaction to loaded page lpage.Redactions.Add(redaction); //Save to disk if (Browser == "Browser") { return(ldoc.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(ldoc.ExportAsActionResult("Document1.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } } else { ViewBag.lab = "Fill proper redaction bounds to redact"; } } else { ViewBag.lab = "Choose PDF document to redact"; } } return(View()); }
public ActionResult AnnotationFlatten(string InsideBrowser, string checkboxFlatten) { //Creates a new PDF document. PdfDocument document = new PdfDocument(); //Creates a new page PdfPage page = document.Pages.Add(); document.PageSettings.SetMargins(0); RectangleF bounds = new RectangleF(350, 50, 80, 80); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f); PdfBrush brush = new PdfSolidBrush(System.Drawing.Color.Black); //Creates a new Circle annotation. PdfCircleAnnotation circleannotation = new PdfCircleAnnotation(bounds); circleannotation.InnerColor = new PdfColor(Color.Yellow); circleannotation.Color = new PdfColor(Color.Red); circleannotation.AnnotationFlags = PdfAnnotationFlags.Default; circleannotation.Author = "Syncfusion"; circleannotation.Subject = "CircleAnnotation"; circleannotation.ModifiedDate = new DateTime(2015, 1, 18); page.Annotations.Add(circleannotation); page.Graphics.DrawString("Circle Annotation", font, brush, new PointF(350, 10)); //Creates a new Ellipse annotation. PdfEllipseAnnotation ellipseannotation = new PdfEllipseAnnotation(new RectangleF(30, 30, 50, 100), "Ellipse Annotation"); ellipseannotation.Color = new PdfColor(Color.Red); ellipseannotation.InnerColor = new PdfColor(Color.Yellow); page.Graphics.DrawString("Ellipse Annotation", font, brush, new PointF(30, 10)); page.Annotations.Add(ellipseannotation); //Creates a new Square annotation. PdfSquareAnnotation squareannotation = new PdfSquareAnnotation(new RectangleF(30, 200, 80, 80)); squareannotation.Text = "SquareAnnotation"; squareannotation.InnerColor = new PdfColor(Color.Red); squareannotation.Color = new PdfColor(Color.Yellow); page.Graphics.DrawString("Square Annotation", font, brush, new PointF(30, 180)); page.Annotations.Add(squareannotation); //Creates a new Rectangle annotation. RectangleF rectannot = new RectangleF(350, 220, 100, 50); PdfRectangleAnnotation rectangleannotation = new PdfRectangleAnnotation(rectannot, "RectangleAnnotation"); rectangleannotation.InnerColor = new PdfColor(Color.Red); rectangleannotation.Color = new PdfColor(Color.Yellow); page.Graphics.DrawString("Rectangle Annotation", font, brush, new PointF(350, 180)); page.Annotations.Add(rectangleannotation); //Creates a new Line annotation. int[] points = new int[] { 400, 450, 550, 450 }; PdfLineAnnotation lineAnnotation = new PdfLineAnnotation(points, "Line Annoation is the one of the annotation type..."); lineAnnotation.Author = "Syncfusion"; lineAnnotation.Subject = "LineAnnotation"; lineAnnotation.ModifiedDate = new DateTime(2015, 1, 18); lineAnnotation.Text = "PdfLineAnnotation"; lineAnnotation.BackColor = new PdfColor(Color.Red); page.Graphics.DrawString("Line Annotation", font, brush, new PointF(400, 320)); page.Annotations.Add(lineAnnotation); //Creates a new Polygon annotation. int[] polypoints = new int[] { 50, 398, 100, 425, 200, 455, 300, 330, 180, 330 }; PdfPolygonAnnotation polygonannotation = new PdfPolygonAnnotation(polypoints, "PolygonAnnotation"); polygonannotation.Bounds = new RectangleF(30, 350, 300, 200); PdfPen pen = new PdfPen(Color.Red); polygonannotation.Text = "polygon"; polygonannotation.Color = new PdfColor(Color.Red); polygonannotation.InnerColor = new PdfColor(Color.LightPink); page.Graphics.DrawString("Polygon Annotation", font, brush, new PointF(50, 320)); page.Annotations.Add(polygonannotation); //Creates a new Freetext annotation. RectangleF freetextrect = new RectangleF(405, 525, 80, 30); PdfFreeTextAnnotation freeText = new PdfFreeTextAnnotation(freetextrect); freeText.MarkupText = "Free Text with Callouts"; freeText.TextMarkupColor = new PdfColor(Color.Green); freeText.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); freeText.BorderColor = new PdfColor(Color.Blue); freeText.Border = new PdfAnnotationBorder(.5f); freeText.AnnotationFlags = PdfAnnotationFlags.Default; freeText.Text = "Free Text"; freeText.Color = new PdfColor(Color.Yellow); PointF[] Freetextpoints = { new PointF(365, 580), new PointF(379, 534), new PointF(405, 534) }; freeText.CalloutLines = Freetextpoints; page.Graphics.DrawString("FreeText Annotation", font, brush, new PointF(400, 510)); page.Annotations.Add(freeText); //Creates a new TextMarkup annotation. string s = "This is TextMarkup annotation!!!"; RectangleF Textmarkuprect = new RectangleF(30, 540, 200, 20); page.Graphics.DrawString(s, font, brush, new PointF(30, 540)); PdfTextMarkupAnnotation textannot = new PdfTextMarkupAnnotation("sample", "Highlight", s, new PointF(70, 580), font); textannot.Author = "Annotation"; textannot.Opacity = 1.0f; textannot.Subject = "pdftextmarkupannotation"; textannot.ModifiedDate = new DateTime(2015, 1, 18); textannot.TextMarkupAnnotationType = PdfTextMarkupAnnotationType.StrikeOut; textannot.TextMarkupColor = new PdfColor(Color.Yellow); textannot.InnerColor = new PdfColor(Color.Red); textannot.Color = new PdfColor(Color.Yellow); page.Graphics.DrawString("TextMarkup Annotation", font, brush, new PointF(30, 510)); page.Annotations.Add(textannot); //Creates a new Ink annotation. List <float> linePoints = new List <float> { 72.919f, 136.376f, 72.264f, 136.376f, 62.446f, 142.922f, 61.137f, 142.922f, 55.901f, 139.649f, 55.246f, 138.34f, 54.592f, 132.449f, 54.592f, 127.867f, 55.901f, 125.904f, 59.828f, 121.976f, 63.101f, 121.322f, 65.719f, 122.631f, 68.992f, 125.249f, 70.301f, 130.485f, 71.61f, 133.104f, 72.264f, 136.376f, 72.919f, 140.304f, 74.883f, 144.885f, 76.192f, 150.776f, 76.192f, 151.431f, 76.192f, 152.085f, 76.192f, 158.631f, 76.192f, 159.94f, 75.537f, 155.358f, 74.228f, 150.122f, 74.228f, 146.195f, 73.574f, 141.613f, 73.574f, 137.685f, 74.228f, 132.449f, 74.883f, 128.522f, 75.537f, 124.594f, 76.192f, 123.285f, 76.846f, 122.631f, 80.774f, 122.631f, 82.737f, 123.285f, 85.355f, 125.249f, 88.628f, 129.831f, 89.283f, 133.104f, 89.937f, 137.031f, 90.592f, 140.958f, 89.937f, 142.267f, 86.665f, 141.613f, 85.355f, 140.304f, 84.701f, 138.34f, 84.701f, 137.685f, 85.355f, 137.031f, 87.974f, 135.722f, 90.592f, 136.376f, 92.555f, 137.031f, 96.483f, 139.649f, 98.446f, 140.958f, 101.719f, 142.922f, 103.028f, 142.922f, 100.41f, 138.34f, 99.756f, 134.413f, 99.101f, 131.14f, 99.101f, 128.522f, 99.756f, 127.213f, 101.065f, 125.904f, 102.374f, 123.94f, 103.683f, 123.94f, 107.61f, 125.904f, 110.228f, 129.831f, 114.156f, 135.067f, 117.428f, 140.304f, 119.392f, 143.576f, 121.356f, 144.231f, 122.665f, 144.231f, 123.974f, 142.267f, 126.592f, 139.649f, 127.247f, 140.304f, 126.592f, 142.922f, 124.628f, 143.576f, 122.01f, 142.922f, 118.083f, 141.613f, 114.81f, 136.376f, 114.81f, 131.14f, 113.501f, 127.213f, 114.156f, 125.904f, 118.083f, 125.904f, 120.701f, 126.558f, 123.319f, 130.485f, 125.283f, 136.376f, 125.937f, 140.304f, 125.937f, 142.922f, 126.592f, 143.576f, 125.937f, 135.722f, 125.937f, 131.794f, 125.937f, 131.14f, 127.247f, 129.176f, 129.21f, 127.213f, 131.828f, 127.213f, 134.447f, 128.522f, 136.41f, 136.376f, 139.028f, 150.122f, 141.647f, 162.558f, 140.992f, 163.213f, 138.374f, 160.595f, 135.756f, 153.395f, 135.101f, 148.158f, 134.447f, 140.304f, 134.447f, 130.485f, 133.792f, 124.594f, 133.792f, 115.431f, 133.792f, 110.194f, 133.792f, 105.612f, 134.447f, 105.612f, 137.065f, 110.194f, 137.719f, 116.74f, 139.028f, 120.013f, 139.028f, 123.94f, 137.719f, 127.213f, 135.756f, 130.485f, 134.447f, 130.485f, 133.792f, 130.485f, 137.719f, 131.794f, 141.647f, 135.722f, 146.883f, 142.922f, 152.774f, 153.395f, 153.428f, 159.286f, 150.156f, 159.94f, 147.537f, 156.667f, 146.883f, 148.813f, 146.883f, 140.958f, 146.883f, 134.413f, 146.883f, 125.904f, 145.574f, 118.703f, 145.574f, 114.776f, 145.574f, 112.158f, 146.228f, 111.503f, 147.537f, 111.503f, 148.192f, 112.158f, 150.156f, 112.812f, 150.81f, 113.467f, 152.119f, 114.776f, 154.083f, 117.394f, 155.392f, 119.358f, 156.701f, 120.667f, 157.356f, 121.976f, 156.701f, 121.322f, 156.047f, 120.013f, 155.392f, 119.358f, 154.083f, 117.394f, 154.083f, 116.74f, 152.774f, 114.776f, 152.119f, 114.121f, 150.81f, 113.467f, 149.501f, 113.467f, 147.537f, 112.158f, 146.883f, 112.158f, 145.574f, 111.503f, 144.919f, 112.158f, 144.265f, 114.121f, 144.265f, 115.431f, 144.265f, 116.74f, 144.265f, 117.394f, 144.265f, 118.049f, 144.919f, 118.703f, 145.574f, 120.667f, 146.228f, 122.631f, 147.537f, 123.285f, 147.537f, 124.594f, 148.192f, 125.904f, 147.537f, 128.522f, 147.537f, 129.176f, 147.537f, 130.485f, 147.537f, 132.449f, 147.537f, 134.413f, 147.537f, 136.376f, 147.537f, 138.34f, 147.537f, 138.994f, 145.574f, 138.994f, 142.956f, 138.252f }; RectangleF rectangle = new RectangleF(30, 580, 300, 400); PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, linePoints); inkAnnotation.Bounds = rectangle; inkAnnotation.Color = new PdfColor(Color.Red); page.Graphics.DrawString("Ink Annotation", font, brush, new PointF(30, 610)); page.Annotations.Add(inkAnnotation); //Creates a new popup annotation. RectangleF popupRect = new RectangleF(430, 670, 30, 30); PdfPopupAnnotation popupAnnotation = new PdfPopupAnnotation(); popupAnnotation.Border.Width = 4; popupAnnotation.Border.HorizontalRadius = 20; popupAnnotation.Border.VerticalRadius = 30; popupAnnotation.Opacity = 1; popupAnnotation.Open = true; popupAnnotation.Text = "Popup Annotation"; popupAnnotation.Color = Color.Green; popupAnnotation.InnerColor = Color.Blue; popupAnnotation.Bounds = popupRect; if (checkboxFlatten == "Flatten") { popupAnnotation.FlattenPopUps = true; popupAnnotation.Flatten = true; } page.Graphics.DrawString("Popup Annotation", font, brush, new PointF(400, 610)); page.Annotations.Add(popupAnnotation); page = document.Pages.Add(); //Creates a new Rubberstamp measurement annotation. rectangle = new RectangleF(10, 40, 200, 50); PdfRubberStampAnnotation rubberStampAnnotation = new PdfRubberStampAnnotation(rectangle, " Approved Rubber Stamp Annotation"); rubberStampAnnotation.Icon = PdfRubberStampAnnotationIcon.Approved; rubberStampAnnotation.Author = "Syncfusion"; rubberStampAnnotation.Subject = "Rubber Stamp"; rubberStampAnnotation.Color = new PdfColor(System.Drawing.Color.Blue); page.Graphics.DrawString("Rubber Stamp Annotation", font, brush, new PointF(40, 10)); if (checkboxFlatten == "Flatten") { rubberStampAnnotation.Flatten = true; } page.Annotations.Add(rubberStampAnnotation); //Creates a new Line measurement annotation. points = new int[] { 350, 750, 500, 750 }; PdfLineMeasurementAnnotation lineMeasureAnnot = new PdfLineMeasurementAnnotation(points); lineMeasureAnnot.Author = "Syncfusion"; lineMeasureAnnot.Subject = "LineAnnotation"; lineMeasureAnnot.ModifiedDate = new DateTime(2015, 1, 18); lineMeasureAnnot.Unit = PdfMeasurementUnit.Inch; lineMeasureAnnot.lineBorder.BorderWidth = 2; lineMeasureAnnot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Regular); lineMeasureAnnot.Color = new PdfColor(Color.Red); if (checkboxFlatten == "Flatten") { lineMeasureAnnot.Flatten = true; } page.Graphics.DrawString("Line Measurement Annotation", font, brush, new PointF(320, 10)); page.Annotations.Add(lineMeasureAnnot); //Creates a new Freetext annotation. RectangleF freetextrect0 = new RectangleF(80, 130, 100, 50); PdfFreeTextAnnotation freeText0 = new PdfFreeTextAnnotation(freetextrect0); freeText0.MarkupText = "Free Text with Callouts"; freeText0.TextMarkupColor = new PdfColor(Color.Green); freeText0.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 7f); freeText0.BorderColor = new PdfColor(Color.Blue); freeText0.Border = new PdfAnnotationBorder(.5f); freeText0.AnnotationFlags = PdfAnnotationFlags.Default; freeText0.Text = "Free Text"; freeText0.Rotate = PdfAnnotationRotateAngle.RotateAngle90; freeText0.Color = new PdfColor(Color.Yellow); PointF[] Freetextpoints0 = { new PointF(45, 190), new PointF(60, 145), new PointF(80, 145) }; freeText0.CalloutLines = Freetextpoints0; page.Graphics.DrawString("Rotated FreeText Annotation", font, brush, new PointF(40, 110)); if (checkboxFlatten == "Flatten") { freeText0.Flatten = true; } page.Annotations.Add(freeText0); MemoryStream SourceStream = new MemoryStream(); document.Save(SourceStream); document.Close(true); //Creates a new Loaded document. PdfLoadedDocument lDoc = new PdfLoadedDocument(SourceStream); PdfLoadedPage lpage = lDoc.Pages[0] as PdfLoadedPage; if (checkboxFlatten == "Flatten") { lpage.Annotations.Flatten = true; } //Save to disk if (InsideBrowser == "Browser") { return(lDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(lDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }