public virtual void AnnotationCheckTest05() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_2B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 650, 400, 100); PdfAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlag(0); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.THE_F_KEYS_PRINT_FLAG_BIT_SHALL_BE_SET_TO_1_AND_ITS_HIDDEN_INVISIBLE_NOVIEW_AND_TOGGLENOVIEW_FLAG_BITS_SHALL_BE_SET_TO_0)) ; }
public virtual void AnnotationCheckTest07() { String outPdf = destinationFolder + "pdfA1b_annotationCheckTest07.pdf"; String cmpPdf = cmpFolder + "cmp_pdfA1b_annotationCheckTest07.pdf"; PdfWriter writer = new PdfWriter(outPdf); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfMarkupAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlags(PdfAnnotation.PRINT | PdfAnnotation.NO_ZOOM | PdfAnnotation.NO_ROTATE); page.AddAnnotation(annot); doc.Close(); CompareResult(outPdf, cmpPdf); }
public virtual void AnnotationCheckTest03() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfMarkupAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlag(0); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.TheFKeysPrintFlagBitShallBeSetTo1AndItsHiddenInvisibleAndNoviewFlagBitsShallBeSetTo0)); ; }
public virtual void AnnotationCheckTest02() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfMarkupAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlag(PdfAnnotation.PRINT); annot.SetOpacity(new PdfNumber(0.5)); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.InstanceOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AN_ANNOTATION_DICTIONARY_SHALL_NOT_CONTAIN_THE_CA_KEY_WITH_A_VALUE_OTHER_THAN_1)) ; }
public virtual void AnnotationCheckTest02() { NUnit.Framework.Assert.That(() => { PdfWriter writer = new PdfWriter(new ByteArrayOutputStream()); Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read); PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1B, new PdfOutputIntent("Custom", "" , "http://www.color.org", "sRGB IEC61966-2.1", @is)); PdfPage page = doc.AddNewPage(); Rectangle rect = new Rectangle(100, 100, 100, 100); PdfMarkupAnnotation annot = new PdfTextAnnotation(rect); annot.SetFlag(PdfAnnotation.PRINT); annot.SetOpacity(new PdfNumber(0.5)); page.AddAnnotation(annot); doc.Close(); } , NUnit.Framework.Throws.TypeOf <PdfAConformanceException>().With.Message.EqualTo(PdfAConformanceException.AnAnnotationDictionaryShallNotContainTheCaKeyWithAValueOtherThan1)); ; }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "AddAnnotationsAndControlsToLayers.pdf"; using (PdfDocument pdf = new PdfDocument()) { pdf.PageMode = PdfPageMode.UseOC; PdfLayer buttonsLayer = pdf.CreateLayer("Buttons"); PdfLayer textLayer = pdf.CreateLayer("Text"); PdfPage page = pdf.Pages[0]; int top = 100; int height = 50; foreach (string name in new string[] { "Button 1", "Button 2", "Button 3" }) { PdfButton button = page.AddButton(name, new PdfRectangle(10, top, 100, height)); button.Text = name; button.Layer = buttonsLayer; top += height + 10; } top = 100; height = 50; foreach (string title in new string[] { "Text 1", "Text 2", "Text 3" }) { PdfTextAnnotation annot = page.AddTextAnnotation(new PdfPoint(200, top), title); annot.Layer = textLayer; top += height + 10; } pdf.Save(pathToFile); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public virtual void CreatePdf(String dest) { //Initialize PDF document PdfDocument pdf = new PdfDocument(new PdfWriter(dest)); //Initialize document Document document = new Document(pdf); document.Add(new Paragraph("The example of text annotation.")); //Create text annotation PdfAnnotation ann = new PdfTextAnnotation(new Rectangle(20, 800, 0, 0)) .SetOpen(true) .SetColor(ColorConstants.GREEN) .SetTitle(new PdfString("iText")) .SetContents("With iText, you can truly take your documentation needs to the next level."); pdf.GetFirstPage().AddAnnotation(ann); //Close document document.Close(); }
public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. string pathToFile = "TextAnnotations.pdf"; using (PdfDocument pdf = new PdfDocument()) { PdfPage page = pdf.Pages[0]; const string content = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; PdfTextAnnotation textAnnotation = page.AddTextAnnotation(10, 50, "Docotic.Pdf Samples", content); textAnnotation.Icon = PdfTextAnnotationIcon.Comment; textAnnotation.Opened = true; pdf.Save(pathToFile); } Process.Start(pathToFile); }
protected void ManipulatePdf(String dest) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest)); PdfPage firstPage = pdfDoc.GetFirstPage(); PdfAnnotation sticky = firstPage.GetAnnotations()[0]; Rectangle stickyRectangle = sticky.GetRectangle().ToRectangle(); PdfAnnotation replySticky = new PdfTextAnnotation(stickyRectangle) // This method specifies whether initially the annotation is displayed open or not. .SetOpen(false) .SetStateModel(new PdfString("Marked")) .SetState(new PdfString("Marked")) .SetIconName(new PdfName("Comment")) // This method sets an annotation to which the current annotation is "in reply". // Both annotations shall be on the same page of the document. .SetInReplyTo(sticky) // This method sets the text label that will be displayed in the title bar of the annotation's pop-up window // when open and active. This entry will identify the user who added the annotation. .SetText(new PdfString("Bruno")) // This method sets the text that will be displayed for the annotation or the alternate description, // if this type of annotation does not display text. .SetContents("Marked set by Bruno") // This method sets a complete set of enabled and disabled flags at once. If not set specifically // the default value is 0. // The argument is an integer interpreted as set of one-bit flags // specifying various characteristics of the annotation. .SetFlags(sticky.GetFlags() + PdfAnnotation.HIDDEN); firstPage.AddAnnotation(replySticky); pdfDoc.Close(); }
private static void CreateTextAnnotations(PdfFixedDocument document, PdfFont font) { PdfBrush blackBrush = new PdfBrush(); PdfPage page = document.Pages.Add(); string[] textAnnotationNames = new string[] { "Comment", "Check", "Circle", "Cross", "Help", "Insert", "Key", "NewParagraph", "Note", "Paragraph", "RightArrow", "RightPointer", "Star", "UpArrow", "UpLeftArrow" }; page.Graphics.DrawString("B/W text annotations", font, blackBrush, 50, 50); for (int i = 0; i < textAnnotationNames.Length; i++) { PdfTextAnnotation ta = new PdfTextAnnotation(); ta.Author = "Xfinium.Pdf"; ta.Contents = "I am a " + textAnnotationNames[i] + " annotation."; ta.IconName = textAnnotationNames[i]; page.Annotations.Add(ta); ta.Location = new PdfPoint(50, 100 + 40 * i); page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 90, 100 + 40 * i); } Random rnd = new Random(); byte[] rgb = new byte[3]; page.Graphics.DrawString("Color text annotations", font, blackBrush, 300, 50); for (int i = 0; i < textAnnotationNames.Length; i++) { PdfTextAnnotation ta = new PdfTextAnnotation(); ta.Author = "Xfinium.Pdf"; ta.Contents = "I am a " + textAnnotationNames[i] + " annotation."; ta.IconName = textAnnotationNames[i]; rnd.NextBytes(rgb); ta.OutlineColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); rnd.NextBytes(rgb); ta.InteriorColor = new PdfRgbColor(rgb[0], rgb[1], rgb[2]); page.Annotations.Add(ta); ta.Location = new PdfPoint(300, 100 + 40 * i); page.Graphics.DrawString(textAnnotationNames[i], font, blackBrush, 340, 100 + 40 * i); } page.Graphics.DrawString("Text annotations with custom icons", font, blackBrush, 50, 700); PdfTextAnnotation customTextAnnotation = new PdfTextAnnotation(); customTextAnnotation.Author = "Xfinium.Pdf"; customTextAnnotation.Contents = "Text annotation with custom icon."; page.Annotations.Add(customTextAnnotation); customTextAnnotation.IconName = "Custom icon appearance"; customTextAnnotation.Location = new PdfPoint(50, 720); PdfAnnotationAppearance customAppearance = new PdfAnnotationAppearance(50, 50); PdfPen redPen = new PdfPen(new PdfRgbColor(255, 0, 0), 10); PdfPen bluePen = new PdfPen(new PdfRgbColor(0, 0, 192), 10); customAppearance.Graphics.DrawRectangle(redPen, 5, 5, 40, 40); customAppearance.Graphics.DrawLine(bluePen, 0, 0, customAppearance.Width, customAppearance.Height); customAppearance.Graphics.DrawLine(bluePen, 0, customAppearance.Height, customAppearance.Width, 0); customAppearance.Graphics.CompressAndClose(); customTextAnnotation.NormalAppearance = customAppearance; }
public static void Cria() { string caminho = @"C:\WorkPedro\pdf\docCanvas.pdf"; using FileStream fileStream = new FileStream(caminho, FileMode.Create); using PdfWriter writer = new PdfWriter(fileStream); using PdfDocument pdf = new PdfDocument(writer); PageSize ps = PageSize.A5; Document document = new Document(pdf, ps); //float offset = 36; //float columnWidth = (ps.GetWidth() - offset * 2 + 10) / 3; //float columnHeigth = ps.GetHeight() - offset * 2; //Rectangle[] columns = //{ // new Rectangle(offset - 5, offset, columnWidth, columnHeigth), // new Rectangle(offset + columnWidth, offset, columnWidth, columnHeigth), // new Rectangle(offset + columnHeigth * 2 + 5, offset, columnWidth, columnHeigth) //}; //document.RenderizadorDeColunas(3, 5); document.SetRenderer(document.RenderizadorDeColunas(3, 5)); float alturaDaColuna = document.AlturaDaColuna(); float larguraDaColuna = document.LarguraDaColuna(3, 5); string caminhoImagem = @"C:\Users\SAMIR-IBRAHIM-EM\Desktop\Estagio\BELIZE_HOLE.png"; Image imagem = new Image(ImageDataFactory.Create(caminhoImagem)).SetWidth(larguraDaColuna).SetHeight(alturaDaColuna); string conteudo = @"Integer ac nulla et quam tristique viverra. Integer et hendrerit neque. Maecenas aliquet elementum massa non placerat. Etiam sed vestibulum velit, eu consequat neque. Vestibulum tempus mollis lectus at malesuada. Proin ac iaculis sem. Integer nec dapibus mauris, sed congue turpis. Pellentesque consectetur molestie ullamcorper. Nam scelerisque, quam ut vulputate sagittis, sapien sapien pharetra justo, tempor hendrerit nibh nisl sed massa. In eget condimentum velit. Nam congue magna a scelerisque iaculis. Nam id odio et enim convallis fermentum et non enim."; string conteudo2 = @"Sagittis primis neque volutpat convallis sodales vulputate ac leo, lectus quis maecenas orci posuere netus ad etiam, dictumst varius porta senectus varius morbi eleifend. mi lectus vivamus sapien hac quisque vitae lacinia tempor, consectetur ullamcorper morbi curae est nisi fusce pharetra, purus sodales a cras cursus convallis interdum. molestie pharetra luctus phasellus nullam convallis lacus tellus massa augue, aenean condimentum nec accumsan nec sit tristique a orci, a metus tortor mollis senectus tincidunt hendrerit venenatis. litora blandit nullam suspendisse ut potenti primis tempus tristique mi arcu sagittis rhoncus interdum, curabitur elit aliquam consequat sociosqu pellentesque himenaeos platea per neque rhoncus aliquet."; document.Add(imagem); //document.Add(new AreaBreak()); document.Add(new Paragraph(conteudo)); //document.Add(new AreaBreak()); document.Add(new Paragraph(conteudo2)); document.Add(new AreaBreak(AreaBreakType.NEXT_PAGE)); document.SetRenderer(document.RenderizadorDeColunas(1, 0)); document.Add(new Paragraph("Exemplo de anotação")); PdfAnnotation annotation = new PdfTextAnnotation(new Rectangle(20, 800, 0, 0)) .SetOpen(true) .SetColor(ColorConstants.GREEN) .SetTitle(new PdfString("iText")) .SetContents("With iText, you can truly take your documentation needs to the next level."); pdf.GetFirstPage().AddAnnotation(annotation); //pdf.GetLastPage().AddAnnotation(annotation); PdfLinkAnnotation linkAnnotation = ((PdfLinkAnnotation) new PdfLinkAnnotation(new Rectangle(0, 0)) .SetAction(PdfAction.CreateURI("https://itextpdf.com/"))); Link link = new Link("aqui", linkAnnotation); Paragraph paragraph = new Paragraph("Exemplo de anotação com link. Clique ") .Add(link.SetUnderline()) .Add(" para saber mais!"); document.Add(paragraph); document.Close(); }
// This sample shows how to create annotations. protected override void DoWork() { // Create a new PDF document PdfDocument document = new PdfDocument(); // Create a font XFont font = new XFont("Verdana", 14); // Create a page PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); // Create a PDF text annotation PdfTextAnnotation textAnnot = new PdfTextAnnotation(); textAnnot.Title = "This is the title"; textAnnot.Subject = "This is the subject"; textAnnot.Contents = "This is the contents of the annotation.\rThis is the 2nd line."; textAnnot.Icon = PdfTextAnnotationIcon.Note; gfx.DrawString("The first text annotation", font, XBrushes.Black, 30, 50, XStringFormats.Default); // Convert rectangle form world space to page space. This is necessary because the annotation is // placed relative to the bottom left corner of the page with units measured in point. XRect rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 60), new XSize(30, 30))); textAnnot.Rectangle = new PdfRectangle(rect); // Add the annotation to the page page.Annotations.Add(textAnnot); // Create another PDF text annotation which is open and transparent textAnnot = new PdfTextAnnotation(); textAnnot.Title = "Annotation 2 (title)"; textAnnot.Subject = "Annotation 2 (subject)"; textAnnot.Contents = "This is the contents of the 2nd annotation."; textAnnot.Icon = PdfTextAnnotationIcon.Help; textAnnot.Color = XColors.LimeGreen; textAnnot.Opacity = 0.5; textAnnot.Open = true; gfx.DrawString("The second text annotation (opened)", font, XBrushes.Black, 30, 140, XStringFormats.Default); rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 150), new XSize(30, 30))); textAnnot.Rectangle = new PdfRectangle(rect); // Add the 2nd annotation to the page page.Annotations.Add(textAnnot); // Create a so called rubber stamp annotion. I'm not sure if it is useful, but at least // it looks impressive... PdfRubberStampAnnotation rsAnnot = new PdfRubberStampAnnotation(); rsAnnot.Icon = PdfRubberStampAnnotationIcon.TopSecret; rsAnnot.Flags = PdfAnnotationFlags.ReadOnly; rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(100, 400), new XSize(350, 150))); rsAnnot.Rectangle = new PdfRectangle(rect); // Add the rubber stamp annotation to the page page.Annotations.Add(rsAnnot); // PDF supports some more pretty types of annotations like PdfLineAnnotation, PdfSquareAnnotation, // PdfCircleAnnotation, PdfMarkupAnnotation (with the subtypes PdfHighlightAnnotation, PdfUnderlineAnnotation, // PdfStrikeOutAnnotation, and PdfSquigglyAnnotation), PdfSoundAnnotation, or PdfMovieAnnotation. // If you need one of them, feel encouraged to implement it. It is quite easy. // Save the document... const string filename = "AltData/PDFsharp/PDFs/Annotations_tempfile.pdf"; document.Save(filename); // ...and start a viewer. Diagnostics.ProcessHelper.Start(filename); }
internal static void Export(Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items) { List <PDFDocumentExportItem> pdf_document_export_items_values = new List <PDFDocumentExportItem>(pdf_document_export_items.Values); for (int i = 0; i < pdf_document_export_items_values.Count; ++i) { var item = pdf_document_export_items_values[i]; try { StatusManager.Instance.UpdateStatus("ContentExport", String.Format("Exporting entry {0} of {1}", i, pdf_document_export_items_values.Count), i, pdf_document_export_items_values.Count); using (PdfDocument document = PdfReader.Open(item.filename, PdfDocumentOpenMode.Modify)) { // First the properties document.Info.Title = item.pdf_document.TitleCombined; document.Info.Author = item.pdf_document.AuthorsCombined; document.Info.ModificationDate = DateTime.Now; document.Info.Creator = "Qiqqa.com library export v1"; { StringBuilder sb = new StringBuilder(); foreach (string tag in TagTools.ConvertTagBundleToTags(item.pdf_document.Tags)) { sb.Append(tag); sb.Append(";"); } document.Info.Keywords = sb.ToString(); } // Then the main comments (if any) { string comments = item.pdf_document.Comments; if (!String.IsNullOrEmpty(comments)) { PdfPage page = document.Pages[0]; using (XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend)) { XRect rect = new XRect(5, 5, 100, 100); PdfTextAnnotation new_annotation = new PdfTextAnnotation(); new_annotation.Contents = comments; new_annotation.Icon = PdfTextAnnotationIcon.Note; new_annotation.Rectangle = new PdfRectangle(gfx.Transformer.WorldToDefaultPage(rect)); page.Annotations.Add(new_annotation); } } } // Then the highlights foreach (PDFHighlight highlight in item.pdf_document.Highlights.GetAllHighlights()) { PdfPage page = document.Pages[highlight.Page - 1]; using (XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend)) { XColor color = XColor.FromArgb(StandardHighlightColours.GetColor(highlight.Color)); XPen pen = new XPen(color); XBrush brush = new XSolidBrush(color); XRect rect = new XRect(highlight.Left * gfx.PageSize.Width, highlight.Top * gfx.PageSize.Height, highlight.Width * gfx.PageSize.Width, highlight.Height * gfx.PageSize.Height); gfx.DrawRectangle(brush, rect); } } // Then the annotations foreach (PDFAnnotation annotation in item.pdf_document.GetAnnotations()) { if (annotation.Deleted) { continue; } PdfPage page = document.Pages[annotation.Page - 1]; using (XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend)) { XColor color = XColor.FromArgb(annotation.Color); XPen pen = new XPen(color); XBrush brush = new XSolidBrush(color); XRect rect = new XRect(annotation.Left * gfx.PageSize.Width, annotation.Top * gfx.PageSize.Height, annotation.Width * gfx.PageSize.Width, annotation.Height * gfx.PageSize.Height); gfx.DrawRectangle(brush, rect); PdfTextAnnotation new_annotation = new PdfTextAnnotation(); new_annotation.Contents = String.Format("Tags:{0}\n{1}", annotation.Tags, annotation.Text); new_annotation.Icon = PdfTextAnnotationIcon.Note; new_annotation.Color = color; new_annotation.Opacity = 0.5; new_annotation.Open = false; new_annotation.Rectangle = new PdfRectangle(gfx.Transformer.WorldToDefaultPage(rect)); page.Annotations.Add(new_annotation); //foreach (var pair in new_annotation.Elements) //{ // Logging.Debug(" {0}={1}", pair.Key, pair.Value); //} } } // Save it Logging.Info("Saving {0}", item.filename); document.Save(item.filename); } } catch (Exception ex) { Logging.Error(ex, "Error updating PDF for " + item.filename); } StatusManager.Instance.UpdateStatus("ContentExport", String.Format("Exported your PDF content")); } }
private void AddAnnotationToPdf(AnnotObject annotObject, PdfDocument pdfDocument) { String annotName = annotObject.GetName(); if (annotName != null) { switch (annotName) { case XfdfConstants.TEXT: { //TODO add all attributes properly one by one PdfTextAnnotation pdfTextAnnotation = new PdfTextAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject .GetAttributeValue(XfdfConstants.RECT))); AddCommonAnnotationAttributes(pdfTextAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfTextAnnotation, annotObject); pdfTextAnnotation.SetIconName(new PdfName(annotObject.GetAttributeValue(XfdfConstants.ICON))); if (annotObject.GetAttributeValue(XfdfConstants.STATE) != null) { pdfTextAnnotation.SetState(new PdfString(annotObject.GetAttributeValue(XfdfConstants.STATE))); } if (annotObject.GetAttributeValue(XfdfConstants.STATE_MODEL) != null) { pdfTextAnnotation.SetStateModel(new PdfString(annotObject.GetAttributeValue(XfdfConstants.STATE_MODEL))); } pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttributeValue(XfdfConstants.PAGE))).AddAnnotation(pdfTextAnnotation ); break; } case XfdfConstants.HIGHLIGHT: { PdfTextMarkupAnnotation pdfHighLightAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Highlight, XfdfObjectUtils.ConvertQuadPointsFromCoordsString (annotObject.GetAttributeValue(XfdfConstants.COORDS))); AddCommonAnnotationAttributes(pdfHighLightAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfHighLightAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfHighLightAnnotation); break; } case XfdfConstants.UNDERLINE: { PdfTextMarkupAnnotation pdfUnderlineAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Underline, XfdfObjectUtils.ConvertQuadPointsFromCoordsString (annotObject.GetAttributeValue(XfdfConstants.COORDS))); AddCommonAnnotationAttributes(pdfUnderlineAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfUnderlineAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfUnderlineAnnotation); break; } case XfdfConstants.STRIKEOUT: { PdfTextMarkupAnnotation pdfStrikeoutAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.StrikeOut, XfdfObjectUtils.ConvertQuadPointsFromCoordsString (annotObject.GetAttributeValue(XfdfConstants.COORDS))); AddCommonAnnotationAttributes(pdfStrikeoutAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfStrikeoutAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfStrikeoutAnnotation); break; } case XfdfConstants.SQUIGGLY: { PdfTextMarkupAnnotation pdfSquigglyAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Squiggly, XfdfObjectUtils.ConvertQuadPointsFromCoordsString (annotObject.GetAttributeValue(XfdfConstants.COORDS))); AddCommonAnnotationAttributes(pdfSquigglyAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfSquigglyAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfSquigglyAnnotation); break; } case XfdfConstants.CIRCLE: { // case XfdfConstants.LINE: // pdfDocument.getPage(Integer.parseInt(annotObject.getAttribute(XfdfConstants.PAGE).getValue())) // .addAnnotation(new PdfLineAnnotation(XfdfObjectUtils.convertRectFromString(annotObject.getAttributeValue(XfdfConstants.RECT)), XfdfObjectUtils.convertVerticesFromString(annotObject.getVertices()))); // break; PdfCircleAnnotation pdfCircleAnnotation = new PdfCircleAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject .GetAttributeValue(XfdfConstants.RECT))); AddCommonAnnotationAttributes(pdfCircleAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfCircleAnnotation, annotObject); if (annotObject.GetAttributeValue(XfdfConstants.FRINGE) != null) { pdfCircleAnnotation.SetRectangleDifferences(XfdfObjectUtils.ConvertFringeFromString(annotObject.GetAttributeValue (XfdfConstants.FRINGE))); } pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfCircleAnnotation); break; } case XfdfConstants.SQUARE: { PdfSquareAnnotation pdfSquareAnnotation = new PdfSquareAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject .GetAttributeValue(XfdfConstants.RECT))); AddCommonAnnotationAttributes(pdfSquareAnnotation, annotObject); AddMarkupAnnotationAttributes(pdfSquareAnnotation, annotObject); if (annotObject.GetAttributeValue(XfdfConstants.FRINGE) != null) { pdfSquareAnnotation.SetRectangleDifferences(XfdfObjectUtils.ConvertFringeFromString(annotObject.GetAttributeValue (XfdfConstants.FRINGE))); } pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (pdfSquareAnnotation); break; } case XfdfConstants.POLYGON: { //XfdfConstants.CARET Rectangle rect = XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants.RECT)); float[] vertices = XfdfObjectUtils.ConvertVerticesFromString(annotObject.GetVertices()); PdfPolyGeomAnnotation polygonAnnotation = PdfPolyGeomAnnotation.CreatePolygon(rect, vertices); AddCommonAnnotationAttributes(polygonAnnotation, annotObject); AddMarkupAnnotationAttributes(polygonAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (polygonAnnotation); break; } case XfdfConstants.POLYLINE: { Rectangle polylineRect = XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants .RECT)); float[] polylineVertices = XfdfObjectUtils.ConvertVerticesFromString(annotObject.GetVertices()); PdfPolyGeomAnnotation polylineAnnotation = PdfPolyGeomAnnotation.CreatePolyLine(polylineRect, polylineVertices ); AddCommonAnnotationAttributes(polylineAnnotation, annotObject); AddMarkupAnnotationAttributes(polylineAnnotation, annotObject); pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (polylineAnnotation); break; } case XfdfConstants.STAMP: { pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (new PdfStampAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants .RECT)))); break; } case XfdfConstants.FREETEXT: { //XfdfConstants.INK pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation (new PdfFreeTextAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants .RECT)), annotObject.GetContents())); break; } default: { //XfdfConstants.FILEATTACHMENT //XfdfConstants.SOUND //XfdfConstants.LINK //XfdfConstants.REDACT //XfdfConstants.PROJECTION logger.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.XFDF_ANNOTATION_IS_NOT_SUPPORTED, annotName )); break; } } } }
protected void ManipulatePdf(string dest) { PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest)); Document doc = new Document(pdfDoc); PdfViewerPreferences viewerPreferences = new PdfViewerPreferences(); viewerPreferences.SetPrintScaling(PdfViewerPreferences.PdfViewerPreferencesConstants.NONE); pdfDoc.GetCatalog().SetPageMode(PdfName.UseThumbs); pdfDoc.GetCatalog().SetPageLayout(PdfName.TwoPageLeft); pdfDoc.GetCatalog().SetViewerPreferences(viewerPreferences); doc.Add(new Paragraph("Hello World")); doc.Add(new Paragraph("Hello People")); doc.Add(new AreaBreak()); PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); // Add the text to the direct content, but not in the right order PdfCanvas canvas = new PdfCanvas(pdfDoc.GetPage(2)); canvas.BeginText(); canvas.SetFontAndSize(font, 12); canvas.MoveText(88.66f, 788); canvas.ShowText("ld"); canvas.MoveText(-22f, 0); canvas.ShowText("Wor"); canvas.MoveText(-15.33f, 0); canvas.ShowText("llo"); canvas.MoveText(-15.33f, 0); canvas.ShowText("He"); canvas.EndText(); PdfFormXObject formXObject = new PdfFormXObject(new Rectangle(250, 25)); new PdfCanvas(formXObject, pdfDoc) .BeginText() .SetFontAndSize(font, 12) .MoveText(0, 7) .ShowText("Hello People") .EndText(); canvas.AddXObjectAt(formXObject, 36, 763); pdfDoc.SetDefaultPageSize(new PageSize(PageSize.A4).Rotate()); doc.Add(new AreaBreak()); doc.Add(new Paragraph("Hello World")); pdfDoc.SetDefaultPageSize(new PageSize(842, 595)); doc.Add(new AreaBreak()); doc.Add(new Paragraph("Hello World")); pdfDoc.SetDefaultPageSize(PageSize.A4); doc.Add(new AreaBreak()); pdfDoc.GetLastPage().SetCropBox(new Rectangle(10, 70, 525, 755)); doc.Add(new Paragraph("Hello World")); doc.Add(new AreaBreak()); pdfDoc.GetLastPage().GetPdfObject().Put(PdfName.UserUnit, new PdfNumber(5)); doc.Add(new Paragraph("Hello World")); doc.Add(new AreaBreak()); pdfDoc.GetLastPage().SetArtBox(new Rectangle(36, 36, 523, 770)); Paragraph p = new Paragraph("Hello ") .Add(new Link("World", PdfAction.CreateURI("http://maps.google.com"))); doc.Add(p); PdfAnnotation a = new PdfTextAnnotation( new Rectangle(36, 755, 30, 30)) .SetTitle(new PdfString("Example")) .SetContents("This is a post-it annotation"); pdfDoc.GetLastPage().AddAnnotation(a); pdfDoc.GetPage(1).SetPageLabel(PageLabelNumberingStyle.UPPERCASE_LETTERS, null); pdfDoc.GetPage(3).SetPageLabel(PageLabelNumberingStyle.DECIMAL_ARABIC_NUMERALS, null); pdfDoc.GetPage(4).SetPageLabel(PageLabelNumberingStyle.DECIMAL_ARABIC_NUMERALS, "Custom-", 2); doc.Close(); }