public PDFAnnotation(PDFAnnotationType type, PDFRectangle position, string content) { PDColor color = PDFHelper.GetColor(PDFColor.Black); switch (type) { case PDFAnnotationType.PDFAnnotationLine: { this.Direction = PDFDirection.UP; PDAnnotationLine pDAnnotationLine = new PDAnnotationLine(); (new PDBorderStyleDictionary()).setWidth(6f); pDAnnotationLine.setEndPointEndingStyle("ROpenArrow"); pDAnnotationLine.setCaption(true); this.pdfAnotation = pDAnnotationLine; break; } case PDFAnnotationType.PDFAnnotationLink: { PDAnnotationLink pDAnnotationLink = new PDAnnotationLink(); PDActionURI pDActionURI = new PDActionURI(); pDActionURI.setURI(content); pDAnnotationLink.setAction(pDActionURI); pDAnnotationLink.setContents(content); this.pdfAnotation = pDAnnotationLink; break; } case PDFAnnotationType.PDFAnnotationPopup: { this.pdfAnotation = new PDAnnotationPopup(); break; } case PDFAnnotationType.PDFAnnotationRubberStamp: { this.pdfAnotation = new PDAnnotationRubberStamp(); break; } case PDFAnnotationType.PDFAnnotationSquare: { this.pdfAnotation = new PDAnnotationSquareCircle("Square"); break; } case PDFAnnotationType.PDFAnnotationCircle: { this.pdfAnotation = new PDAnnotationSquareCircle("Circle"); break; } case PDFAnnotationType.PDFAnnotationText: { this.pdfAnotation = new PDAnnotationText(); break; } case PDFAnnotationType.PDFAnnotationTextMarkup: { PDAnnotationTextMarkup pDAnnotationTextMarkup = new PDAnnotationTextMarkup("FreeText"); float[] array = new float[8]; array[0] = position.PDFBoxRectangle.getLowerLeftX(); array[1] = position.PDFBoxRectangle.getUpperRightY() - 2f; array[2] = position.PDFBoxRectangle.getUpperRightX(); array[3] = array[1]; array[4] = array[0]; array[5] = position.PDFBoxRectangle.getLowerLeftY() - 2f; array[6] = array[2]; array[7] = array[5]; pDAnnotationTextMarkup.setQuadPoints(array); pDAnnotationTextMarkup.setContents(content); pDAnnotationTextMarkup.setConstantOpacity(0.2f); this.pdfAnotation = pDAnnotationTextMarkup; break; } } this.annotationType = type; this.position = position; if (string.IsNullOrEmpty(this.pdfAnotation.getContents())) { this.pdfAnotation.setContents(content); } this.pdfAnotation.setColor(color); }
public bool AddAnnotation(PDFAnnotation annotation, PDFDocument doc) { bool result; try { List annotations = this.PDFBoxPage.getAnnotations(); PDRectangle rectangle = new PDRectangle(annotation.Position.X, this.MediaBox.Height - annotation.Position.Y - annotation.Position.Height, annotation.Position.Width, annotation.Position.Height); annotation.pdfAnotation.setRectangle(rectangle); bool flag = annotation.type == PDFAnnotationType.PDFAnnotationLine; if (flag) { PDAnnotationLine pDAnnotationLine = (PDAnnotationLine)annotation.pdfAnotation; float[] array = new float[4]; switch (annotation.Direction) { case PDFDirection.DIAGONALLEFTUP: array[2] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array[3] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY(); array[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX() + annotation.Position.PDFBoxRectangle.getWidth(); array[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - annotation.Position.PDFBoxRectangle.getHeight(); break; case PDFDirection.DIAGONALRIGHTUP: array[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - annotation.Position.PDFBoxRectangle.getHeight(); array[2] = annotation.Position.PDFBoxRectangle.getLowerLeftX() + annotation.Position.PDFBoxRectangle.getWidth(); array[3] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY(); break; case PDFDirection.DIAGONALRIGHTDOWN: array[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY(); array[2] = annotation.Position.PDFBoxRectangle.getLowerLeftX() + annotation.Position.PDFBoxRectangle.getWidth(); array[3] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - annotation.Position.PDFBoxRectangle.getHeight(); break; case PDFDirection.DIAGONALLEFTDOWN: array[2] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array[3] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - annotation.Position.PDFBoxRectangle.getHeight(); array[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX() + annotation.Position.PDFBoxRectangle.getWidth(); array[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY(); break; } pDAnnotationLine.setLine(array); annotations.add(pDAnnotationLine); } else { bool flag2 = annotation.type == PDFAnnotationType.PDFAnnotationTextMarkup; if (flag2) { PDAnnotationTextMarkup pDAnnotationTextMarkup = (PDAnnotationTextMarkup)annotation.pdfAnotation; float[] array2 = new float[8]; array2[0] = annotation.Position.PDFBoxRectangle.getLowerLeftX(); array2[1] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getUpperRightY() - 2f; array2[2] = annotation.Position.PDFBoxRectangle.getUpperRightX(); array2[3] = array2[1]; array2[4] = array2[0]; array2[5] = this.PDFBoxPage.getCropBox().getHeight() - annotation.Position.PDFBoxRectangle.getLowerLeftY() - 2f; array2[6] = array2[2]; array2[7] = array2[5]; pDAnnotationTextMarkup.setQuadPoints(array2); annotations.add(pDAnnotationTextMarkup); } else { bool flag3 = annotation.type == PDFAnnotationType.PDFAnnotationLink; if (flag3) { PDAnnotationLink pDAnnotationLink = (PDAnnotationLink)annotation.pdfAnotation; bool flag4 = !string.IsNullOrEmpty(annotation.LinkURL); if (flag4) { PDActionURI pDActionURI = new PDActionURI(); pDActionURI.setURI(annotation.LinkURL); pDAnnotationLink.setAction(pDActionURI); } else { Console.WriteLine("The PDFAnnotationLink has no LinkURL property. Set this property for the link to work well."); } annotations.add(pDAnnotationLink); } else { bool flag5 = annotation.type == PDFAnnotationType.PDFAnnotationRubberStamp; if (flag5) { PDAnnotationRubberStamp pDAnnotationRubberStamp = (PDAnnotationRubberStamp)annotation.pdfAnotation; pDAnnotationRubberStamp.setName("TopSecret"); pDAnnotationRubberStamp.setAppearance(PDFHelper.GetRubberStampAppearance(doc, annotation.Position, annotation.SubType)); pDAnnotationRubberStamp.setRectangle(rectangle); annotations.add(pDAnnotationRubberStamp); } else { annotations.add(annotation.pdfAnotation); } } } } result = true; } catch (Exception ex) { throw new PDFToolkitException(ex.Message, ex); } return(result); }