Ejemplo n.º 1
0
        public static PdfAnnotation CreateMarkup(PdfWriter writer, Rectangle rect, string contents, int type, float[] quadPoints)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);
            PdfName       name  = PdfName.Highlight;

            switch (type)
            {
            case MARKUP_UNDERLINE:
                name = PdfName.Underline;
                break;

            case MARKUP_STRIKEOUT:
                name = PdfName.Strikeout;
                break;

            case MARKUP_SQUIGGLY:
                name = PdfName.Squiggly;
                break;
            }
            annot.Put(PdfName.Subtype, name);
            annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            PdfArray array = new PdfArray();

            for (int k = 0; k < quadPoints.Length; ++k)
            {
                array.Add(new PdfNumber(quadPoints[k]));
            }
            annot.Put(PdfName.Quadpoints, array);
            return(annot);
        }
Ejemplo n.º 2
0
        public static PdfAnnotation CreateMarkup(PdfWriter writer, Rectangle rect, string contents, int type, float[] quadPoints)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);
            PdfName       name  = PdfName.HIGHLIGHT;

            switch (type)
            {
            case MARKUP_UNDERLINE:
                name = PdfName.UNDERLINE;
                break;

            case MARKUP_STRIKEOUT:
                name = PdfName.STRIKEOUT;
                break;

            case MARKUP_SQUIGGLY:
                name = PdfName.SQUIGGLY;
                break;
            }
            annot.Put(PdfName.SUBTYPE, name);
            annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            PdfArray array = new PdfArray();

            for (int k = 0; k < quadPoints.Length; ++k)
            {
                array.Add(new PdfNumber(quadPoints[k]));
            }
            annot.Put(PdfName.QUADPOINTS, array);
            return(annot);
        }
Ejemplo n.º 3
0
        public static PdfAnnotation CreateStamp(PdfWriter writer, Rectangle rect, string contents, string name)
        {
            PdfAnnotation annot = writer.CreateAnnotation(rect, PdfName.STAMP);

            annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            annot.Put(PdfName.NAME, new PdfName(name));
            return(annot);
        }
Ejemplo n.º 4
0
        // ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
              using (Document document = new Document()) {
            // step 2
            PdfWriter writer = PdfWriter.GetInstance(document, stream);
            // step 3
            document.Open();
            // step 4
            Rectangle rect = new Rectangle(100, 400, 500, 800);
            rect.Border = Rectangle.BOX;
            rect.BorderWidth = 0.5f;
            rect.BorderColor = new BaseColor(0xFF, 0x00, 0x00);
            document.Add(rect);

            PdfIndirectObject streamObject = null;
            using (FileStream fs =
              new FileStream(RESOURCE, FileMode.Open, FileAccess.Read))
            {
              PdfStream stream3D = new PdfStream(fs, writer);

              stream3D.Put(PdfName.TYPE, new PdfName("3D"));
              stream3D.Put(PdfName.SUBTYPE, new PdfName("U3D"));
              stream3D.FlateCompress();
              streamObject = writer.AddToBody(stream3D);
              stream3D.WriteLength();
            }

            PdfDictionary dict3D = new PdfDictionary();
            dict3D.Put(PdfName.TYPE, new PdfName("3DView"));
            dict3D.Put(new PdfName("XN"), new PdfString("Default"));
            dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
            dict3D.Put(new PdfName("MS"), PdfName.M);
            dict3D.Put(
              new PdfName("C2W"),
              new PdfArray(
            new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }
              )
            );
            dict3D.Put(PdfName.CO, new PdfNumber(235));

            PdfIndirectObject dictObject = writer.AddToBody(dict3D);

            PdfAnnotation annot = new PdfAnnotation(writer, rect);
            annot.Put(PdfName.CONTENTS, new PdfString("3D Model"));
            annot.Put(PdfName.SUBTYPE, new PdfName("3D"));
            annot.Put(PdfName.TYPE, PdfName.ANNOT);
            annot.Put(new PdfName("3DD"), streamObject.IndirectReference);
            annot.Put(new PdfName("3DV"), dictObject.IndirectReference);
            PdfAppearance ap = writer.DirectContent.CreateAppearance(
              rect.Width, rect.Height
            );
            annot.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
            annot.SetPage();

            writer.AddAnnotation(annot);
              }
        }
Ejemplo n.º 5
0
        public static PdfAnnotation CreateStamp(PdfWriter writer, Rectangle rect, string contents, string name)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.Subtype, PdfName.Stamp);
            annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            annot.Put(PdfName.Name, new PdfName(name));
            return(annot);
        }
Ejemplo n.º 6
0
        public static PdfAnnotation CreateFreeText(PdfWriter writer, Rectangle rect, string contents, PdfContentByte defaultAppearance)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.SUBTYPE, PdfName.FREETEXT);
            annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            annot.DefaultAppearanceString = defaultAppearance;
            return(annot);
        }
Ejemplo n.º 7
0
        public static PdfAnnotation CreateFreeText(PdfWriter writer, Rectangle rect, string contents, PdfContentByte defaultAppearance)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.Subtype, PdfName.Freetext);
            annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            annot.DefaultAppearanceString = defaultAppearance;
            return(annot);
        }
Ejemplo n.º 8
0
        protected static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.SUBTYPE, PdfName.LINK);
            if (!highlight.Equals(HIGHLIGHT_INVERT))
            {
                annot.Put(PdfName.H, highlight);
            }
            return(annot);
        }
Ejemplo n.º 9
0
        protected static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.Subtype, PdfName.Link);
            if (!highlight.Equals(HighlightInvert))
            {
                annot.Put(PdfName.H, highlight);
            }
            return(annot);
        }
Ejemplo n.º 10
0
        /** Creates a file attachment annotation
         * @param writer
         * @param rect
         * @param contents
         * @param fs
         * @return the annotation
         * @throws IOException
         */
        public static PdfAnnotation CreateFileAttachment(PdfWriter writer, Rectangle rect, String contents, PdfFileSpecification fs)
        {
            PdfAnnotation annot = writer.CreateAnnotation(rect, PdfName.FILEATTACHMENT);

            if (contents != null)
            {
                annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            }
            annot.Put(PdfName.FS, fs.Reference);
            return(annot);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a file attachment annotation
        /// @throws IOException
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="rect"></param>
        /// <param name="contents"></param>
        /// <param name="fs"></param>
        /// <returns>the annotation</returns>
        public static PdfAnnotation CreateFileAttachment(PdfWriter writer, Rectangle rect, string contents, PdfFileSpecification fs)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.Subtype, PdfName.Fileattachment);
            if (contents != null)
            {
                annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            }
            annot.Put(PdfName.Fs, fs.Reference);
            return(annot);
        }
Ejemplo n.º 12
0
        public static PdfAnnotation CreateLine(PdfWriter writer, Rectangle rect, string contents, float x1, float y1, float x2, float y2)
        {
            PdfAnnotation annot = writer.CreateAnnotation(rect, PdfName.LINE);

            annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            PdfArray array = new PdfArray(new PdfNumber(x1));

            array.Add(new PdfNumber(y1));
            array.Add(new PdfNumber(x2));
            array.Add(new PdfNumber(y2));
            annot.Put(PdfName.L, array);
            return(annot);
        }
Ejemplo n.º 13
0
        public static PdfAnnotation CreateLine(PdfWriter writer, Rectangle rect, string contents, float x1, float y1, float x2, float y2)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.Subtype, PdfName.Line);
            annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            PdfArray array = new PdfArray(new PdfNumber(x1));

            array.Add(new PdfNumber(y1));
            array.Add(new PdfNumber(x2));
            array.Add(new PdfNumber(y2));
            annot.Put(PdfName.L, array);
            return(annot);
        }
Ejemplo n.º 14
0
        public static PdfAnnotation CreatePopup(PdfWriter writer, Rectangle rect, string contents, bool open)
        {
            PdfAnnotation annot = writer.CreateAnnotation(rect, PdfName.POPUP);

            if (contents != null)
            {
                annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            }
            if (open)
            {
                annot.Put(PdfName.OPEN, PdfBoolean.PDFTRUE);
            }
            return(annot);
        }
Ejemplo n.º 15
0
        public static PdfAnnotation CreateSquareCircle(PdfWriter writer, Rectangle rect, string contents, bool square)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            if (square)
            {
                annot.Put(PdfName.SUBTYPE, PdfName.SQUARE);
            }
            else
            {
                annot.Put(PdfName.SUBTYPE, PdfName.CIRCLE);
            }
            annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            return(annot);
        }
Ejemplo n.º 16
0
        public static PdfAnnotation CreateSquareCircle(PdfWriter writer, Rectangle rect, string contents, bool square)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            if (square)
            {
                annot.Put(PdfName.Subtype, PdfName.Square);
            }
            else
            {
                annot.Put(PdfName.Subtype, PdfName.Circle);
            }
            annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            return(annot);
        }
Ejemplo n.º 17
0
        public static PdfAnnotation CreatePopup(PdfWriter writer, Rectangle rect, string contents, bool open)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.Subtype, PdfName.Popup);
            if (contents != null)
            {
                annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            }
            if (open)
            {
                annot.Put(PdfName.Open, PdfBoolean.Pdftrue);
            }
            return(annot);
        }
Ejemplo n.º 18
0
        public static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight, string namedDestination)
        {
            PdfAnnotation annot = CreateLink(writer, rect, highlight);

            annot.Put(PdfName.DEST, new PdfString(namedDestination, PdfObject.TEXT_UNICODE));
            return(annot);
        }
Ejemplo n.º 19
0
        public virtual bool SetFieldAsJavascript(String field, PdfName jsTrigName, String js)
        {
            PdfAnnotation dict       = wrt.CreateAnnotation(null, null);
            PdfAction     javascript = PdfAction.JavaScript(js, wrt);

            dict.Put(jsTrigName, javascript);
            return(SetField(field, dict));
        }
Ejemplo n.º 20
0
        /**
         * Creates a polygon or -line annotation
         * @param writer the PdfWriter
         * @param rect the annotation position
         * @param contents the textual content of the annotation
         * @param polygon if true, the we're creating a polygon annotation, if false, a polyline
         * @param vertices an array with the vertices of the polygon or -line
         * @since 5.0.2
         */
        public static PdfAnnotation CreatePolygonPolyline(
            PdfWriter writer, Rectangle rect, String contents, bool polygon, PdfArray vertices)
        {
            PdfAnnotation annot = null;

            if (polygon)
            {
                annot = writer.CreateAnnotation(rect, PdfName.POLYGON);
            }
            else
            {
                annot = writer.CreateAnnotation(rect, PdfName.POLYLINE);
            }
            annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            annot.Put(PdfName.VERTICES, new PdfArray(vertices));
            return(annot);
        }
Ejemplo n.º 21
0
 /**
  * @see com.itextpdf.text.pdf.PdfPageEventHelper#onGenericTag(
  *      com.itextpdf.text.pdf.PdfWriter,
  *      com.itextpdf.text.Document,
  *      com.itextpdf.text.Rectangle, java.lang.String)
  */
 public override void OnGenericTag(PdfWriter writer,
   Document document, Rectangle rect, string text)
 {
     PdfAnnotation annotation = new PdfAnnotation(writer,
       new Rectangle(
         rect.Right + 10, rect.Bottom,
         rect.Right + 30, rect.Top
       )
     );
     annotation.Title = "Text annotation";
     annotation.Put(PdfName.SUBTYPE, PdfName.TEXT);
     annotation.Put(PdfName.OPEN, PdfBoolean.PDFFALSE);
     annotation.Put(PdfName.CONTENTS,
       new PdfString(string.Format("Icon: {0}", text))
     );
     annotation.Put(PdfName.NAME, new PdfName(text));
     writer.AddAnnotation(annotation);
 }
Ejemplo n.º 22
0
        public static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight, int page, PdfDestination dest)
        {
            PdfAnnotation        annot = CreateLink(writer, rect, highlight);
            PdfIndirectReference piref = writer.GetPageReference(page);

            dest.AddPage(piref);
            annot.Put(PdfName.DEST, dest);
            return(annot);
        }
Ejemplo n.º 23
0
        public override PdfAnnotation CreateAnnotation(Rectangle rect, PdfName subtype)
        {
            PdfAnnotation a = base.CreateAnnotation(rect, subtype);

            if (!PdfName.POPUP.Equals(subtype))
            {
                a.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            }
            return(a);
        }
Ejemplo n.º 24
0
        public override PdfAnnotation CreateAnnotation(float llx, float lly, float urx, float ury, PdfAction action, PdfName subtype)
        {
            PdfAnnotation a = base.CreateAnnotation(llx, lly, urx, ury, action, subtype);

            if (!PdfName.POPUP.Equals(subtype))
            {
                a.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            }
            return(a);
        }
Ejemplo n.º 25
0
        public static PdfAnnotation CreateInk(PdfWriter writer, Rectangle rect, string contents, float[][] inkList)
        {
            PdfAnnotation annot = writer.CreateAnnotation(rect, PdfName.INK);

            annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            PdfArray outer = new PdfArray();

            for (int k = 0; k < inkList.Length; ++k)
            {
                PdfArray inner = new PdfArray();
                float[]  deep  = inkList[k];
                for (int j = 0; j < deep.Length; ++j)
                {
                    inner.Add(new PdfNumber(deep[j]));
                }
                outer.Add(inner);
            }
            annot.Put(PdfName.INKLIST, outer);
            return(annot);
        }
Ejemplo n.º 26
0
        public static PdfAnnotation CreateInk(PdfWriter writer, Rectangle rect, string contents, float[][] inkList)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.Subtype, PdfName.Ink);
            annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            PdfArray outer = new PdfArray();

            for (int k = 0; k < inkList.Length; ++k)
            {
                PdfArray inner = new PdfArray();
                float[]  deep  = inkList[k];
                for (int j = 0; j < deep.Length; ++j)
                {
                    inner.Add(new PdfNumber(deep[j]));
                }
                outer.Add(inner);
            }
            annot.Put(PdfName.Inklist, outer);
            return(annot);
        }
Ejemplo n.º 27
0
        /**
         * Creates a screen PdfAnnotation
         * @param writer
         * @param rect
         * @param clipTitle
         * @param fs
         * @param mimeType
         * @param playOnDisplay
         * @return a screen PdfAnnotation
         * @throws IOException
         */
        public static PdfAnnotation CreateScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs,
                                                 String mimeType, bool playOnDisplay)
        {
            PdfAnnotation ann = writer.CreateAnnotation(rect, PdfName.SCREEN);

            ann.Put(PdfName.F, new PdfNumber(FLAGS_PRINT));
            ann.Put(PdfName.TYPE, PdfName.ANNOT);
            ann.SetPage();
            PdfIndirectReference refi      = ann.IndirectReference;
            PdfAction            action    = PdfAction.Rendition(clipTitle, fs, mimeType, refi);
            PdfIndirectReference actionRef = writer.AddToBody(action).IndirectReference;

            // for play on display add trigger event
            if (playOnDisplay)
            {
                PdfDictionary aa = new PdfDictionary();
                aa.Put(new PdfName("PV"), actionRef);
                ann.Put(PdfName.AA, aa);
            }
            ann.Put(PdfName.A, actionRef);
            return(ann);
        }
Ejemplo n.º 28
0
        public static PdfAnnotation CreateText(PdfWriter writer, Rectangle rect, string title, string contents, bool open, string icon)
        {
            PdfAnnotation annot = writer.CreateAnnotation(rect, PdfName.TEXT);

            if (title != null)
            {
                annot.Put(PdfName.T, new PdfString(title, PdfObject.TEXT_UNICODE));
            }
            if (contents != null)
            {
                annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
            }
            if (open)
            {
                annot.Put(PdfName.OPEN, PdfBoolean.PDFTRUE);
            }
            if (icon != null)
            {
                annot.Put(PdfName.NAME, new PdfName(icon));
            }
            return(annot);
        }
Ejemplo n.º 29
0
        public static PdfAnnotation CreateText(PdfWriter writer, Rectangle rect, string title, string contents, bool open, string icon)
        {
            PdfAnnotation annot = new PdfAnnotation(writer, rect);

            annot.Put(PdfName.Subtype, PdfName.Text);
            if (title != null)
            {
                annot.Put(PdfName.T, new PdfString(title, TEXT_UNICODE));
            }
            if (contents != null)
            {
                annot.Put(PdfName.Contents, new PdfString(contents, TEXT_UNICODE));
            }
            if (open)
            {
                annot.Put(PdfName.Open, PdfBoolean.Pdftrue);
            }
            if (icon != null)
            {
                annot.Put(PdfName.Name, new PdfName(icon));
            }
            return(annot);
        }
Ejemplo n.º 30
0
            public PdfAnnotation CreateAnnotation(PdfWriter writer)
            {
                PdfAnnotation annotation = new PdfAnnotation(writer, new Rectangle(_llx, _lly, _urx, _ury));

                if (_newPage != 0)
                {
                    PdfIndirectReference refi = writer.GetPageReference(_newPage);
                    _destination[0] = refi;
                }
                if (_destination != null)
                {
                    annotation.Put(PdfName.Dest, _destination);
                }
                foreach (object key in _parameters.Keys)
                {
                    annotation.HashMap[key] = _parameters[key];
                }
                return(annotation);
            }
Ejemplo n.º 31
0
            virtual public PdfAnnotation CreateAnnotation(PdfWriter writer)
            {
                PdfAnnotation annotation = writer.CreateAnnotation(new Rectangle(llx, lly, urx, ury), null);

                if (newPage != 0)
                {
                    PdfIndirectReference refi = writer.GetPageReference(newPage);
                    destination.Set(0, refi);
                }
                if (destination != null)
                {
                    annotation.Put(PdfName.DEST, destination);
                }
                foreach (PdfName key in parameters.Keys)
                {
                    annotation.hashMap[key] = parameters[key];
                }
                return(annotation);
            }
Ejemplo n.º 32
0
        public void AnnotationCheckTest6() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest6.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_2B);
            writer.CreateXmpMetadata();
            document.Open();

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            annot.Put(PdfName.SUBTYPE, PdfName.WIDGET);
            annot.Put(PdfName.CONTENTS, new PdfDictionary());
            annot.Put(PdfName.FT, new PdfName("Btn"));
            PdfDictionary ap = new PdfDictionary();
            PdfStream s = new PdfStream(Encoding.Default.GetBytes("Hello World"));
            //PdfDictionary s = new PdfDictionary();
            ap.Put(PdfName.N, writer.AddToBody(s).IndirectReference);
            annot.Put(PdfName.AP, ap);
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            bool exceptionThrown = false;
            try {
                document.Close();
            }
            catch (PdfAConformanceException e) {
                if (e.GetObject() == annot && e.Message
                    .Equals("Appearance dictionary of Widget subtype and Btn field type shall contain only the n key with dictionary value")) {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException should be thrown.");
        }
Ejemplo n.º 33
0
        public void AnnotationCheckTest4() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest4.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_2B);
            writer.CreateXmpMetadata();
            document.Open();

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.TEXT);
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT & PdfAnnotation.FLAGS_INVISIBLE));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            bool exceptionThrown = false;
            try {
                document.Close();
            }
            catch (PdfAConformanceException e) {
                if (e.GetObject() == annot && e.Message
                    .Equals("The F key's Print flag bit shall be set to 1 and its Hidden, Invisible, NoView and ToggleNoView flag bits shall be set to 0.")) {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException should be thrown.");
        }
Ejemplo n.º 34
0
        public void AnnotationCheckTest2_3() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest2_3.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_2B);
            writer.CreateXmpMetadata();
            document.Open();

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.WIDGET);
            annot.Put(PdfName.CONTENTS, new PdfDictionary());
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            bool exceptionThrown = false;
            try {
                document.Close();
            }
            catch (PdfAConformanceException e) {
                if (e.GetObject() == annot && e.Message.Equals("Every annotation shall have at least one appearance dictionary")) {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException with correct message should be thrown.");
        }
Ejemplo n.º 35
0
        public void AnnotationCheckTest2_2() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest2_2.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_2B);
            writer.CreateXmpMetadata();
            document.Open();

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 200, 100, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.WIDGET);
            annot.Put(PdfName.CONTENTS, new PdfDictionary());
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            document.Close();
        }
Ejemplo n.º 36
0
 public static PdfAnnotation CreateSquareCircle(PdfWriter writer, Rectangle rect, string contents, bool square)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     if (square)
         annot.Put(PdfName.SUBTYPE, PdfName.SQUARE);
     else
         annot.Put(PdfName.SUBTYPE, PdfName.CIRCLE);
     annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     return annot;
 }
Ejemplo n.º 37
0
 internal void AddAnnotation(PdfAnnotation annot, PdfDictionary pageN)
 {
     ArrayList allAnnots = new ArrayList();
     if (annot.IsForm()) {
         fieldsAdded = true;
         AcroFields afdummy = AcroFields;
         PdfFormField field = (PdfFormField)annot;
         if (field.Parent != null)
             return;
         ExpandFields(field, allAnnots);
     }
     else
         allAnnots.Add(annot);
     for (int k = 0; k < allAnnots.Count; ++k) {
         annot = (PdfAnnotation)allAnnots[k];
         if (annot.PlaceInPage > 0)
             pageN = reader.GetPageN(annot.PlaceInPage);
         if (annot.IsForm()) {
             if (!annot.IsUsed()) {
                 Hashtable templates = annot.Templates;
                 if (templates != null) {
                     foreach (object tpl in templates.Keys) {
                         fieldTemplates[tpl] = null;
                     }
                 }
             }
             PdfFormField field = (PdfFormField)annot;
             if (field.Parent == null)
                 AddDocumentField(field.IndirectReference);
         }
         if (annot.IsAnnotation()) {
             PdfArray annots = (PdfArray)PdfReader.GetPdfObject(pageN.Get(PdfName.ANNOTS), pageN);
             if (annots == null) {
                 annots = new PdfArray();
                 pageN.Put(PdfName.ANNOTS, annots);
                 MarkUsed(pageN);
             }
             annots.Add(annot.IndirectReference);
             MarkUsed(annots);
             if (!annot.IsUsed()) {
                 PdfRectangle rect = (PdfRectangle)annot.Get(PdfName.RECT);
                 if (rect != null && (rect.Left != 0 || rect.Right != 0 || rect.Top != 0 || rect.Bottom != 0)) {
                     int rotation = reader.GetPageRotation(pageN);
                     Rectangle pageSize = reader.GetPageSizeWithRotation(pageN);
                     switch (rotation) {
                         case 90:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 pageSize.Top - rect.Bottom,
                                 rect.Left,
                                 pageSize.Top - rect.Top,
                                 rect.Right));
                             break;
                         case 180:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 pageSize.Right - rect.Left,
                                 pageSize.Top - rect.Bottom,
                                 pageSize.Right - rect.Right,
                                 pageSize.Top - rect.Top));
                             break;
                         case 270:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 rect.Bottom,
                                 pageSize.Right - rect.Left,
                                 rect.Top,
                                 pageSize.Right - rect.Right));
                             break;
                     }
                 }
             }
         }
         if (!annot.IsUsed()) {
             annot.SetUsed();
             AddToBody(annot, annot.IndirectReference);
         }
     }
 }
Ejemplo n.º 38
0
 public static PdfAnnotation CreatePopup(PdfWriter writer, Rectangle rect, string contents, bool open)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.POPUP);
     if (contents != null)
         annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     if (open)
         annot.Put(PdfName.OPEN, PdfBoolean.PDFTRUE);
     return annot;
 }
Ejemplo n.º 39
0
 /**
  * Creates a polygon or -line annotation
  * @param writer the PdfWriter
  * @param rect the annotation position
  * @param contents the textual content of the annotation
  * @param polygon if true, the we're creating a polygon annotation, if false, a polyline
  * @param vertices an array with the vertices of the polygon or -line
  * @since 5.0.2
  */
 public static PdfAnnotation CreatePolygonPolyline(
     PdfWriter writer, Rectangle rect, String contents, bool polygon, PdfArray vertices)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     if (polygon)
         annot.Put(PdfName.SUBTYPE, PdfName.POLYGON);
     else
         annot.Put(PdfName.SUBTYPE, PdfName.POLYLINE);
     annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     annot.Put(PdfName.VERTICES, new PdfArray(vertices));
     return annot;
 }
Ejemplo n.º 40
0
 public static PdfAnnotation CreateText(PdfWriter writer, Rectangle rect, string title, string contents, bool open, string icon)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.TEXT);
     if (title != null)
         annot.Put(PdfName.T, new PdfString(title, PdfObject.TEXT_UNICODE));
     if (contents != null)
         annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     if (open)
         annot.Put(PdfName.OPEN, PdfBoolean.PDFTRUE);
     if (icon != null) {
         annot.Put(PdfName.NAME, new PdfName(icon));
     }
     return annot;
 }
Ejemplo n.º 41
0
 protected static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.LINK);
     if (!highlight.Equals(HIGHLIGHT_INVERT))
         annot.Put(PdfName.H, highlight);
     return annot;
 }
Ejemplo n.º 42
0
 public PdfAnnotation CreateAnnotation(PdfWriter writer)
 {
     PdfAnnotation annotation = new PdfAnnotation(writer, new Rectangle(llx, lly, urx, ury));
     if (newPage != 0) {
         PdfIndirectReference refi = writer.GetPageReference(newPage);
         destination[0] = refi;
     }
     if (destination != null) annotation.Put(PdfName.DEST, destination);
     foreach (PdfName key in parameters.Keys)
         annotation.hashMap[key] = parameters[key];
     return annotation;
 }
Ejemplo n.º 43
0
 /**
  * Creates a RichMediaAnnotation using rich media content that has already
  * been added to the writer. Note that assets, configurations, views added
  * to a RichMediaAnnotation created like this will be ignored.
  * @param   writer  the PdfWriter to which the annotation will be added.
  * @param   rect    the rectangle where the annotation will be added.
  * @param   richMediaContentReference   reused rich media content.
  */
 public RichMediaAnnotation(PdfWriter writer, Rectangle rect, PdfIndirectReference richMediaContentReference) {
     this.richMediaContentReference = richMediaContentReference;
     richMediaContent = null;
     this.writer = writer;
     annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.RICHMEDIA);
 }
Ejemplo n.º 44
0
        virtual public void AnnotationCheckTest8()
        {
            string filename = OUT + "AnnotationCheckTest8.pdf";
            FileStream fos = new FileStream(filename, FileMode.Create);

            Document document = new Document();

            PdfAWriter writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_1A);
            writer.CreateXmpMetadata();

            document.Open();

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.STAMP);
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            bool exceptionThrown = false;
            try
            {
                document.Close();
            }
            catch (PdfAConformanceException e)
            {
                if (e.GetObject().Equals(annot) && e.Message.Equals("Annotation of type /Stamp should have Contents key."))
                {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException with correct message should be thrown.");
        }
Ejemplo n.º 45
0
 public static PdfAnnotation CreateLine(PdfWriter writer, Rectangle rect, string contents, float x1, float y1, float x2, float y2)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.LINE);
     annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     PdfArray array = new PdfArray(new PdfNumber(x1));
     array.Add(new PdfNumber(y1));
     array.Add(new PdfNumber(x2));
     array.Add(new PdfNumber(y2));
     annot.Put(PdfName.L, array);
     return annot;
 }
Ejemplo n.º 46
0
 /** Creates a file attachment annotation
 * @param writer
 * @param rect
 * @param contents
 * @param fs
 * @return the annotation
 * @throws IOException
 */
 public static PdfAnnotation CreateFileAttachment(PdfWriter writer, Rectangle rect, String contents, PdfFileSpecification fs)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.FILEATTACHMENT);
     if (contents != null)
         annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     annot.Put(PdfName.FS, fs.Reference);
     return annot;
 }
Ejemplo n.º 47
0
 /**
 * Creates a screen PdfAnnotation
 * @param writer
 * @param rect
 * @param clipTitle
 * @param fs
 * @param mimeType
 * @param playOnDisplay
 * @return a screen PdfAnnotation
 * @throws IOException
 */
 public static PdfAnnotation CreateScreen(PdfWriter writer, Rectangle rect, String clipTitle, PdfFileSpecification fs,
                                         String mimeType, bool playOnDisplay)
 {
     PdfAnnotation ann = new PdfAnnotation(writer, rect);
     ann.Put(PdfName.SUBTYPE, PdfName.SCREEN);
     ann.Put (PdfName.F, new PdfNumber(FLAGS_PRINT));
     ann.Put(PdfName.TYPE, PdfName.ANNOT);
     ann.SetPage();
     PdfIndirectReference refi = ann.IndirectReference;
     PdfAction action = PdfAction.Rendition(clipTitle,fs,mimeType, refi);
     PdfIndirectReference actionRef = writer.AddToBody(action).IndirectReference;
     // for play on display add trigger event
     if (playOnDisplay)
     {
         PdfDictionary aa = new PdfDictionary();
         aa.Put(new PdfName("PV"), actionRef);
         ann.Put(PdfName.AA, aa);
     }
     ann.Put(PdfName.A, actionRef);
     return ann;
 }
Ejemplo n.º 48
0
 public static PdfAnnotation CreateStamp(PdfWriter writer, Rectangle rect, string contents, string name)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.STAMP);
     annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     annot.Put(PdfName.NAME, new PdfName(name));
     return annot;
 }
Ejemplo n.º 49
0
 /**
  * Creates a RichMediaAnnotation.
  * @param   writer  the PdfWriter to which the annotation will be added.
  * @param   rect    the rectangle where the annotation will be added.
  */
 public RichMediaAnnotation(PdfWriter writer, Rectangle rect) {
     this.writer = writer;
     annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.RICHMEDIA);
     richMediaContent = new PdfDictionary(PdfName.RICHMEDIACONTENT);
     assetsmap = new Dictionary<string,PdfIndirectReference>();
     configurations = new PdfArray();
     views = new PdfArray();
 }
            public void AddAnnotation(PdfAnnotation annot)
            {
                var allAnnots = new ArrayList();

                if (annot.IsForm())
                {
                    var field = (PdfFormField)annot;
                    if (field.Parent != null)
                    {
                        return;
                    }

                    expandFields(field, allAnnots);
                    if (_cstp.FieldTemplates == null)
                    {
                        _cstp.FieldTemplates = new Hashtable();
                    }
                }
                else
                {
                    allAnnots.Add(annot);
                }

                for (var k = 0; k < allAnnots.Count; ++k)
                {
                    annot = (PdfAnnotation)allAnnots[k];
                    if (annot.IsForm())
                    {
                        if (!annot.IsUsed())
                        {
                            var templates = annot.Templates;
                            if (templates != null)
                            {
                                foreach (var tpl in templates.Keys)
                                {
                                    _cstp.FieldTemplates[tpl] = null;
                                }
                            }
                        }
                        var field = (PdfFormField)annot;
                        if (field.Parent == null)
                        {
                            addDocumentField(field.IndirectReference);
                        }
                    }
                    if (annot.IsAnnotation())
                    {
                        var      pdfobj = PdfReader.GetPdfObject(_pageN.Get(PdfName.Annots), _pageN);
                        PdfArray annots = null;
                        if (pdfobj == null || !pdfobj.IsArray())
                        {
                            annots = new PdfArray();
                            _pageN.Put(PdfName.Annots, annots);
                        }
                        else
                        {
                            annots = (PdfArray)pdfobj;
                        }

                        annots.Add(annot.IndirectReference);
                        if (!annot.IsUsed())
                        {
                            var rect = (PdfRectangle)annot.Get(PdfName.Rect);
                            if (rect != null && (rect.Left.ApproxNotEqual(0) || rect.Right.ApproxNotEqual(0) || rect.Top.ApproxNotEqual(0) || rect.Bottom.ApproxNotEqual(0)))
                            {
                                var rotation = _reader.GetPageRotation(_pageN);
                                var pageSize = _reader.GetPageSizeWithRotation(_pageN);
                                switch (rotation)
                                {
                                case 90:
                                    annot.Put(PdfName.Rect, new PdfRectangle(
                                                  pageSize.Top - rect.Bottom,
                                                  rect.Left,
                                                  pageSize.Top - rect.Top,
                                                  rect.Right));
                                    break;

                                case 180:
                                    annot.Put(PdfName.Rect, new PdfRectangle(
                                                  pageSize.Right - rect.Left,
                                                  pageSize.Top - rect.Bottom,
                                                  pageSize.Right - rect.Right,
                                                  pageSize.Top - rect.Top));
                                    break;

                                case 270:
                                    annot.Put(PdfName.Rect, new PdfRectangle(
                                                  rect.Bottom,
                                                  pageSize.Right - rect.Left,
                                                  rect.Top,
                                                  pageSize.Right - rect.Right));
                                    break;
                                }
                            }
                        }
                    }
                    if (!annot.IsUsed())
                    {
                        annot.SetUsed();
                        _cstp.AddToBody(annot, annot.IndirectReference);
                    }
                }
            }
Ejemplo n.º 51
0
        public void AnnotationCheckTest9()
        {
            string filename = OUT + "annotationCheckTest9.pdf";
            FileStream fos = new FileStream(filename, FileMode.Create);

            Document document = new Document();

            PdfAWriter writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_1A);
            writer.CreateXmpMetadata();
            writer.SetTagged();

            document.Open();
            document.AddLanguage("en-US");

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccProfileFileStream = new FileStream(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.STAMP);
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            annot.Put(PdfName.CONTENTS, new PdfString("Hello World"));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            document.Close();
        }
Ejemplo n.º 52
0
 public static PdfAnnotation CreateInk(PdfWriter writer, Rectangle rect, string contents, float[][] inkList)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.INK);
     annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     PdfArray outer = new PdfArray();
     for (int k = 0; k < inkList.Length; ++k) {
         PdfArray inner = new PdfArray();
         float[] deep = inkList[k];
         for (int j = 0; j < deep.Length; ++j)
             inner.Add(new PdfNumber(deep[j]));
         outer.Add(inner);
     }
     annot.Put(PdfName.INKLIST, outer);
     return annot;
 }
Ejemplo n.º 53
0
        public void AnnotationCheckTest3()
        {
            string filename = OUT + "annotationCheckTest3.pdf";
            FileStream fos = new FileStream(filename, FileMode.Create);

            Document document = new Document();

            PdfAWriter writer = PdfAWriter.GetInstance(document, fos, PdfAConformanceLevel.PDF_A_1B);
            writer.CreateXmpMetadata();

            document.Open();

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccProfileFileStream = new FileStream(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.F, new PdfNumber(0));
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            bool exceptionThrown = false;
            try
            {
                document.Close();
            }
            catch (PdfAConformanceException e)
            {
                if (e.GetObject() == annot)
                {
                    exceptionThrown = true;
                }
            }
            if (!exceptionThrown)
                Assert.Fail("PdfAConformanceException should be thrown.");
        }
Ejemplo n.º 54
0
 public static PdfAnnotation CreateFreeText(PdfWriter writer, Rectangle rect, string contents, PdfContentByte defaultAppearance)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.FREETEXT);
     annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     annot.DefaultAppearanceString = defaultAppearance;
     return annot;
 }
Ejemplo n.º 55
0
 /**
  * A wrapper around PdfAnnotation constructor.
  * It is recommended to use this wrapper instead of direct constructor as this is a convenient way to override PdfAnnotation construction when needed.
  *
  * @param llx
  * @param lly
  * @param urx
  * @param ury
  * @param action
  * @param subtype
  * @return
  */
 public virtual PdfAnnotation CreateAnnotation(float llx, float lly, float urx, float ury, PdfAction action, PdfName subtype) {
     PdfAnnotation a = new PdfAnnotation(this, llx, lly, urx, ury, action);
     if (subtype != null)
         a.Put(PdfName.SUBTYPE, subtype);
     return a;
 }
Ejemplo n.º 56
0
 public static PdfAnnotation CreateMarkup(PdfWriter writer, Rectangle rect, string contents, int type, float[] quadPoints)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     PdfName name = PdfName.HIGHLIGHT;
     switch (type) {
         case MARKUP_UNDERLINE:
             name = PdfName.UNDERLINE;
             break;
         case MARKUP_STRIKEOUT:
             name = PdfName.STRIKEOUT;
             break;
         case MARKUP_SQUIGGLY:
             name = PdfName.SQUIGGLY;
             break;
     }
     annot.Put(PdfName.SUBTYPE, name);
     annot.Put(PdfName.CONTENTS, new PdfString(contents, PdfObject.TEXT_UNICODE));
     PdfArray array = new PdfArray();
     for (int k = 0; k < quadPoints.Length; ++k)
         array.Add(new PdfNumber(quadPoints[k]));
     annot.Put(PdfName.QUADPOINTS, array);
     return annot;
 }
Ejemplo n.º 57
0
 public void AddAnnotation(PdfAnnotation annot)
 {
     List<PdfAnnotation> allAnnots = new List<PdfAnnotation>();
     if (annot.IsForm()) {
         PdfFormField field = (PdfFormField)annot;
         if (field.Parent != null)
             return;
         ExpandFields(field, allAnnots);
         if (cstp.fieldTemplates == null)
             cstp.fieldTemplates = new Dictionary<PdfTemplate,object>();
     }
     else
         allAnnots.Add(annot);
     for (int k = 0; k < allAnnots.Count; ++k) {
         annot = allAnnots[k];
         if (annot.IsForm()) {
             if (!annot.IsUsed()) {
                 Dictionary<PdfTemplate,object> templates = annot.Templates;
                 if (templates != null) {
                     foreach (PdfTemplate tpl in templates.Keys) {
                         cstp.fieldTemplates[tpl] = null;
                     }
                 }
             }
             PdfFormField field = (PdfFormField)annot;
             if (field.Parent == null)
                 AddDocumentField(field.IndirectReference);
         }
         if (annot.IsAnnotation()) {
             PdfObject pdfobj = PdfReader.GetPdfObject(pageN.Get(PdfName.ANNOTS), pageN);
             PdfArray annots = null;
             if (pdfobj == null || !pdfobj.IsArray()) {
                 annots = new PdfArray();
                 pageN.Put(PdfName.ANNOTS, annots);
             }
             else
                 annots = (PdfArray)pdfobj;
             annots.Add(annot.IndirectReference);
             if (!annot.IsUsed()) {
                 PdfRectangle rect = (PdfRectangle)annot.Get(PdfName.RECT);
                 if (rect != null && (rect.Left != 0 || rect.Right != 0 || rect.Top != 0 || rect.Bottom != 0)) {
                     int rotation = reader.GetPageRotation(pageN);
                     Rectangle pageSize = reader.GetPageSizeWithRotation(pageN);
                     switch (rotation) {
                         case 90:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 pageSize.Top - rect.Bottom,
                                 rect.Left,
                                 pageSize.Top - rect.Top,
                                 rect.Right));
                             break;
                         case 180:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 pageSize.Right - rect.Left,
                                 pageSize.Top - rect.Bottom,
                                 pageSize.Right - rect.Right,
                                 pageSize.Top - rect.Top));
                             break;
                         case 270:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 rect.Bottom,
                                 pageSize.Right - rect.Left,
                                 rect.Top,
                                 pageSize.Right - rect.Right));
                             break;
                     }
                 }
             }
         }
         if (!annot.IsUsed()) {
             annot.SetUsed();
             cstp.AddToBody(annot, annot.IndirectReference);
         }
     }
 }
Ejemplo n.º 58
0
        virtual public void AnnotationCheckTest11() {
            Document document = new Document();
            PdfAWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT + "annotationCheckTest11.pdf", FileMode.Create), PdfAConformanceLevel.PDF_A_2A);
            writer.CreateXmpMetadata();
            writer.SetTagged();
            document.Open();
            document.AddLanguage("en-US");

            Font font = FontFactory.GetFont(RESOURCES + "FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12);
            document.Add(new Paragraph("Hello World", font));

            FileStream iccProfileFileStream = File.Open(RESOURCES + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read, FileShare.Read);
            ICC_Profile icc = ICC_Profile.GetInstance(iccProfileFileStream);
            iccProfileFileStream.Close();

            writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);

            PdfAnnotation annot = new PdfAnnotation(writer, new Rectangle(100, 100, 200, 200));
            annot.Put(PdfName.SUBTYPE, PdfName.STAMP);
            annot.Put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT));
            annot.Put(PdfName.CONTENTS, new PdfString("Hello World"));
            PdfDictionary ap = new PdfDictionary();
            PdfStream s = new PdfStream(Encoding.Default.GetBytes("Hello World"));
            ap.Put(PdfName.N, writer.AddToBody(s).IndirectReference);
            annot.Put(PdfName.AP, ap);
            PdfContentByte canvas = writer.DirectContent;
            canvas.AddAnnotation(annot);
            document.Close();
        }
Ejemplo n.º 59
0
 internal void AddAnnotation(PdfAnnotation annot, PdfDictionary pageN) {
     List<PdfAnnotation> allAnnots = new List<PdfAnnotation>();
     if (annot.IsForm()) {
         fieldsAdded = true;
         GetAcroFields();
         PdfFormField field = (PdfFormField)annot;
         if (field.Parent != null)
             return;
         ExpandFields(field, allAnnots);
     }
     else
         allAnnots.Add(annot);
     for (int k = 0; k < allAnnots.Count; ++k) {
         annot = allAnnots[k];
         if (annot.PlaceInPage > 0)
             pageN = reader.GetPageN(annot.PlaceInPage);
         if (annot.IsForm()) { 
             if (!annot.IsUsed()) {
                 HashSet2<PdfTemplate> templates = annot.GetTemplates();
                 if (templates != null)
                     fieldTemplates.AddAll(templates);
             }
             PdfFormField field = (PdfFormField)annot;
             if (field.Parent == null)
                 AddDocumentField(field.IndirectReference);
         }
         if (annot.IsAnnotation()) {
             PdfObject pdfobj = PdfReader.GetPdfObject(pageN.Get(PdfName.ANNOTS), pageN);
             PdfArray annots = null;
             if (pdfobj == null || !pdfobj.IsArray()) {
                 annots = new PdfArray();
                 pageN.Put(PdfName.ANNOTS, annots);
                 MarkUsed(pageN);
             }
             else 
                annots = (PdfArray)pdfobj;
             annots.Add(annot.IndirectReference);
             MarkUsed(annots);
             if (!annot.IsUsed()) {
                 PdfRectangle rect = (PdfRectangle)annot.Get(PdfName.RECT);
                 if (rect != null && (rect.Left != 0 || rect.Right != 0 || rect.Top != 0 || rect.Bottom != 0)) {
                     int rotation = reader.GetPageRotation(pageN);
                     Rectangle pageSize = reader.GetPageSizeWithRotation(pageN);
                     switch (rotation) {
                         case 90:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 pageSize.Top - rect.Top,
                                 rect.Right,
                                 pageSize.Top - rect.Bottom,
                                 rect.Left));
                             break;
                         case 180:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 pageSize.Right - rect.Left,
                                 pageSize.Top - rect.Bottom,
                                 pageSize.Right - rect.Right,
                                 pageSize.Top - rect.Top));
                             break;
                         case 270:
                             annot.Put(PdfName.RECT, new PdfRectangle(
                                 rect.Bottom,
                                 pageSize.Right - rect.Left,
                                 rect.Top,
                                 pageSize.Right - rect.Right));
                             break;
                     }
                 }
             }
         }
         if (!annot.IsUsed()) {
             annot.SetUsed();
             AddToBody(annot, annot.IndirectReference);
         }
     }
 }
Ejemplo n.º 60
0
 internal virtual void AddAnnotation(PdfAnnotation annot) {
     bool needToTag = IsTagged() && annot.Role != null && (!(annot is PdfFormField) || ((PdfFormField) annot).Kids == null);
     if (needToTag) {
         OpenMCBlock(annot);
     }
     writer.AddAnnotation(annot);
     if (needToTag) {
         PdfStructureElement strucElem = null;
         pdf.structElements.TryGetValue(annot.ID, out strucElem);
         if (strucElem != null) {
             int structParent = pdf.GetStructParentIndex(annot);
             annot.Put(PdfName.STRUCTPARENT, new PdfNumber(structParent));
             strucElem.SetAnnotation(annot, CurrentPage);
             writer.StructureTreeRoot.SetAnnotationMark(structParent, strucElem.Reference);
         }
         CloseMCBlock(annot);
     }
 }