[ https://issues.apache.org/jira/browse/PDFBOX-5343?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17461179#comment-17461179 ]
Tilman Hausherr commented on PDFBOX-5343: ----------------------------------------- Here's code that creates a push button with an image. The position is set only in the widget rectangle, not in the BBox and not in the content stream. {code} PDDocument doc = new PDDocument(); PDPage page = new PDPage(); doc.addPage(page); PDAcroForm acroForm = new PDAcroForm(doc); doc.getDocumentCatalog().setAcroForm(acroForm); PDPushButton pushButton = new PDPushButton(acroForm); pushButton.setPartialName("push"); acroForm.getFields().add(pushButton); PDAnnotationWidget widget = pushButton.getWidgets().get(0); page.getAnnotations().add(widget); widget.setRectangle(new PDRectangle(50, 500, 100, 100)); // position on the page widget.setPrinted(true); widget.setPage(page); PDActionJavaScript javascriptAction = new PDActionJavaScript("app.alert(\"button pressed\")"); PDAnnotationAdditionalActions actions = new PDAnnotationAdditionalActions(); actions.setU(javascriptAction); widget.setActions(actions); // Create a PDFormXObject PDFormXObject form = new PDFormXObject(doc); form.setResources(new PDResources()); form.setBBox(new PDRectangle(100, 100)); form.setFormType(1); PDAppearanceDictionary appearanceDictionary = new PDAppearanceDictionary(new COSDictionary()); widget.setAppearance(appearanceDictionary); PDAppearanceStream appearanceStream = new PDAppearanceStream(form.getCOSObject()); appearanceDictionary.setNormalAppearance(appearanceStream); // Create the content stream BufferedImage bim = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); // black PDImageXObject image = LosslessFactory.createFromImage(doc, bim); try (PDAppearanceContentStream cs = new PDAppearanceContentStream(appearanceStream)) { cs.drawImage(image, 0, 0); } doc.save("button.pdf"); acroForm.flatten(); doc.save("button-flat.pdf"); doc.close(); {code} > PdfBox images Alignation Issue after using flatten function > ----------------------------------------------------------- > > Key: PDFBOX-5343 > URL: https://issues.apache.org/jira/browse/PDFBOX-5343 > Project: PDFBox > Issue Type: Bug > Components: AcroForm > Affects Versions: 3.0.0 PDFBox > Reporter: Mohamed Sameem > Priority: Major > Labels: PDFBox, acroform, bug, flatten, pdf > Attachments: Screenshot_2021-12-15-22-49-00-277_com.adobe.reader.jpg, > Screenshot_2021-12-15-22-50-18-641_com.adobe.reader.jpg, bug.pdf, > irregular.png, irregular2.png > > > Using flatten function of pdfbox changes the position of images from the > required box to be filled.I would like to know if there is a fix for this. I > would like the pdfbox team to look into it.Images attached The images are > moving out of their respective position after using PDAcroForm.flatten() > Images attached > https://stackoverflow.com/questions/70361091/pdfbox-images-alignation-issue-after-using-flatten-function -- This message was sent by Atlassian Jira (v8.20.1#820001) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org