|
25 | 25 | import org.apache.pdfbox.pdmodel.common.PDRectangle; |
26 | 26 | import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation; |
27 | 27 | import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationFileAttachment; |
| 28 | +import org.apache.pdfbox.util.Matrix; |
28 | 29 |
|
29 | 30 | /** |
30 | 31 | * |
@@ -64,8 +65,19 @@ public void generateNormalAppearance() |
64 | 65 | annotation.setRectangle(rect); |
65 | 66 | annotation.getNormalAppearanceStream().setBBox(new PDRectangle(size, size)); |
66 | 67 |
|
67 | | - //TODO support Graph, PushPin, Paperclip, Tag |
68 | | - drawPaperclip(contentStream); |
| 68 | + //TODO support Graph, Tag |
| 69 | + // test case: pdf_commenting_new.pdf page 7 |
| 70 | + String attachmentName = annotation.getAttachmentName(); |
| 71 | + switch (attachmentName) |
| 72 | + { |
| 73 | + case "PushPin": |
| 74 | + drawPushPin(contentStream); |
| 75 | + break; |
| 76 | + case "Paperclip": |
| 77 | + default: |
| 78 | + drawPaperclip(contentStream); |
| 79 | + break; |
| 80 | + } |
69 | 81 | } |
70 | 82 | catch (IOException e) |
71 | 83 | { |
@@ -112,7 +124,60 @@ private void drawPaperclip(final PDAppearanceContentStream contentStream) throws |
112 | 124 | contentStream.closePath(); |
113 | 125 | contentStream.fill(); |
114 | 126 | } |
115 | | - |
| 127 | + |
| 128 | + private void drawPushPin(final PDAppearanceContentStream contentStream) throws IOException |
| 129 | + { |
| 130 | + // ty 18 is from the caller, scale 0.022 is by trial and error |
| 131 | + contentStream.transform(new Matrix(0.022f, 0, 0, -0.022f, 0f, 18f)); |
| 132 | + |
| 133 | + // Source: https://www.svgrepo.com/svg/269187/push-pin |
| 134 | + // License: CC0 |
| 135 | + contentStream.transform(Matrix.getTranslateInstance(586.47f, 178.97f)); |
| 136 | + contentStream.moveTo(0, 0); |
| 137 | + contentStream.curveTo(13f, 0f, 23.43f, -10.58f, 23.43f, -23.57f); |
| 138 | + contentStream.lineTo(23.43f, -70.53f); |
| 139 | + contentStream.curveTo(23.43f, -109.32f, -8.19f, -141.06f, -47.03f, -141.06f); |
| 140 | + contentStream.lineTo(-329.17f, -141.06f); |
| 141 | + contentStream.curveTo(-368.17f, -141.06f, -399.79f, -109.32f, -399.79f, -70.53f); |
| 142 | + contentStream.lineTo(-399.79f, -23.57f); |
| 143 | + contentStream.curveTo(-399.79f, -10.58f, -389.19f, 0.0f, -376.19f, 0f); |
| 144 | + contentStream.lineTo(-305.74f, 0f); |
| 145 | + contentStream.lineTo(-305.74f, 129.52f); |
| 146 | + contentStream.curveTo(-364.0f, 168.47f, -399.79f, 234.67f, -399.79f, 305.36f); |
| 147 | + contentStream.curveTo(-399.79f, 318.34f, -389.19f, 328.76f, -376.19f, 328.76f); |
| 148 | + contentStream.lineTo(-211.69f, 328.76f); |
| 149 | + contentStream.lineTo(-211.69f, 555.9f); |
| 150 | + contentStream.curveTo(-211.69f, 568.88f, -201.1f, 579.3f, -188.1f, 579.3f); |
| 151 | + contentStream.curveTo(-175.1f, 579.3f, -164.67f, 568.88f, -164.67f, 555.9f); |
| 152 | + contentStream.lineTo(-164.67f, 328.76f); |
| 153 | + contentStream.lineTo(0f, 328.76f); |
| 154 | + contentStream.curveTo(13.0f, 328.76f, 23.43f, 318.34f, 23.43f, 305.36f); |
| 155 | + contentStream.curveTo(23.43f, 234.67f, -12.2f, 168.47f, -70.62f, 129.52f); |
| 156 | + contentStream.lineTo(-70.62f, 0f); |
| 157 | + contentStream.lineTo(0f, 0f); |
| 158 | + contentStream.closePath(); |
| 159 | + contentStream.moveTo(-25.2f, 281.79f); |
| 160 | + contentStream.lineTo(-351.0f, 281.79f); |
| 161 | + contentStream.curveTo(-343.77f, 232.42f, -314.24f, 188.18f, -270.43f, 162.86f); |
| 162 | + contentStream.curveTo(-263.21f, 158.69f, -258.71f, 150.99f, -258.71f, 142.5f); |
| 163 | + contentStream.lineTo(-258.71f, 0f); |
| 164 | + contentStream.lineTo(-117.64f, 0f); |
| 165 | + contentStream.lineTo(-117.64f, 142.5f); |
| 166 | + contentStream.curveTo(-117.64f, 150.99f, -113.15f, 158.69f, -105.77f, 162.86f); |
| 167 | + contentStream.curveTo(-61.95f, 188.18f, -32.42f, 232.42f, -25.2f, 281.79f); |
| 168 | + contentStream.closePath(); |
| 169 | + contentStream.moveTo(-352.76f, -46.97f); |
| 170 | + contentStream.lineTo(-352.76f, -70.53f); |
| 171 | + contentStream.curveTo(-352.76f, -83.52f, -342.17f, -93.93f, -329.17f, -93.93f); |
| 172 | + contentStream.lineTo(-47.03f, -93.93f); |
| 173 | + contentStream.curveTo(-34.03f, -93.93f, -23.59f, -83.52f, -23.59f, -70.53f); |
| 174 | + contentStream.lineTo(-23.59f, -46.97f); |
| 175 | + contentStream.lineTo(-352.76f, -46.97f); |
| 176 | + contentStream.lineTo(-352.76f, -46.97f); |
| 177 | + contentStream.closePath(); |
| 178 | + contentStream.fill(); |
| 179 | + } |
| 180 | + |
116 | 181 | @Override |
117 | 182 | public void generateRolloverAppearance() |
118 | 183 | { |
|
0 commit comments