Hi Tilman, The flag does the trick. Thank you for the quick solution.
Jason On Mon, Apr 30, 2018 at 2:19 PM, Tilman Hausherr <thaush...@t-online.de> wrote: > If it is an annotation, then set the print flag > > setPrinted(true) > > Tilman > > Am 30.04.2018 um 17:01 schrieb JZ Q: > >> Dear Tilman, >> >> Using a sizing parameter solved the problem. Thank you. I found out the >> rubberstamp does not get printed, even if it is visible in PDF reader? >> Why? >> On the print dialog, I have selected to print stamp. >> >> Thanks. >> Jason >> >> On Mon, Apr 30, 2018 at 6:54 AM, Tilman Hausherr <thaush...@t-online.de> >> wrote: >> >> In the drawXObject call, divide / multiply the size parameters by a float >>> value, e.g. 0.5. >>> >>> TilmaN >>> >>> >>> Am 30.04.2018 um 03:35 schrieb JZ Q: >>> >>> Hi everyone, >>>> >>>> I used a lightly modified example code (RubberstampWithImage) to add >>>> rubber stamp to a text field. it works fine except the resolution of >>>> image >>>> seems to be too low. >>>> >>>> See below, if I use the image of same pixel width as the box size, the >>>> image becomes very blur. But I increase the image, it only shows part of >>>> it. >>>> >>>> So how do I add a clear stamp (image) that fits into the RECT of the >>>> text >>>> widget? Thanks. >>>> >>>> >>>> Field FQN: broker_sig >>>> Image File: broker_signature.png >>>> Image Size: (170, 34) >>>> Box Size (424.46, 16.25) >>>> in inch (5.8952775, 0.22569445) >>>> Box Position (135.035, 182.717) >>>> >>>> >>>> public static void addStamp(PDDocument document, PDField selectedField, >>>> String imageFilename) throws IOException { >>>> >>>> PDPage page = selectedField.getWidgets().get(0).getPage(); >>>> >>>> PDRectangle rect = selectedField.getWidgets().get(0).getRectangle(); >>>> List<PDAnnotation> annotations = page.getAnnotations(); >>>> PDAnnotationRubberStamp rubberStamp = new PDAnnotationRubberStamp(); >>>> >>>> // create a PDXObjectImage with the given image file >>>> PDImageXObject ximage = PDImageXObject.createFromFile(imageFilename, >>>> document); >>>> >>>> // define and set the target rectangle >>>> int imgWidth = ximage.getImage().getWidth(); >>>> int imgHeight = ximage.getImage().getHeight(); >>>> System.out.println("Field FQN: " + selectedField.getFullyQualifie >>>> dName()); >>>> System.out.println("Image File: " + imageFilename); >>>> System.out.println("Image Size: (" + imgWidth + ", " + imgHeight + ")"); >>>> System.out.println("Box Size (" + rect.getWidth() + ", " + >>>> rect.getHeight() >>>> + ")"); >>>> System.out.println("in inch (" + rect.getWidth()/72 + ", " + >>>> rect.getHeight()/72 + ")"); >>>> System.out.println("Box Position (" + rect.getLowerLeftX() + ", " + >>>> rect.getLowerLeftY() + ")"); >>>> // Create a PDFormXObject >>>> PDFormXObject form = new PDFormXObject(document); >>>> form.setResources(new PDResources()); >>>> form.setBBox(rect); >>>> form.setFormType(1); >>>> >>>> // adjust the image to the target rectangle and add it to the stream >>>> OutputStream os = form.getStream().createOutputStream(); >>>> //center the object horizontally >>>> float imageLeftX = rect.getLowerLeftX() + (rect.getWidth() - >>>> imgWidth)/2; >>>> drawXObject(ximage, form.getResources(), os, imageLeftX, >>>> rect.getLowerLeftY(), imgWidth, imgHeight); >>>> os.close(); >>>> >>>> PDAppearanceStream myDic = new PDAppearanceStream(form.getCOSObject()); >>>> PDAppearanceDictionary appearance = new PDAppearanceDictionary(new >>>> COSDictionary()); >>>> appearance.setNormalAppearance(myDic); >>>> rubberStamp.setAppearance(appearance); >>>> rubberStamp.setRectangle(rect); >>>> >>>> // add the new RubberStamp to the document >>>> annotations.add(rubberStamp); >>>> } >>>> >>>> >>>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org >>> For additional commands, e-mail: users-h...@pdfbox.apache.org >>> >>> >>> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org > For additional commands, e-mail: users-h...@pdfbox.apache.org > > -- Best Wishes, Jason