private PDAppearanceContentStream getAppearanceEntryAsContentStream( PDAppearanceEntry appearanceEntry, boolean compress) throws IOException { PDAppearanceStream appearanceStream = appearanceEntry.getAppearanceStream(); setTransformationMatrix(appearanceStream); // ensure there are resources PDResources resources = appearanceStream.getResources(); if (resources == null) { resources = new PDResources(); appearanceStream.setResources(resources); } return new PDAppearanceContentStream(appearanceStream, compress); }
/** * Returns the entry as an appearance stream. * * @throws IllegalStateException if this entry is not an appearance stream */ public PDAppearanceStream getAppearanceStream() { if (!isStream()) { throw new IllegalStateException("This entry is not an appearance stream"); } return new PDAppearanceStream((COSStream) entry); }
appearanceStream = new PDAppearanceStream(field.getAcroForm().getDocument()); appearanceStream.setBBox(bbox); appearanceStream.setMatrix(calculateMatrix(bbox, rotation)); appearanceStream.setFormType(1); appearanceStream.setResources(new PDResources()); if (widget.getAppearanceCharacteristics() != null || appearanceStream.getContentStream().getLength() == 0)
PDAppearanceStream yesAP = new PDAppearanceStream(document); yesAP.setBBox(new PDRectangle(rect.getWidth(), rect.getHeight())); yesAP.setResources(new PDResources()); try (PDAppearanceContentStream yesAPCS = new PDAppearanceContentStream(yesAP))
public static PDAppearanceStream createCheckboxAppearance(String appear, PDDocument doc, PDResources resources) { PDAppearanceStream s = new PDAppearanceStream(doc); s.setBBox(new PDRectangle(100f, 100f)); OutputStream os = null; try { os = s.getContentStream().createOutputStream(); os.write(appear.getBytes("ASCII")); } catch (IOException e) { throw new PdfContentStreamAdapter.PdfException("createCheckboxAppearance", e); } finally { try { if (os != null) os.close(); } catch (IOException e) { } } s.setResources(resources); return s; }
/** * Create a new appearance stream. * * @param appearance * The appearance stream to add to. * @param outputStream * The appearances output stream to write to. */ public PDAppearanceContentStream(PDAppearanceStream appearance, OutputStream outputStream) { super(null, outputStream, appearance.getResources()); }
private static PDAppearanceStream createCheckBoxAppearanceStream( final PDDocument document, PDAnnotationWidget widget, boolean on) throws IOException { PDRectangle rect = widget.getRectangle(); PDAppearanceStream onAP = new PDAppearanceStream(document); onAP.setBBox(new PDRectangle(rect.getWidth(), rect.getHeight())); try (PDAppearanceContentStream onAPCS = new PDAppearanceContentStream(onAP)) { PDAppearanceCharacteristicsDictionary appearanceCharacteristics = widget.getAppearanceCharacteristics(); PDColor backgroundColor = appearanceCharacteristics.getBackground(); PDColor borderColor = appearanceCharacteristics.getBorderColour(); float lineWidth = getLineWidth(widget); onAPCS.setBorderLine(lineWidth, widget.getBorderStyle(), widget.getBorder()); onAPCS.setNonStrokingColor(backgroundColor); float radius = Math.min(rect.getWidth() / 2, rect.getHeight() / 2); drawCircle(onAPCS, rect.getWidth() / 2, rect.getHeight() / 2, radius); onAPCS.fill(); onAPCS.setStrokingColor(borderColor); drawCircle(onAPCS, rect.getWidth() / 2, rect.getHeight() / 2, radius - lineWidth / 2); onAPCS.stroke(); if (on) { onAPCS.setNonStrokingColor(0f); drawCircle(onAPCS, rect.getWidth() / 2, rect.getHeight() / 2, (radius - lineWidth) / 2); onAPCS.fill(); } } return onAP; }
annotation.setRectDifferences(rd); bbox = new PDRectangle(-rd, -rd, rect.getWidth() + 2 * rd, rect.getHeight() + 2 * rd); Matrix matrix = annotation.getNormalAppearanceStream().getMatrix(); matrix.transformPoint(rd, rd); annotation.getNormalAppearanceStream().setMatrix(matrix.createAffineTransform()); PDRectangle rect2 = new PDRectangle(rect.getLowerLeftX() - rd, rect.getLowerLeftY() - rd, rect.getWidth() + 2 * rd, rect.getHeight() + 2 * rd); annotation.setRectangle(rect2); annotation.getNormalAppearanceStream().setBBox(bbox);
pdAppearanceStream.setResources(new PDResources()); try (PDPageContentStream pdPageContentStream = new PDPageContentStream(document, pdAppearanceStream)) pdAppearanceStream.setBBox(new PDRectangle(width, height));
/** * Create a new appearance stream. * * @param appearance * The appearance stream to write to. * @throws IOException If there is an error writing to the content stream. */ public PDAppearanceContentStream(PDAppearanceStream appearance) throws IOException { this(appearance, appearance.getStream().createOutputStream()); }
processSubStream( page, appearance.getResources(), appearance.getStream() ); g.translate( (int)-rect.getLowerLeftX(), (int)+rect.getLowerLeftY() );
private PDRectangle adjustRectAndBBox(PDAnnotationText annotation, float width, float height) { // For /Note (other types have different values): // Adobe takes the left upper bound as anchor, and adjusts the rectangle to 18 x 20. // Observed with files 007071.pdf, 038785.pdf, 038787.pdf, // but not with 047745.pdf p133 and 084374.pdf p48, both have the NoZoom flag. // there the BBox is also set to fixed values, but the rectangle is left untouched. // When no flags are there, Adobe sets /F 24 = NoZoom NoRotate. PDRectangle rect = getRectangle(); PDRectangle bbox; if (!annotation.isNoZoom()) { rect.setUpperRightX(rect.getLowerLeftX() + width); rect.setLowerLeftY(rect.getUpperRightY() - height); annotation.setRectangle(rect); } if (!annotation.getCOSObject().containsKey(COSName.F)) { // We set these flags because Adobe does so, but PDFBox doesn't support them when rendering. annotation.setNoRotate(true); annotation.setNoZoom(true); } bbox = new PDRectangle(width, height); annotation.getNormalAppearanceStream().setBBox(bbox); return bbox; }
private void addAppearance(List<PDContentStream> list, PDAppearanceStream toAdd) { if (toAdd != null) { PDInheritableResources resources = PDInheritableResources.getInstance(this.pageResources, toAdd.getResources()); PBoxPDContentStream stream = new PBoxPDContentStream(toAdd, resources, this.document, this.flavour); this.containsTransparency |= stream.isContainsTransparency(); org.apache.pdfbox.pdmodel.graphics.form.PDGroup group = toAdd.getGroup(); this.containsTransparency |= group != null && COSName.TRANSPARENCY.equals(group.getSubType()); list.add(stream); } } }
/** * Resolve the bounding box. * * @param fieldWidget the annotation widget. * @param appearanceStream the annotations appearance stream. * @return the resolved boundingBox. */ private PDRectangle resolveBoundingBox(PDAnnotationWidget fieldWidget, PDAppearanceStream appearanceStream) { PDRectangle boundingBox = appearanceStream.getBBox(); if (boundingBox == null) { boundingBox = fieldWidget.getRectangle().createRetranslatedRectangle(); } return boundingBox; }
PDFormXObject fieldObject = new PDFormXObject(appearanceStream.getCOSObject()); PDRectangle bbox = appearanceStream.getBBox(); PDRectangle fieldRect = annotation.getRectangle();
/** * Writes the stream to the actual stream in the COSStream. * * @throws IOException If there is an error writing to the stream */ private void writeToStream(byte[] data, PDAppearanceStream appearanceStream) throws IOException { try (OutputStream out = appearanceStream.getCOSObject().createOutputStream()) { out.write(data); } }
appearanceStream = new PDAppearanceStream(field.getAcroForm().getDocument()); appearanceStream.setBBox(bbox); appearanceStream.setMatrix(calculateMatrix(bbox, rotation)); appearanceStream.setFormType(1); appearanceStream.setResources(new PDResources()); if (widget.getAppearanceCharacteristics() != null || appearanceStream.getContentStream().getLength() == 0)
pattern.setMatrix(patternTransform); PDAppearanceStream appearance = new PDAppearanceStream(state.document); appearance.setResources(pattern.getResources()); appearance.setBBox(pattern.getBBox());