⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pdfcontentbyte.java

📁 一个java操作pdf文件的开发包,很好用的.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        public void newPath() {        content.append("n").append_i(separator);    }        /**     * Strokes the path.     */        public void stroke() {        content.append("S").append_i(separator);    }        /**     * Closes the path and strokes it.     */        public void closePathStroke() {        content.append("s").append_i(separator);    }        /**     * Fills the path, using the non-zero winding number rule to determine the region to fill.     */        public void fill() {        content.append("f").append_i(separator);    }        /**     * Fills the path, using the even-odd rule to determine the region to fill.     */        public void eoFill() {        content.append("f*").append_i(separator);    }        /**     * Fills the path using the non-zero winding number rule to determine the region to fill and strokes it.     */        public void fillStroke() {        content.append("B").append_i(separator);    }        /**     * Closes the path, fills it using the non-zero winding number rule to determine the region to fill and strokes it.     */        public void closePathFillStroke() {        content.append("b").append_i(separator);    }        /**     * Fills the path, using the even-odd rule to determine the region to fill and strokes it.     */        public void eoFillStroke() {        content.append("B*").append_i(separator);    }        /**     * Closes the path, fills it using the even-odd rule to determine the region to fill and strokes it.     */        public void closePathEoFillStroke() {        content.append("b*").append_i(separator);    }        /**     * Adds an <CODE>Image</CODE> to the page. The <CODE>Image</CODE> must have     * absolute positioning.     * @param image the <CODE>Image</CODE> object     * @throws DocumentException if the <CODE>Image</CODE> does not have absolute positioning     */    public void addImage(Image image) throws DocumentException {        if (!image.hasAbsolutePosition())            throw new DocumentException("The image must have absolute positioning.");        float matrix[] = image.matrix();        matrix[Image.CX] = image.absoluteX() - matrix[Image.CX];        matrix[Image.CY] = image.absoluteY() - matrix[Image.CY];        addImage(image, matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);    }        /**     * Adds an <CODE>Image</CODE> to the page. The positioning of the <CODE>Image</CODE>     * is done with the transformation matrix. To position an <CODE>image</CODE> at (x,y)     * use addImage(image, image_width, 0, 0, image_height, x, y).     * @param image the <CODE>Image</CODE> object     * @param a an element of the transformation matrix     * @param b an element of the transformation matrix     * @param c an element of the transformation matrix     * @param d an element of the transformation matrix     * @param e an element of the transformation matrix     * @param f an element of the transformation matrix     * @throws DocumentException on error     */    public void addImage(Image image, float a, float b, float c, float d, float e, float f) throws DocumentException {        checkWriter();        try {            if (image.isImgTemplate()) {                pdf.addDirectImage(image);                PdfTemplate template = image.templateData();                float w = template.getWidth();                float h = template.getHeight();                addTemplate(template, a / w, b / w, c / h, d / h, e, f);            }            else {                PdfName name = pdf.addDirectImage(image);                content.append("q ");                content.append(a).append(' ');                content.append(b).append(' ');                content.append(c).append(' ');                content.append(d).append(' ');                content.append(e).append(' ');                content.append(f).append(" cm ");                content.append(name.toString()).append(" Do Q").append_i(separator);            }        }        catch (Exception ee) {            throw new DocumentException(ee.getMessage());        }    }        /**     * Makes this <CODE>PdfContentByte</CODE> empty.     */    public void reset() {        content.reset();        stateList.clear();        state = new GraphicState();    }        /**     * Starts the writing of text.     */    public void beginText() {        state.xTLM = 0;        state.yTLM = 0;        content.append("BT").append_i(separator);    }        /**     * Ends the writing of text and makes the current font invalid.     */    public void endText() {        content.append("ET").append_i(separator);    }        /**     * Saves the graphic state. <CODE>saveState</CODE> and     * <CODE>restoreState</CODE> must be balanced.     */    public void saveState() {        content.append("q").append_i(separator);        stateList.add(state);    }        /**     * Restores the graphic state. <CODE>saveState</CODE> and     * <CODE>restoreState</CODE> must be balanced.     */    public void restoreState() {        content.append("Q").append_i(separator);        int idx = stateList.size() - 1;        if (idx < 0)            throw new RuntimeException("Unbalanced save/restore state operators.");        state = (GraphicState)stateList.get(idx);        stateList.remove(idx);    }        /**     * Sets the character spacing parameter.     *     * @param		charSpace			a parameter     */    public void setCharacterSpacing(float charSpace) {        content.append(charSpace).append(" Tc").append_i(separator);    }        /**     * Sets the word spacing parameter.     *     * @param		wordSpace			a parameter     */    public void setWordSpacing(float wordSpace) {        content.append(wordSpace).append(" Tw").append_i(separator);    }        /**     * Sets the horizontal scaling parameter.     *     * @param		scale				a parameter     */    public void setHorizontalScaling(float scale) {        content.append(scale).append(" Tz").append_i(separator);    }        /**     * Sets the text leading parameter.     * <P>     * The leading parameter is measured in text space units. It specifies the vertical distance     * between the baselines of adjacent lines of text.</P>     *     * @param		leading			the new leading     */    public void setLeading(float leading) {        state.leading = leading;        content.append(leading).append(" TL").append_i(separator);    }        /**     * Set the font and the size for the subsequent text writing.     *     * @param bf the font     * @param size the font size in points     */    public void setFontAndSize(BaseFont bf, float size) {        checkWriter();        state.size = size;        state.fontDetails = writer.add(bf);        content.append(state.fontDetails.getFontName().toPdf(null)).append(' ').append(size).append(" Tf").append_i(separator);    }        /**     * Sets the text rendering parameter.     *     * @param		rendering				a parameter     */    public void setTextRenderingMode(int rendering) {        content.append(rendering).append(" Tr").append_i(separator);    }        /**     * Sets the text rise parameter.     * <P>     * This allows to write text in subscript or superscript mode.</P>     *     * @param		rise				a parameter     */    public void setTextRise(float rise) {        content.append(rise).append(" Ts").append_i(separator);    }        /**     * A helper to insert into the content stream the <CODE>text</CODE>     * converted to bytes according to the font's encoding.     *     * @param text the text to write     */    private void showText2(String text) {        if (state.fontDetails == null)            throw new NullPointerException("Font and size must be set before writing any text");        byte b[] = state.fontDetails.convertToBytes(text);        escapeString(b, content);    }        /**     * Shows the <CODE>text</CODE>.     *     * @param text the text to write     */    public void showText(String text) {        showText2(text);        content.append("Tj").append_i(separator);    }        public static PdfTextArray getKernArray(String text, BaseFont font) {        PdfTextArray pa = new PdfTextArray();        StringBuffer acc = new StringBuffer();        int len = text.length() - 1;        char c[] = text.toCharArray();        if (len >= 0)            acc.append(c, 0, 1);        for (int k = 0; k < len; ++k) {            char c2 = c[k + 1];            int kern = font.getKerning(c[k], c2);            if (kern == 0) {                acc.append(c2);            }            else {                pa.add(acc.toString());                acc.setLength(0);                acc.append(c, k + 1, 1);                pa.add(-kern);            }        }        pa.add(acc.toString());        return pa;    }        /**     * Shows the <CODE>text</CODE> kerned.     *     * @param text the text to write     */    public void showTextKerned(String text) {        if (state.fontDetails == null)            throw new NullPointerException("Font and size must be set before writing any text");        BaseFont bf = state.fontDetails.getBaseFont();        if (bf.hasKernPairs())            showText(getKernArray(text, bf));        else            showText(text);    }        /**     * Moves to the next line and shows <CODE>text</CODE>.     *     * @param text the text to write     */    public void newlineShowText(String text) {        state.yTLM -= state.leading;        showText2(text);        content.append("'").append_i(separator);    }        /**     * Moves to the next line and shows text string, using the given values of the character and word spacing parameters.     *     * @param		wordSpacing		a parameter     * @param		charSpacing		a parameter     * @param text the text to write     */    public void newlineShowText(float wordSpacing, float charSpacing, String text) {        state.yTLM -= state.leading;        content.append(wordSpacing).append(' ').append(charSpacing);        showText2(text);        content.append("\"").append_i(separator);    }        /**     * Changes the text matrix.     * <P>     * Remark: this operation also initializes the current point position.</P>     *     * @param		a			operand 1,1 in the matrix     * @param		b			operand 1,2 in the matrix     * @param		c			operand 2,1 in the matrix     * @param		d			operand 2,2 in the matrix     * @param		x			operand 3,1 in the matrix     * @param		y			operand 3,2 in the matrix     */    public void setTextMatrix(float a, float b, float c, float d, float x, float y) {        state.xTLM = x;        state.yTLM = y;        content.append(a).append(' ').append(b).append_i(' ')        .append(c).append_i(' ').append(d).append_i(' ')        .append(x).append_i(' ').append(y).append(" Tm").append_i(separator);    }        /**     * Changes the text matrix. The first four parameters are {1,0,0,1}.     * <P>     * Remark: this operation also initializes the current point position.</P>     *     * @param		x			operand 3,1 in the matrix     * @param		y			operand 3,2 in the matrix     */    public void setTextMatrix(float x, float y) {        setTextMatrix(1, 0, 0, 1, x, y);    }        /**     * Moves to the start of the next line, offset from the start of the current line.     *     * @param		x			x-coordinate of the new current point     * @param		y			y-coordinate of the new current point     */    public void moveText(float x, float y) {        state.xTLM += x;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -