Example #1
0
        private static void AddBorderStyleAlt(BorderStyleAltObject borderStyleAltObject, XmlElement annot, XmlDocument
                                              document)
        {
            //BorderStyle alt contains Border style encoded in the format specified in the border style attributes as content
            //has attributes
            XmlElement borderStyleAlt = document.CreateElement(XfdfConstants.BORDER_STYLE_ALT);

            //required attributes
            borderStyleAlt.SetAttribute(XfdfConstants.H_CORNER_RADIUS, XfdfObjectUtils.ConvertFloatToString(borderStyleAltObject
                                                                                                            .GetHCornerRadius()));
            borderStyleAlt.SetAttribute(XfdfConstants.V_CORNER_RADIUS, XfdfObjectUtils.ConvertFloatToString(borderStyleAltObject
                                                                                                            .GetVCornerRadius()));
            borderStyleAlt.SetAttribute(XfdfConstants.WIDTH_CAPITAL, XfdfObjectUtils.ConvertFloatToString(borderStyleAltObject
                                                                                                          .GetWidth()));
            //optional attribute
            if (borderStyleAltObject.GetDashPattern() != null)
            {
                //TODO add real conversion from PdfArray (PdfName.D in Border dictionary) to String
                borderStyleAlt.SetAttribute(XfdfConstants.DASH_PATTERN, JavaUtil.ArraysToString(borderStyleAltObject.GetDashPattern
                                                                                                    ()));
            }
            if (borderStyleAltObject.GetContent() != null)
            {
                borderStyleAlt.InnerText = borderStyleAltObject.GetContent();
            }
            annot.AppendChild(borderStyleAlt);
        }
Example #2
0
        private static void AddFitV(FitObject fitVObject, XmlElement dest, XmlDocument document)
        {
            XmlElement fitV = document.CreateElement(XfdfConstants.FIT_V);

            //all required
            fitV.SetAttribute(XfdfConstants.PAGE_CAPITAL, fitVObject.GetPage().ToString());
            fitV.SetAttribute(XfdfConstants.LEFT, XfdfObjectUtils.ConvertFloatToString(fitVObject.GetLeft()));
            dest.AppendChild(fitV);
        }
Example #3
0
 private void AddCommonAnnotationAttributes(PdfAnnotation annotation, AnnotObject annotObject)
 {
     annotation.SetFlags(XfdfObjectUtils.ConvertFlagsFromString(annotObject.GetAttributeValue(XfdfConstants.FLAGS
                                                                                              )));
     annotation.SetColor(XfdfObjectUtils.ConvertColorFloatsFromString(annotObject.GetAttributeValue(XfdfConstants
                                                                                                    .COLOR)));
     annotation.SetDate(new PdfString(annotObject.GetAttributeValue(XfdfConstants.DATE)));
     annotation.SetName(new PdfString(annotObject.GetAttributeValue(XfdfConstants.NAME)));
     annotation.SetTitle(new PdfString(annotObject.GetAttributeValue(XfdfConstants.TITLE)));
 }
Example #4
0
        private static void AddFitR(FitObject fitRObject, XmlElement dest, XmlDocument document)
        {
            XmlElement fitR = document.CreateElement(XfdfConstants.FIT_R);

            //all required
            fitR.SetAttribute(XfdfConstants.PAGE_CAPITAL, fitRObject.GetPage().ToString());
            fitR.SetAttribute(XfdfConstants.LEFT, XfdfObjectUtils.ConvertFloatToString(fitRObject.GetLeft()));
            fitR.SetAttribute(XfdfConstants.BOTTOM, XfdfObjectUtils.ConvertFloatToString(fitRObject.GetBottom()));
            fitR.SetAttribute(XfdfConstants.RIGHT, XfdfObjectUtils.ConvertFloatToString(fitRObject.GetRight()));
            fitR.SetAttribute(XfdfConstants.TOP, XfdfObjectUtils.ConvertFloatToString(fitRObject.GetTop()));
            dest.AppendChild(fitR);
        }
Example #5
0
        private static void AddXYZ(FitObject xyzObject, XmlElement dest, XmlDocument document)
        {
            XmlElement xyz = document.CreateElement(XfdfConstants.XYZ_CAPITAL);

            //all required
            xyz.SetAttribute(XfdfConstants.PAGE_CAPITAL, xyzObject.GetPage().ToString());
            xyz.SetAttribute(XfdfConstants.LEFT, XfdfObjectUtils.ConvertFloatToString(xyzObject.GetLeft()));
            xyz.SetAttribute(XfdfConstants.BOTTOM, XfdfObjectUtils.ConvertFloatToString(xyzObject.GetBottom()));
            xyz.SetAttribute(XfdfConstants.RIGHT, XfdfObjectUtils.ConvertFloatToString(xyzObject.GetRight()));
            xyz.SetAttribute(XfdfConstants.TOP, XfdfObjectUtils.ConvertFloatToString(xyzObject.GetTop()));
            dest.AppendChild(xyz);
        }
Example #6
0
        internal virtual void AddAttribute(String name, Rectangle value)
        {
            String stringValue = XfdfObjectUtils.ConvertRectToString(value);

            attributes.Add(new AttributeObject(name, stringValue));
        }
Example #7
0
        private void AddAnnotationToPdf(AnnotObject annotObject, PdfDocument pdfDocument)
        {
            String annotName = annotObject.GetName();

            if (annotName != null)
            {
                switch (annotName)
                {
                case XfdfConstants.TEXT: {
                    //TODO add all attributes properly one by one
                    PdfTextAnnotation pdfTextAnnotation = new PdfTextAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject
                                                                                                                      .GetAttributeValue(XfdfConstants.RECT)));
                    AddCommonAnnotationAttributes(pdfTextAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(pdfTextAnnotation, annotObject);
                    pdfTextAnnotation.SetIconName(new PdfName(annotObject.GetAttributeValue(XfdfConstants.ICON)));
                    if (annotObject.GetAttributeValue(XfdfConstants.STATE) != null)
                    {
                        pdfTextAnnotation.SetState(new PdfString(annotObject.GetAttributeValue(XfdfConstants.STATE)));
                    }
                    if (annotObject.GetAttributeValue(XfdfConstants.STATE_MODEL) != null)
                    {
                        pdfTextAnnotation.SetStateModel(new PdfString(annotObject.GetAttributeValue(XfdfConstants.STATE_MODEL)));
                    }
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttributeValue(XfdfConstants.PAGE))).AddAnnotation(pdfTextAnnotation
                                                                                                                          );
                    break;
                }

                case XfdfConstants.HIGHLIGHT: {
                    PdfTextMarkupAnnotation pdfHighLightAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString
                                                                                                     (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Highlight, XfdfObjectUtils.ConvertQuadPointsFromCoordsString
                                                                                                     (annotObject.GetAttributeValue(XfdfConstants.COORDS)));
                    AddCommonAnnotationAttributes(pdfHighLightAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(pdfHighLightAnnotation, annotObject);
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (pdfHighLightAnnotation);
                    break;
                }

                case XfdfConstants.UNDERLINE: {
                    PdfTextMarkupAnnotation pdfUnderlineAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString
                                                                                                     (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Underline, XfdfObjectUtils.ConvertQuadPointsFromCoordsString
                                                                                                     (annotObject.GetAttributeValue(XfdfConstants.COORDS)));
                    AddCommonAnnotationAttributes(pdfUnderlineAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(pdfUnderlineAnnotation, annotObject);
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (pdfUnderlineAnnotation);
                    break;
                }

                case XfdfConstants.STRIKEOUT: {
                    PdfTextMarkupAnnotation pdfStrikeoutAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString
                                                                                                     (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.StrikeOut, XfdfObjectUtils.ConvertQuadPointsFromCoordsString
                                                                                                     (annotObject.GetAttributeValue(XfdfConstants.COORDS)));
                    AddCommonAnnotationAttributes(pdfStrikeoutAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(pdfStrikeoutAnnotation, annotObject);
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (pdfStrikeoutAnnotation);
                    break;
                }

                case XfdfConstants.SQUIGGLY: {
                    PdfTextMarkupAnnotation pdfSquigglyAnnotation = new PdfTextMarkupAnnotation(XfdfObjectUtils.ConvertRectFromString
                                                                                                    (annotObject.GetAttributeValue(XfdfConstants.RECT)), PdfName.Squiggly, XfdfObjectUtils.ConvertQuadPointsFromCoordsString
                                                                                                    (annotObject.GetAttributeValue(XfdfConstants.COORDS)));
                    AddCommonAnnotationAttributes(pdfSquigglyAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(pdfSquigglyAnnotation, annotObject);
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (pdfSquigglyAnnotation);
                    break;
                }

                case XfdfConstants.CIRCLE: {
                    //                case XfdfConstants.LINE:
                    //                    pdfDocument.getPage(Integer.parseInt(annotObject.getAttribute(XfdfConstants.PAGE).getValue()))
                    //                            .addAnnotation(new PdfLineAnnotation(XfdfObjectUtils.convertRectFromString(annotObject.getAttributeValue(XfdfConstants.RECT)), XfdfObjectUtils.convertVerticesFromString(annotObject.getVertices())));
                    //                    break;
                    PdfCircleAnnotation pdfCircleAnnotation = new PdfCircleAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject
                                                                                                                            .GetAttributeValue(XfdfConstants.RECT)));
                    AddCommonAnnotationAttributes(pdfCircleAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(pdfCircleAnnotation, annotObject);
                    if (annotObject.GetAttributeValue(XfdfConstants.FRINGE) != null)
                    {
                        pdfCircleAnnotation.SetRectangleDifferences(XfdfObjectUtils.ConvertFringeFromString(annotObject.GetAttributeValue
                                                                                                                (XfdfConstants.FRINGE)));
                    }
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (pdfCircleAnnotation);
                    break;
                }

                case XfdfConstants.SQUARE: {
                    PdfSquareAnnotation pdfSquareAnnotation = new PdfSquareAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject
                                                                                                                            .GetAttributeValue(XfdfConstants.RECT)));
                    AddCommonAnnotationAttributes(pdfSquareAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(pdfSquareAnnotation, annotObject);
                    if (annotObject.GetAttributeValue(XfdfConstants.FRINGE) != null)
                    {
                        pdfSquareAnnotation.SetRectangleDifferences(XfdfObjectUtils.ConvertFringeFromString(annotObject.GetAttributeValue
                                                                                                                (XfdfConstants.FRINGE)));
                    }
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (pdfSquareAnnotation);
                    break;
                }

                case XfdfConstants.POLYGON: {
                    //XfdfConstants.CARET
                    Rectangle             rect              = XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants.RECT));
                    float[]               vertices          = XfdfObjectUtils.ConvertVerticesFromString(annotObject.GetVertices());
                    PdfPolyGeomAnnotation polygonAnnotation = PdfPolyGeomAnnotation.CreatePolygon(rect, vertices);
                    AddCommonAnnotationAttributes(polygonAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(polygonAnnotation, annotObject);
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (polygonAnnotation);
                    break;
                }

                case XfdfConstants.POLYLINE: {
                    Rectangle polylineRect = XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants
                                                                                                                 .RECT));
                    float[] polylineVertices = XfdfObjectUtils.ConvertVerticesFromString(annotObject.GetVertices());
                    PdfPolyGeomAnnotation polylineAnnotation = PdfPolyGeomAnnotation.CreatePolyLine(polylineRect, polylineVertices
                                                                                                    );
                    AddCommonAnnotationAttributes(polylineAnnotation, annotObject);
                    AddMarkupAnnotationAttributes(polylineAnnotation, annotObject);
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (polylineAnnotation);
                    break;
                }

                case XfdfConstants.STAMP: {
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (new PdfStampAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants
                                                                                                                    .RECT))));
                    break;
                }

                case XfdfConstants.FREETEXT: {
                    //XfdfConstants.INK
                    pdfDocument.GetPage(Convert.ToInt32(annotObject.GetAttribute(XfdfConstants.PAGE).GetValue())).AddAnnotation
                        (new PdfFreeTextAnnotation(XfdfObjectUtils.ConvertRectFromString(annotObject.GetAttributeValue(XfdfConstants
                                                                                                                       .RECT)), annotObject.GetContents()));
                    break;
                }

                default: {
                    //XfdfConstants.FILEATTACHMENT
                    //XfdfConstants.SOUND
                    //XfdfConstants.LINK
                    //XfdfConstants.REDACT
                    //XfdfConstants.PROJECTION
                    logger.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.XFDF_ANNOTATION_IS_NOT_SUPPORTED, annotName
                                                         ));
                    break;
                }
                }
            }
        }