Exemple #1
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)));
 }
Exemple #2
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;
                }
                }
            }
        }
Exemple #3
0
 private void AddMarkupAnnotationAttributes(PdfMarkupAnnotation annotation, AnnotObject annotObject)
 {
     annotation.SetCreationDate(new PdfString(annotObject.GetAttributeValue(XfdfConstants.CREATION_DATE)));
     annotation.SetSubject(new PdfString(annotObject.GetAttributeValue(XfdfConstants.SUBJECT)));
 }