'Stamp Annotation added at wrong place
Using below code when we add Stamp Annotation on PDF page, it will add that stamp at random location for some files.
BufferedImage bufferedImage = getImage();
PDImageXObject image = JPEGFactory.createFromImage(pdDocument, bufferedImage)
PDAnnotationRubberStamp rubberStamp = new PDAnnotationRubberStamp();
rubberStamp.setRectangle(new PDRectangle(x, y, width, height));
rubberStamp.setName(Name);
PDFormXObject form = new PDFormXObject(pdDocument);
form.setMatrix(AffineTransform.getRotateInstance(Math.toRadians(rotation)));
form.setBBox(new PDRectangle(x, y, width, height));
form.setResources(new PDResources());
PDAppearanceStream myDic = new PDAppearanceStream(form.getCOSObject());
PDPageContentStream pageContentStream = new PDPageContentStream(pdDocument, myDic);
pageContentStream.drawImage(image, x, y, width, height);
pageContentStream.close();
PDAppearanceDictionary appearance = new PDAppearanceDictionary(new COSDictionary());
appearance.setNormalAppearance(myDic);
rubberStamp.setAppearance(appearance);
annotations.add(rubberStamp);
For example, for some files x coordinate 0.0 considers right side of page and for some files it will be bottom.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
