/** * The Td operator. * Move to the start of the next line, offset from the start of the current line by (tx, ty). * * @param tx The x translation. * @param ty The y translation. * @throws IOException If there is an error writing to the stream. * @throws IllegalStateException If the method was not allowed to be called at this time. */ public void newLineAtOffset(float tx, float ty) throws IOException { if (!inTextMode) { throw new IllegalStateException("Error: must call beginText() before newLineAtOffset()"); } writeOperand(tx); writeOperand(ty); writeOperator("Td"); }
/** * Set the horizontal scaling to scale / 100. * * @param scale number specifying the percentage of the normal width. Default value: 100 (normal * width). * @throws IOException If the content stream could not be written. */ public void setHorizontalScaling(float scale) throws IOException { writeOperand(scale); writeOperator("Tz"); }
/** * Move the current position to the given coordinates. * * @param x The x coordinate. * @param y The y coordinate. * @throws IOException If the content stream could not be written. * @throws IllegalStateException If the method was called within a text block. */ public void moveTo(float x, float y) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: moveTo is not allowed within a text block."); } writeOperand(x); writeOperand(y); writeOperator("m"); }
/** * Draw a line from the current position to the given coordinates. * * @param x The x coordinate. * @param y The y coordinate. * @throws IOException If the content stream could not be written. * @throws IllegalStateException If the method was called within a text block. */ public void lineTo(float x, float y) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: lineTo is not allowed within a text block."); } writeOperand(x); writeOperand(y); writeOperator("l"); }
/** * Begin a marked content sequence. * * @param tag the tag * @throws IOException If the content stream could not be written */ public void beginMarkedContent(COSName tag) throws IOException { writeOperand(tag); writeOperator("BMC"); }
/** * Set the character spacing. The value shall be added to the horizontal or vertical component * of the glyph's displacement, depending on the writing mode. * * @param spacing character spacing * @throws IOException If the content stream could not be written. */ public void setCharacterSpacing(float spacing) throws IOException { writeOperand(spacing); writeOperator("Tc"); }
/** * Sets the text leading. * * @param leading The leading in unscaled text units. * @throws IOException If there is an error writing to the stream. */ public void setLeading(float leading) throws IOException { writeOperand(leading); writeOperator("TL"); }
/** * Writes an AffineTransform to the content stream as an array. */ private void writeAffineTransform(AffineTransform transform) throws IOException { double[] values = new double[6]; transform.getMatrix(values); for (double v : values) { writeOperand((float) v); } }
/** * Begin a marked content sequence with a reference to an entry in the page resources' * Properties dictionary. * * @param tag the tag * @param propertyList property list * @throws IOException If the content stream could not be written */ public void beginMarkedContent(COSName tag, PDPropertyList propertyList) throws IOException { writeOperand(tag); writeOperand(resources.add(propertyList)); writeOperator("BDC"); }
/** * Set the text rise value, i.e. move the baseline up or down. This is useful for drawing * superscripts or subscripts. * * @param rise Specifies the distance, in unscaled text space units, to move the baseline up or * down from its default location. 0 restores the default location. * @throws IOException */ public void setTextRise(float rise) throws IOException { writeOperand(rise); writeOperator("Ts"); }
/** * Set line width to the given value. * * @param lineWidth The width which is used for drawing. * @throws IOException If the content stream could not be written * @throws IllegalStateException If the method was called within a text block. */ public void setLineWidth(float lineWidth) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: setLineWidth is not allowed within a text block."); } writeOperand(lineWidth); writeOperator("w"); }
/** * Set the word spacing. The value shall be added to the horizontal or vertical component of the * ASCII SPACE character, depending on the writing mode. * <p> * This will have an effect only with Type1 and TrueType fonts, not with Type0 fonts. The PDF * specification tells why: "Word spacing shall be applied to every occurrence of the * single-byte character code 32 in a string when using a simple font or a composite font that * defines code 32 as a single-byte code. It shall not apply to occurrences of the byte value 32 * in multiple-byte codes." * * @param spacing word spacing * @throws IOException If the content stream could not be written. */ public void setWordSpacing(float spacing) throws IOException { writeOperand(spacing); writeOperator("Tw"); }
/** * Set the miter limit. * * @param miterLimit the new miter limit. * @throws IOException If the content stream could not be written. */ public void setMiterLimit(float miterLimit) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: setMiterLimit is not allowed within a text block."); } if (miterLimit <= 0.0) { throw new IllegalArgumentException("A miter limit <= 0 is invalid and will not render in Acrobat Reader"); } writeOperand(miterLimit); writeOperator("M"); }
/** * Set an extended graphics state. * * @param state The extended graphics state. * @throws IOException If the content stream could not be written. */ public void setGraphicsStateParameters(PDExtendedGraphicsState state) throws IOException { writeOperand(resources.add(state)); writeOperator("gs"); }
/** * Set the text rendering mode. This determines whether showing text shall cause glyph outlines * to be stroked, filled, used as a clipping boundary, or some combination of the three. * * @param rm The text rendering mode. * @throws IOException If the content stream could not be written. */ public void setRenderingMode(RenderingMode rm) throws IOException { writeOperand(rm.intValue()); writeOperator("Tr"); }
/** * Draws the given Form XObject at the current location. * * @param form Form XObject * @throws IOException if the content stream could not be written * @throws IllegalStateException If the method was called within a text block. */ public void drawForm(PDFormXObject form) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: drawForm is not allowed within a text block."); } writeOperand(resources.add(form)); writeOperator("Do"); }
/** * Set the non-stroking color in the DeviceRGB color space. Range is 0..255. * * @param r The red value. * @param g The green value. * @param b The blue value. * @throws IOException If an IO error occurs while writing to the stream. * @throws IllegalArgumentException If the parameters are invalid. */ public void setNonStrokingColor(int r, int g, int b) throws IOException { if (isOutside255Interval(r) || isOutside255Interval(g) || isOutside255Interval(b)) { throw new IllegalArgumentException("Parameters must be within 0..255, but are " + String.format("(%d,%d,%d)", r, g, b)); } writeOperand(r / 255f); writeOperand(g / 255f); writeOperand(b / 255f); writeOperator("rg"); setNonStrokingColorSpaceStack(PDDeviceRGB.INSTANCE); }
/** * Fills the clipping area with the given shading. * * @param shading Shading resource * @throws IOException If the content stream could not be written * @throws IllegalStateException If the method was called within a text block. */ public void shadingFill(PDShading shading) throws IOException { if (inTextMode) { throw new IllegalStateException("Error: shadingFill is not allowed within a text block."); } writeOperand(resources.add(shading)); writeOperator("sh"); }
/** * Set the stroking color in the DeviceGray color space. Range is 0..1. * * @param g The gray value. * @throws IOException If an IO error occurs while writing to the stream. * @throws IllegalArgumentException If the parameter is invalid. */ public void setStrokingColor(float g) throws IOException { if (isOutsideOneInterval(g)) { throw new IllegalArgumentException("Parameter must be within 0..1, but is " + g); } writeOperand(g); writeOperator("G"); setStrokingColorSpaceStack(PDDeviceGray.INSTANCE); }
/** * Set the non-stroking color in the DeviceGray color space. Range is 0..1. * * @param g The gray value. * @throws IOException If an IO error occurs while writing to the stream. * @throws IllegalArgumentException If the parameter is invalid. */ public void setNonStrokingColor(float g) throws IOException { if (isOutsideOneInterval(g)) { throw new IllegalArgumentException("Parameter must be within 0..1, but is " + g); } writeOperand(g); writeOperator("g"); setNonStrokingColorSpaceStack(PDDeviceGray.INSTANCE); }