@Override protected PdfObject newInstance() { return new PdfStream(); }
/** * Creates a Type3Glyph canvas with a new Content Stream. * * @param pdfDocument the document that this canvas is created for */ Type3Glyph(PdfDocument pdfDocument, float wx, float llx, float lly, float urx, float ury, boolean isColor) { super((PdfStream)new PdfStream().makeIndirect(pdfDocument), null, pdfDocument); writeMetrics(wx, llx, lly, urx, ury, isColor); }
/** * Parses an inline image from the provided content parser. The parser must be positioned immediately following the BI operator in the content stream. * The parser will be left with current position immediately following the EI operator that terminates the inline image * * @param ps the content parser to use for reading the image. * @param colorSpaceDic a color space dictionary * @return the parsed image * @throws IOException if anything goes wring with the parsing * @throws InlineImageParseException if parsing of the inline image failed due to issues specific to inline image processing */ public static PdfStream parse(PdfCanvasParser ps, PdfDictionary colorSpaceDic) throws IOException { PdfDictionary inlineImageDict = parseDictionary(ps); byte[] samples = parseSamples(inlineImageDict, colorSpaceDic, ps); PdfStream inlineImageAsStreamObject = new PdfStream(samples); inlineImageAsStreamObject.putAll(inlineImageDict); return inlineImageAsStreamObject; }
private static PdfStream makeType4(PdfArray domain, PdfArray range, byte[] ps) { PdfStream stream = new PdfStream(ps); stream.put(PdfName.FunctionType, new PdfNumber(4)); stream.put(PdfName.Domain, domain); stream.put(PdfName.Range, range); return stream; } }
/** * Generate default appearance, /DA key. * * @param font preferred font. If {@link #getFont()} is not null, it will be used instead. * @param fontSize preferred font size. If {@link PdfFormField#fontSize} is valid, * it will be used instead. * @return generated string */ protected String generateDefaultAppearanceString(PdfFont font, float fontSize, Color color, PdfResources res) { if (this.fontSize >= 0) { fontSize = this.fontSize; } if (this.font != null) { font = this.font; } PdfStream stream = new PdfStream(); PdfCanvas canvas = new PdfCanvas(stream, res, getDocument()); canvas.setFontAndSize(font, fontSize); if (color != null) canvas.setColor(color, true); return new String(stream.getBytes()); }
/** * Generate default appearance, /DA key. * * @param font preferred font. If {@link #getFont()} is not null, it will be used instead. * @param fontSize preferred font size. If {@link PdfFormField#fontSize} is valid, * it will be used instead. * @return generated string */ protected String generateDefaultAppearanceString(PdfFont font, float fontSize, Color color, PdfResources res) { if (this.fontSize >= 0) { fontSize = this.fontSize; } if (this.font != null) { font = this.font; } PdfStream stream = new PdfStream(); PdfCanvas canvas = new PdfCanvas(stream, res, getDocument()); canvas.setFontAndSize(font, fontSize); if (color != null) canvas.setColor(color, true); return new String(stream.getBytes()); }
/** * Creates the new instance of the class. * * @param cs the {@link PdfColorSpace} object in which colour values shall be expressed. * The special Pattern space isn't excepted. * @param bitsPerCoordinate the number of bits used to represent each vertex coordinate. * The value shall be 1, 2, 4, 8, 12, 16, 24, or 32. * @param bitsPerComponent the number of bits used to represent each colour component. * The value shall be 1, 2, 4, 8, 12, or 16. * @param verticesPerRow the number of vertices in each row of the lattice (shall be > 1). * The number of rows need not be specified. * @param decode the {@link PdfArray} of numbers specifying how to map vertex coordinates and colour components * into the appropriate ranges of values. The ranges shall be specified as follows: * [x_min x_max y_min y_max c1_min c1_max … cn_min cn_max]. * Only one pair of color values shall be specified if a Function entry is present. */ public LatticeFormGouraudShadedTriangleMesh(PdfColorSpace cs, int bitsPerCoordinate, int bitsPerComponent, int verticesPerRow, PdfArray decode) { super(new PdfStream(), ShadingType.LATTICE_FORM_GOURAUD_SHADED_TRIANGLE_MESH, cs); setBitsPerCoordinate(bitsPerCoordinate); setBitsPerComponent(bitsPerComponent); setVerticesPerRow(verticesPerRow); setDecode(decode); }
/** * Create {@code PdfStream} based on {@code fontStreamBytes}. * * @param fontStreamBytes original font data, must be not null. * @param fontStreamLengths array to generate {@code Length*} keys, must be not null. * @return the PdfStream containing the font or {@code null}, if there is an error reading the font. * @throws PdfException Method will throw exception if {@code fontStreamBytes} is {@code null}. */ protected PdfStream getPdfFontStream(byte[] fontStreamBytes, int[] fontStreamLengths) { if (fontStreamBytes == null) { throw new PdfException(PdfException.FontEmbeddingIssue); } PdfStream fontStream = new PdfStream(fontStreamBytes); makeObjectIndirect(fontStream); for (int k = 0; k < fontStreamLengths.length; ++k) { fontStream.put(new PdfName("Length" + (k + 1)), new PdfNumber(fontStreamLengths[k])); } return fontStream; }
/** * Creates a new instance of Form XObject. * * @param bBox the form XObject’s bounding box. */ public PdfFormXObject(Rectangle bBox) { super(new PdfStream()); getPdfObject().put(PdfName.Type, PdfName.XObject); getPdfObject().put(PdfName.Subtype, PdfName.Form); if (bBox != null) { getPdfObject().put(PdfName.BBox, new PdfArray(bBox)); } }
/** * Sets the XMP Metadata. * * @param xmpMetadata the {@code byte[]} of XMP Metadata to set. * @return this {@link PdfPage} instance. * @throws IOException in case of writing error. */ public PdfPage setXmpMetadata(byte[] xmpMetadata) throws IOException { PdfStream xmp = (PdfStream) new PdfStream().makeIndirect(getDocument()); xmp.getOutputStream().write(xmpMetadata); xmp.put(PdfName.Type, PdfName.Metadata); xmp.put(PdfName.Subtype, PdfName.XML); put(PdfName.Metadata, xmp); return this; }
public static PdfStream getIccProfileStream(IccProfile iccProfile) { PdfStream stream = new PdfStream(iccProfile.getData()); stream.put(PdfName.N, new PdfNumber(iccProfile.getNumComponents())); switch (iccProfile.getNumComponents()) { case 1: stream.put(PdfName.Alternate, PdfName.DeviceGray); break; case 3: stream.put(PdfName.Alternate, PdfName.DeviceRGB); break; case 4: stream.put(PdfName.Alternate, PdfName.DeviceCMYK); break; default: break; } return stream; }
private static PdfStream makeType0(PdfArray domain, PdfArray range, PdfArray size, PdfNumber bitsPerSample, PdfNumber order, PdfArray encode, PdfArray decode, byte[] samples) { PdfStream stream = new PdfStream(samples); stream.put(PdfName.FunctionType, new PdfNumber(0)); stream.put(PdfName.Domain, domain); stream.put(PdfName.Range, range); stream.put(PdfName.Size, size); stream.put(PdfName.BitsPerSample, bitsPerSample); if (order != null) stream.put(PdfName.Order, order); if (encode != null) stream.put(PdfName.Encode, encode); if (decode != null) stream.put(PdfName.Decode, decode); return stream; } }
/** * Embed a file to a PdfDocument. * * @param doc * @param is * @param description * @param fileDisplay * @param mimeType * @param fileParameter * @param afRelationshipValue */ public static PdfFileSpec createEmbeddedFileSpec(PdfDocument doc, InputStream is, String description, String fileDisplay, PdfName mimeType, PdfDictionary fileParameter, PdfName afRelationshipValue) { PdfStream stream = new PdfStream(doc, is); PdfDictionary params = new PdfDictionary(); if (fileParameter != null) { params.mergeDifferent(fileParameter); } if (!params.containsKey(PdfName.ModDate)) { params.put(PdfName.ModDate, new PdfDate().getPdfObject()); } stream.put(PdfName.Params, params); return createEmbeddedFileSpec(doc, stream, description, fileDisplay, mimeType, afRelationshipValue); }
/** * Creates a sound annotation. Sound annotations are deprecated in PDF 2.0. * @param document * @param rect * @param soundStream * @param sampleRate * @param encoding * @param channels * @param sampleSizeInBits * @throws IOException */ public PdfSoundAnnotation(PdfDocument document, Rectangle rect, InputStream soundStream, float sampleRate, PdfName encoding, int channels, int sampleSizeInBits) throws IOException { super(rect); PdfStream sound = new PdfStream(document, correctWavFile(soundStream)); sound.put(PdfName.R, new PdfNumber(sampleRate)); sound.put(PdfName.E, encoding); sound.put(PdfName.B, new PdfNumber(sampleSizeInBits)); sound.put(PdfName.C, new PdfNumber(channels)); put(PdfName.Sound, sound); }
/** * Draws the appearance of a radio button with a specified value. * * @param width the width of the radio button to draw * @param height the height of the radio button to draw * @param value the value of the button * @deprecated Please, use {@link #drawRadioAppearance(float, float, String)} instead. */ @Deprecated protected void drawPdfA1RadioAppearance(float width, float height, String value) { PdfStream stream = (PdfStream) new PdfStream().makeIndirect(getDocument()); PdfCanvas canvas = new PdfCanvas(stream, new PdfResources(), getDocument()); Rectangle rect = new Rectangle(0, 0, width, height); PdfFormXObject xObject = new PdfFormXObject(rect); drawBorder(canvas, xObject, width, height); drawRadioField(canvas, rect.getWidth(), rect.getHeight(), !"Off".equals(value)); PdfDictionary normalAppearance = new PdfDictionary(); normalAppearance.put(new PdfName(value), xObject.getPdfObject()); PdfWidgetAnnotation widget = getWidgets().get(0); xObject.getPdfObject().getOutputStream().writeBytes(stream.getBytes()); widget.setNormalAppearance(normalAppearance); }
/** * Draws the appearance of a radio button with a specified value. * * @param width the width of the radio button to draw * @param height the height of the radio button to draw * @param value the value of the button * @deprecated Please, use {@link #drawRadioAppearance(float, float, String)} instead. */ @Deprecated protected void drawPdfA1RadioAppearance(float width, float height, String value) { PdfStream stream = (PdfStream) new PdfStream().makeIndirect(getDocument()); PdfCanvas canvas = new PdfCanvas(stream, new PdfResources(), getDocument()); Rectangle rect = new Rectangle(0, 0, width, height); PdfFormXObject xObject = new PdfFormXObject(rect); drawBorder(canvas, xObject, width, height); drawRadioField(canvas, rect.getWidth(), rect.getHeight(), !"Off".equals(value)); PdfDictionary normalAppearance = new PdfDictionary(); normalAppearance.put(new PdfName(value), xObject.getPdfObject()); PdfWidgetAnnotation widget = getWidgets().get(0); xObject.getPdfObject().getOutputStream().writeBytes(stream.getBytes()); widget.setNormalAppearance(normalAppearance); }
/** * @deprecated use {@link #drawPdfA2CheckAppearance(float, float, String, int)} instead. */ @Deprecated protected void drawPdfA1CheckAppearance(float width, float height, String selectedValue, int checkType) { PdfStream stream = (PdfStream) new PdfStream().makeIndirect(getDocument()); PdfCanvas canvas = new PdfCanvas(stream, new PdfResources(), getDocument()); Rectangle rect = new Rectangle(0, 0, width, height); PdfFormXObject xObject = new PdfFormXObject(rect); this.checkType = checkType; drawBorder(canvas, xObject, width, height); drawPdfACheckBox(canvas, width, height, !"Off".equals(selectedValue)); xObject.getPdfObject().getOutputStream().writeBytes(stream.getBytes()); PdfDictionary normalAppearance = new PdfDictionary(); normalAppearance.put(new PdfName(selectedValue), xObject.getPdfObject()); PdfDictionary mk = new PdfDictionary(); mk.put(PdfName.CA, new PdfString(text)); PdfWidgetAnnotation widget = getWidgets().get(0); widget.put(PdfName.MK, mk); widget.setNormalAppearance(normalAppearance); }
/** * @deprecated use {@link #drawPdfA2CheckAppearance(float, float, String, int)} instead. */ @Deprecated protected void drawPdfA1CheckAppearance(float width, float height, String selectedValue, int checkType) { PdfStream stream = (PdfStream) new PdfStream().makeIndirect(getDocument()); PdfCanvas canvas = new PdfCanvas(stream, new PdfResources(), getDocument()); Rectangle rect = new Rectangle(0, 0, width, height); PdfFormXObject xObject = new PdfFormXObject(rect); this.checkType = checkType; drawBorder(canvas, xObject, width, height); drawPdfACheckBox(canvas, width, height, !"Off".equals(selectedValue)); xObject.getPdfObject().getOutputStream().writeBytes(stream.getBytes()); PdfDictionary normalAppearance = new PdfDictionary(); normalAppearance.put(new PdfName(selectedValue), xObject.getPdfObject()); PdfDictionary mk = new PdfDictionary(); mk.put(PdfName.CA, new PdfString(text)); PdfWidgetAnnotation widget = getWidgets().get(0); widget.put(PdfName.MK, mk); widget.setNormalAppearance(normalAppearance); }
protected PdfPage(PdfDocument pdfDocument, PageSize pageSize) { this((PdfDictionary) new PdfDictionary().makeIndirect(pdfDocument)); PdfStream contentStream = (PdfStream) new PdfStream().makeIndirect(pdfDocument); getPdfObject().put(PdfName.Contents, contentStream); getPdfObject().put(PdfName.Type, PdfName.Page); getPdfObject().put(PdfName.MediaBox, new PdfArray(pageSize)); getPdfObject().put(PdfName.TrimBox, new PdfArray(pageSize)); if (pdfDocument.isTagged()) { setTabOrder(PdfName.S); } }
public Tiling(Rectangle bbox, float xStep, float yStep, boolean colored) { super(new PdfStream()); getPdfObject().put(PdfName.Type, PdfName.Pattern); getPdfObject().put(PdfName.PatternType, new PdfNumber(1)); getPdfObject().put(PdfName.PaintType, new PdfNumber(colored ? PaintType.COLORED : PaintType.UNCOLORED)); getPdfObject().put(PdfName.TilingType, new PdfNumber(TilingType.CONSTANT_SPACING)); getPdfObject().put(PdfName.BBox, new PdfArray(bbox)); getPdfObject().put(PdfName.XStep, new PdfNumber(xStep)); getPdfObject().put(PdfName.YStep, new PdfNumber(yStep)); resources = new PdfResources(); getPdfObject().put(PdfName.Resources, resources.getPdfObject()); }