Inheritance: PdfDictionary
Ejemplo n.º 1
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.º 2
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);
        }
 /**
  * @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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
0
        public static PdfAnnotation ShallowDuplicate(PdfAnnotation annot)
        {
            PdfAnnotation dup;

            if (annot.IsForm())
            {
                dup = new PdfFormField(annot.writer);
                PdfFormField dupField = (PdfFormField)dup;
                PdfFormField srcField = (PdfFormField)annot;
                dupField.parent = srcField.parent;
                dupField.kids   = srcField.kids;
            }
            else
            {
                dup = annot.writer.CreateAnnotation(null, (PdfName)annot.Get(PdfName.SUBTYPE));
            }
            dup.Merge(annot);
            dup.form       = annot.form;
            dup.annotation = annot.annotation;
            dup.templates  = annot.templates;
            return(dup);
        }
Ejemplo n.º 9
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.º 10
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.º 11
0
        public static PdfAnnotation ShallowDuplicate(PdfAnnotation annot)
        {
            PdfAnnotation dup;

            if (annot.IsForm())
            {
                dup = new PdfFormField(annot.Writer);
                PdfFormField dupField = (PdfFormField)dup;
                PdfFormField srcField = (PdfFormField)annot;
                dupField.parent = srcField.parent;
                dupField.kids   = srcField.kids;
            }
            else
            {
                dup = new PdfAnnotation(annot.Writer, null);
            }
            dup.Merge(annot);
            dup.Form       = annot.Form;
            dup.Annotation = annot.Annotation;
            dup.templates  = annot.templates;
            return(dup);
        }
Ejemplo n.º 12
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.º 13
0
        internal virtual void SetAnnotation(PdfAnnotation annot, PdfIndirectReference currentPage)
        {
            PdfArray kArray = GetAsArray(PdfName.K);

            if (kArray == null)
            {
                kArray = new PdfArray();
                PdfObject k = Get(PdfName.K);
                if (k != null)
                {
                    kArray.Add(k);
                }
                Put(PdfName.K, kArray);
            }
            PdfDictionary dict = new PdfDictionary();

            dict.Put(PdfName.TYPE, PdfName.OBJR);
            dict.Put(PdfName.OBJ, annot.IndirectReference);
            if (annot.Role == PdfName.FORM)
            {
                dict.Put(PdfName.PG, currentPage);
            }
            kArray.Add(dict);
        }
Ejemplo n.º 14
0
 /** Adds a <CODE>PdfAnnotation</CODE> or a <CODE>PdfFormField</CODE>
 * to the document. Only the top parent of a <CODE>PdfFormField</CODE>
 * needs to be added.
 * @param annot the <CODE>PdfAnnotation</CODE> or the <CODE>PdfFormField</CODE> to add
 */
 public virtual void AddAnnotation(PdfAnnotation annot) {
     pdf.AddAnnotation(annot);
 }
Ejemplo n.º 15
0
 virtual public void AddAnnotation(PdfAnnotation annot) {
     if (annot.IsForm()) {
         PdfFormField field = (PdfFormField)annot;
         if (field.Parent == null)
             AddFormFieldRaw(field);
     }
     else
         annotations.Add(annot);
 }
Ejemplo n.º 16
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.º 17
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);
     }
 }
Ejemplo n.º 18
0
 internal virtual void AddAnnotation(PdfAnnotation annot)
 {
     writer.AddAnnotation(annot);
 }
Ejemplo n.º 19
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();
        }
 internal void AddAnnotation(PdfAnnotation annot, bool applyCTM)
 {
     if (applyCTM && !state.CTM.IsIdentity()) {
         annot.ApplyCTM(state.CTM);
     }
     AddAnnotation(annot);
 }
Ejemplo n.º 21
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.º 22
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.º 23
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.º 24
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.º 25
0
 internal override void AddAnnotation(PdfAnnotation annot)
 {
     ((PdfStamperImp)writer).AddAnnotation(annot, ps.pageN);
 }
Ejemplo n.º 26
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.º 28
0
 public override void AddAnnotation(PdfAnnotation annot)
 {
 }
Ejemplo n.º 29
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.º 30
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.º 31
0
 /// <summary>
 /// Sets a generic annotation to this Chunk.
 /// </summary>
 /// <param name="annotation">the annotation</param>
 /// <returns>this Chunk</returns>
 public Chunk SetAnnotation(PdfAnnotation annotation) {
     return SetAttribute(PDFANNOTATION, annotation);
 }
Ejemplo n.º 32
0
 internal override void AddAnnotation(PdfAnnotation annot)
 {
     ((PdfStamperImp)writer).AddAnnotation(annot, ps.pageN);
 }
Ejemplo n.º 33
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.º 34
0
 /**
 * Adds an annotation of form field in a specific page. This page number
 * can be overridden with {@link PdfAnnotation#setPlaceInPage(int)}.
 * @param annot the annotation
 * @param page the page
 */    
 virtual public void AddAnnotation(PdfAnnotation annot, int page) {
     stamper.AddAnnotation(annot, page);
 }
Ejemplo n.º 35
0
 /**
  * Adds an annotation of form field in a specific page. This page number
  * can be overridden with {@link PdfAnnotation#setPlaceInPage(int)}.
  * @param annot the annotation
  * @param page the page
  */
 public void AddAnnotation(PdfAnnotation annot, int page)
 {
     stamper.AddAnnotation(annot, page);
 }
Ejemplo n.º 36
0
 public static PdfAction CreateHide(PdfAnnotation annot, bool hide) {
     return CreateHide(annot.IndirectReference, hide);
 }
Ejemplo n.º 37
0
 public static PdfAction CreateHide(PdfAnnotation annot, bool hide)
 {
     return(CreateHide(annot.IndirectReference, hide));
 }
 internal void AddAnnotation(PdfAnnotation annot) {
     pageEmpty = false;
     annotationsImp.AddAnnotation(annot);
 }
Ejemplo n.º 39
0
 /**
 * @see com.lowagie.text.pdf.PdfWriter#addAnnotation(com.lowagie.text.pdf.PdfAnnotation)
 */
 public override void AddAnnotation(PdfAnnotation annot)
 {
     throw new Exception("Unsupported in this context. Use PdfStamper.AddAnnotation()");
 }
Ejemplo n.º 40
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);
         }
     }
 }
        /**
        * Writes a text line to the document. It takes care of all the attributes.
        * <P>
        * Before entering the line position must have been established and the
        * <CODE>text</CODE> argument must be in text object scope (<CODE>beginText()</CODE>).
        * @param line the line to be written
        * @param text the <CODE>PdfContentByte</CODE> where the text will be written to
        * @param graphics the <CODE>PdfContentByte</CODE> where the graphics will be written to
        * @param currentValues the current font and extra spacing values
        * @param ratio
        * @throws DocumentException on error
        */
        internal float WriteLineToContent(PdfLine line, PdfContentByte text, PdfContentByte graphics, Object[] currentValues, float ratio)  {
            PdfFont currentFont = (PdfFont)(currentValues[0]);
            float lastBaseFactor = (float)currentValues[1];
            //PdfChunk chunkz;
            int numberOfSpaces;
            int lineLen;
            bool isJustified;
            float hangingCorrection = 0;
            float hScale = 1;
            float lastHScale = float.NaN;
            float baseWordSpacing = 0;
            float baseCharacterSpacing = 0;
            float glueWidth = 0;
            float lastX = text.XTLM + line.OriginalWidth;
            
            numberOfSpaces = line.NumberOfSpaces;
            lineLen = line.GetLineLengthUtf32();
            // does the line need to be justified?
            isJustified = line.HasToBeJustified() && (numberOfSpaces != 0 || lineLen > 1);
            int separatorCount = line.GetSeparatorCount();
            if (separatorCount > 0) {
                glueWidth = line.WidthLeft / separatorCount;
            }
            else if (isJustified && separatorCount == 0) {
                if (line.NewlineSplit && line.WidthLeft >= (lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1))) {
                    if (line.RTL) {
                        text.MoveText(line.WidthLeft - lastBaseFactor * (ratio * numberOfSpaces + lineLen - 1), 0);
                    }
                    baseWordSpacing = ratio * lastBaseFactor;
                    baseCharacterSpacing = lastBaseFactor;
                }
                else {
                    float width = line.WidthLeft;
                    PdfChunk last = line.GetChunk(line.Size - 1);
                    if (last != null) {
                        String s = last.ToString();
                        char c;
                        if (s.Length > 0 && hangingPunctuation.IndexOf((c = s[s.Length - 1])) >= 0) {
                            float oldWidth = width;
                            width += last.Font.Width(c) * 0.4f;
                            hangingCorrection = width - oldWidth;
                        }
                    }
                    float baseFactor = width / (ratio * numberOfSpaces + lineLen - 1);
                    baseWordSpacing = ratio * baseFactor;
                    baseCharacterSpacing = baseFactor;
                    lastBaseFactor = baseFactor;
                }
            }
            else if (line.alignment == Element.ALIGN_LEFT || line.alignment == Element.ALIGN_UNDEFINED) {
                lastX -= line.WidthLeft;
            }
            
            int lastChunkStroke = line.LastStrokeChunk;
            int chunkStrokeIdx = 0;
            float xMarker = text.XTLM;
            float baseXMarker = xMarker;
            float yMarker = text.YTLM;
            bool adjustMatrix = false;
            float tabPosition = 0;
            
            // looping over all the chunks in 1 line
            foreach (PdfChunk chunk in line) {
                if (IsTagged(writer) && chunk.accessibleElement != null) {
                    text.OpenMCBlock(chunk.accessibleElement);
                }
                BaseColor color = chunk.Color;
                float fontSize = chunk.Font.Size;
                float ascender;
                float descender;
                if (chunk.IsImage())
                {
                    ascender = chunk.Height();
                    descender = 0;
                }
                else
                {
                    ascender = chunk.Font.Font.GetFontDescriptor(BaseFont.ASCENT, fontSize);
                    descender = chunk.Font.Font.GetFontDescriptor(BaseFont.DESCENT, fontSize);
                }
                hScale = 1;
                
                if (chunkStrokeIdx <= lastChunkStroke) {
                    float width;
                    if (isJustified) {
                        width = chunk.GetWidthCorrected(baseCharacterSpacing, baseWordSpacing);
                    }
                    else {
                        width = chunk.Width();
                    }
                    if (chunk.IsStroked()) {
                        PdfChunk nextChunk = line.GetChunk(chunkStrokeIdx + 1);
                        if (chunk.IsSeparator()) {
                            width = glueWidth;
                            Object[] sep = (Object[])chunk.GetAttribute(Chunk.SEPARATOR);
                            IDrawInterface di = (IDrawInterface)sep[0];
                            bool vertical = (bool)sep[1];
                            if (vertical) {
                                di.Draw(graphics, baseXMarker, yMarker + descender, baseXMarker + line.OriginalWidth, ascender - descender, yMarker);      
                            }
                            else {
                                di.Draw(graphics, xMarker, yMarker + descender, xMarker + width, ascender - descender, yMarker);
                            }
                        }
                        if (chunk.IsTab()) {
                            if (chunk.IsAttribute(Chunk.TABSETTINGS))
                            {
                                TabStop tabStop = chunk.TabStop;
                                if (tabStop != null) {
                                    tabPosition = tabStop.Position + baseXMarker;
                                    if (tabStop.Leader != null)
                                        tabStop.Leader.Draw(graphics, xMarker, yMarker + descender, tabPosition, ascender - descender, yMarker);
                                }
                                else {
                                    tabPosition = xMarker;
                                }
                            } else {
                                //Keep deprecated tab logic for backward compatibility...
                                Object[] tab = (Object[])chunk.GetAttribute(Chunk.TAB);
                                IDrawInterface di = (IDrawInterface)tab[0];
                                tabPosition = (float)tab[1] + (float)tab[3];
                                if (tabPosition > xMarker)
                                    di.Draw(graphics, xMarker, yMarker + descender, tabPosition, ascender - descender, yMarker);
                            }
                            float tmp = xMarker;
                            xMarker = tabPosition;
                            tabPosition = tmp;
                        }
                        if (chunk.IsAttribute(Chunk.BACKGROUND)) {
                            bool inText = graphics.InText;
                            if (inText && IsTagged(writer)) {
                                graphics.EndText();
                            }
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.BACKGROUND))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[] bgr = (Object[])chunk.GetAttribute(Chunk.BACKGROUND);
                            graphics.SetColorFill((BaseColor)bgr[0]);
                            float[] extra = (float[])bgr[1];
                            graphics.Rectangle(xMarker - extra[0],
                                yMarker + descender - extra[1] + chunk.TextRise,
                                width - subtract + extra[0] + extra[2],
                                ascender - descender + extra[1] + extra[3]);
                            graphics.Fill();
                            graphics.SetGrayFill(0);
                            if (inText && IsTagged(writer)) {
                                graphics.BeginText(true);
                            }
                        }
                        if (chunk.IsAttribute(Chunk.UNDERLINE) && !chunk.IsNewlineSplit()) {
                            bool inText = graphics.InText;
                            if (inText && IsTagged(writer)) {
                                graphics.EndText();
                            }
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.UNDERLINE))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[][] unders = (Object[][])chunk.GetAttribute(Chunk.UNDERLINE);
                            BaseColor scolor = null;
                            for (int k = 0; k < unders.Length; ++k) {
                                Object[] obj = unders[k];
                                scolor = (BaseColor)obj[0];
                                float[] ps = (float[])obj[1];
                                if (scolor == null)
                                    scolor = color;
                                if (scolor != null)
                                    graphics.SetColorStroke(scolor);
                                graphics.SetLineWidth(ps[0] + fontSize * ps[1]);
                                float shift = ps[2] + fontSize * ps[3];
                                int cap2 = (int)ps[4];
                                if (cap2 != 0)
                                    graphics.SetLineCap(cap2);
                                graphics.MoveTo(xMarker, yMarker + shift);
                                graphics.LineTo(xMarker + width - subtract, yMarker + shift);
                                graphics.Stroke();
                                if (scolor != null)
                                    graphics.ResetGrayStroke();
                                if (cap2 != 0)
                                    graphics.SetLineCap(0);
                            }
                            graphics.SetLineWidth(1);
                            if (inText && IsTagged(writer)) {
                                graphics.BeginText(true);
                            }
                        }
                        if (chunk.IsAttribute(Chunk.ACTION))
                        {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.ACTION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            PdfAnnotation annot = null;
                            if (chunk.IsImage()) {
                                annot = new PdfAnnotation(writer, xMarker, yMarker + chunk.ImageOffsetY, xMarker + width - subtract, yMarker + chunk.ImageHeight + chunk.ImageOffsetY, (PdfAction)chunk.GetAttribute(Chunk.ACTION));
                            }
                            else {
                        	    annot = new PdfAnnotation(writer, xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise, (PdfAction)chunk.GetAttribute(Chunk.ACTION));
                            }
                            text.AddAnnotation(annot, true);
                            if (IsTagged(writer) && chunk.accessibleElement != null) {
                                int structParent = GetStructParentIndex(annot);
                                annot.Put(PdfName.STRUCTPARENT, new PdfNumber(structParent));
                                PdfStructureElement strucElem;
                                structElements.TryGetValue(chunk.accessibleElement.ID, out strucElem);
                                if (strucElem != null) {
                                    PdfArray kArray = strucElem.GetAsArray(PdfName.K);
                                    if (kArray == null) {
                                        kArray = new PdfArray();
                                        PdfObject k = strucElem.Get(PdfName.K);
                                        if (k != null) {
                                            kArray.Add(k);
                                        }
                                        strucElem.Put(PdfName.K, kArray);
                                    }
                                    PdfDictionary dict = new PdfDictionary();
                                    dict.Put(PdfName.TYPE, PdfName.OBJR);
                                    dict.Put(PdfName.OBJ, annot.IndirectReference);
                                    kArray.Add(dict);
                                    writer.StructureTreeRoot.SetAnnotationMark(structParent, strucElem.Reference);
                                }
                            }
                        }
                        if (chunk.IsAttribute(Chunk.REMOTEGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.REMOTEGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Object[] obj = (Object[])chunk.GetAttribute(Chunk.REMOTEGOTO);
                            String filename = (String)obj[0];
                            if (obj[1] is String)
                                RemoteGoto(filename, (String)obj[1], xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise);
                            else
                                RemoteGoto(filename, (int)obj[1], xMarker, yMarker + descender + chunk.TextRise, xMarker + width - subtract, yMarker + ascender + chunk.TextRise);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALGOTO)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALGOTO))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            LocalGoto((String)chunk.GetAttribute(Chunk.LOCALGOTO), xMarker, yMarker, xMarker + width - subtract, yMarker + fontSize);
                        }
                        if (chunk.IsAttribute(Chunk.LOCALDESTINATION)) {
                            /*float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.LOCALDESTINATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;*/
                            LocalDestination((String)chunk.GetAttribute(Chunk.LOCALDESTINATION), new PdfDestination(PdfDestination.XYZ, xMarker, yMarker + fontSize, 0));
                        }
                        if (chunk.IsAttribute(Chunk.GENERICTAG)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.GENERICTAG))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            Rectangle rect = new Rectangle(xMarker, yMarker, xMarker + width - subtract, yMarker + fontSize);
                            IPdfPageEvent pev = writer.PageEvent;
                            if (pev != null)
                                pev.OnGenericTag(writer, this, rect, (String)chunk.GetAttribute(Chunk.GENERICTAG));
                        }
                        if (chunk.IsAttribute(Chunk.PDFANNOTATION)) {
                            float subtract = lastBaseFactor;
                            if (nextChunk != null && nextChunk.IsAttribute(Chunk.PDFANNOTATION))
                                subtract = 0;
                            if (nextChunk == null)
                                subtract += hangingCorrection;
                            PdfAnnotation annot = PdfFormField.ShallowDuplicate((PdfAnnotation)chunk.GetAttribute(Chunk.PDFANNOTATION));
                            annot.Put(PdfName.RECT, new PdfRectangle(xMarker, yMarker + descender, xMarker + width - subtract, yMarker + ascender));
                            text.AddAnnotation(annot, true);
                        }
                        float[] paramsx = (float[])chunk.GetAttribute(Chunk.SKEW);
                        object hs = chunk.GetAttribute(Chunk.HSCALE);
                        if (paramsx != null || hs != null) {
                            float b = 0, c = 0;
                            if (paramsx != null) {
                                b = paramsx[0];
                                c = paramsx[1];
                            }
                            if (hs != null)
                                hScale = (float)hs;
                            text.SetTextMatrix(hScale, b, c, 1, xMarker, yMarker);
                        }
                        if (!isJustified)
                        {
                            if (chunk.IsAttribute(Chunk.WORD_SPACING))
                            {
                                float ws = (float)chunk.GetAttribute(Chunk.WORD_SPACING);
                                text.SetWordSpacing(ws);
                            }
                        }

                        if (chunk.IsAttribute(Chunk.CHAR_SPACING)) {
                    	    float cs = (float) chunk.GetAttribute(Chunk.CHAR_SPACING);
						    text.SetCharacterSpacing(cs);
					    }
                        if (chunk.IsImage()) {
                            Image image = chunk.Image;
                            width = chunk.ImageWidth;
                            float[] matrix = image.GetMatrix(chunk.ImageScalePercentage);
                            matrix[Image.CX] = xMarker + chunk.ImageOffsetX - matrix[Image.CX];
                            matrix[Image.CY] = yMarker + chunk.ImageOffsetY - matrix[Image.CY];
                            graphics.AddImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
                            text.MoveText(xMarker + lastBaseFactor + chunk.ImageWidth - text.XTLM, 0);
                        }
                    }

                    xMarker += width;
                    ++chunkStrokeIdx;
                }

                if (!chunk.IsImage() && chunk.Font.CompareTo(currentFont) != 0) {
                    currentFont = chunk.Font;
                    text.SetFontAndSize(currentFont.Font, currentFont.Size);
                }
                float rise = 0;
                Object[] textRender = (Object[])chunk.GetAttribute(Chunk.TEXTRENDERMODE);
                int tr = 0;
                float strokeWidth = 1;
                BaseColor strokeColor = null;
                object fr = chunk.GetAttribute(Chunk.SUBSUPSCRIPT);
                if (textRender != null) {
                    tr = (int)textRender[0] & 3;
                    if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                        text.SetTextRenderingMode(tr);
                    if (tr == PdfContentByte.TEXT_RENDER_MODE_STROKE || tr == PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE) {
                        strokeWidth = (float)textRender[1];
                        if (strokeWidth != 1)
                            text.SetLineWidth(strokeWidth);
                        strokeColor = (BaseColor)textRender[2];
                        if (strokeColor == null)
                            strokeColor = color;
                        if (strokeColor != null)
                            text.SetColorStroke(strokeColor);
                    }
                }
                if (fr != null)
                    rise = (float)fr;
                if (color != null)
                    text.SetColorFill(color);
                if (rise != 0)
                    text.SetTextRise(rise);
                if (chunk.IsImage()) {
                    adjustMatrix = true;
                }
                else if (chunk.IsHorizontalSeparator()) {
                    PdfTextArray array = new PdfTextArray();
                    array.Add(-glueWidth * 1000f / chunk.Font.Size / hScale);
                    text.ShowText(array);
                }
                else if (chunk.IsTab() && tabPosition != xMarker)
                {
                    PdfTextArray array = new PdfTextArray();
                    array.Add((tabPosition - xMarker) * 1000f / chunk.Font.Size / hScale);
                    text.ShowText(array);
                }
                
                // If it is a CJK chunk or Unicode TTF we will have to simulate the
                // space adjustment.
                else if (isJustified && numberOfSpaces > 0 && chunk.IsSpecialEncoding()) {
                    if (hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale + text.CharacterSpacing);
                    }
                    String s = chunk.ToString();
                    int idx = s.IndexOf(' ');
                    if (idx < 0)
                        text.ShowText(s);
                    else {
                        float spaceCorrection = - baseWordSpacing * 1000f / chunk.Font.Size / hScale;
                        PdfTextArray textArray = new PdfTextArray(s.Substring(0, idx));
                        int lastIdx = idx;
                        while ((idx = s.IndexOf(' ', lastIdx + 1)) >= 0) {
                            textArray.Add(spaceCorrection);
                            textArray.Add(s.Substring(lastIdx, idx - lastIdx));
                            lastIdx = idx;
                        }
                        textArray.Add(spaceCorrection);
                        textArray.Add(s.Substring(lastIdx));
                        text.ShowText(textArray);
                    }
                }
                else {
                    if (isJustified && hScale != lastHScale) {
                        lastHScale = hScale;
                        text.SetWordSpacing(baseWordSpacing / hScale);
                        text.SetCharacterSpacing(baseCharacterSpacing / hScale + text.CharacterSpacing);
                    }
                    text.ShowText(chunk.ToString());
                }
                
                if (rise != 0)
                    text.SetTextRise(0);
                if (color != null)
                    text.ResetRGBColorFill();
                if (tr != PdfContentByte.TEXT_RENDER_MODE_FILL)
                    text.SetTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL);
                if (strokeColor != null)
                    text.ResetRGBColorStroke();
                if (strokeWidth != 1)
                    text.SetLineWidth(1);            
                if (chunk.IsAttribute(Chunk.SKEW) || chunk.IsAttribute(Chunk.HSCALE)) {
                    adjustMatrix = true;
                    text.SetTextMatrix(xMarker, yMarker);
                }
                if (chunk.IsAttribute(Chunk.CHAR_SPACING)) {
				    text.SetCharacterSpacing(baseCharacterSpacing);
                }
                if (chunk.IsAttribute(Chunk.WORD_SPACING)) {
                    text.SetWordSpacing(baseWordSpacing);
                }
                if (IsTagged(writer) && chunk.accessibleElement != null) {
                    text.CloseMCBlock(chunk.accessibleElement);
                }
            }
            if (isJustified) {
                text.SetWordSpacing(0);
                text.SetCharacterSpacing(0);
                if (line.NewlineSplit)
                    lastBaseFactor = 0;
            }
            if (adjustMatrix)
                text.MoveText(baseXMarker - text.XTLM, 0);
            currentValues[0] = currentFont;
            currentValues[1] = lastBaseFactor;
            return lastX;
        }
Ejemplo n.º 42
0
 virtual public void AddPlainAnnotation(PdfAnnotation annot) {
     annotations.Add(annot);
 }
Ejemplo n.º 43
0
 /**
 * @see com.lowagie.text.pdf.PdfWriter#addAnnotation(com.lowagie.text.pdf.PdfAnnotation)
 */
 public override void AddAnnotation(PdfAnnotation annot) {
     throw new Exception(MessageLocalization.GetComposedMessage("unsupported.in.this.context.use.pdfstamper.addannotation"));
 }
Ejemplo n.º 44
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.º 45
0
 internal override void AddAnnotation(PdfAnnotation annot, int page) {
     annot.Page = page;
     AddAnnotation(annot, reader.GetPageN(page));
 }
 public override void AddAnnotation(PdfAnnotation annot)
 {
 }
Ejemplo n.º 47
0
 internal virtual void AddAnnotation(PdfAnnotation annot, int page) {
     AddAnnotation(annot);
 }
Ejemplo n.º 48
0
 public void AddAnnotation(PdfAnnotation annot, int page);