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

📄 pdfcontentbyte.java

📁 一个java操作pdf文件的开发包,很好用的.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @param width the width of the pattern     * @param height the height of the pattern     * @return the <CODE>PdfPatternPainter</CODE> where the pattern will be created     */    public PdfPatternPainter createPattern(float width, float height) {        return createPattern(width, height, width, height);    }        /**     * Create a new uncolored tiling pattern.     *     * @param width the width of the pattern     * @param height the height of the pattern     * @param xstep the desired horizontal spacing between pattern cells.     * May be either positive or negative, but not zero.     * @param ystep the desired vertical spacing between pattern cells.     * May be either positive or negative, but not zero.     * @param color the default color. Can be <CODE>null</CODE>     * @return the <CODE>PdfPatternPainter</CODE> where the pattern will be created     */    public PdfPatternPainter createPattern(float width, float height, float xstep, float ystep, Color color) {        checkWriter();        if ( xstep == 0.0f || ystep == 0.0f )            throw new RuntimeException("XStep or YStep can not be ZERO.");        PdfPatternPainter painter = new PdfPatternPainter(writer, color);        painter.setWidth(width);        painter.setHeight(height);        painter.setXStep(xstep);        painter.setYStep(ystep);        writer.addSimplePattern(painter);        return painter;    }        /**     * Create a new uncolored tiling pattern.     * Variables xstep and ystep are set to the same values     * of width and height.     * @param width the width of the pattern     * @param height the height of the pattern     * @param color the default color. Can be <CODE>null</CODE>     * @return the <CODE>PdfPatternPainter</CODE> where the pattern will be created     */    public PdfPatternPainter createPattern(float width, float height, Color color) {        return createPattern(width, height, width, height, color);    }        /**     * Creates a new template.     * <P>     * Creates a new template that is nothing more than a form XObject. This template can be included     * in this <CODE>PdfContentByte</CODE> or in another template. Templates are only written     * to the output when the document is closed permitting things like showing text in the first page     * that is only defined in the last page.     *     * @param width the bounding box width     * @param height the bounding box height     * @return the templated created     */    public PdfTemplate createTemplate(float width, float height) {        checkWriter();        PdfTemplate template = new PdfTemplate(writer);        template.setWidth(width);        template.setHeight(height);        writer.addDirectTemplateSimple(template);        return template;    }        /**     * Creates a new appearance to be used with form fields.     *     * @param width the bounding box width     * @param height the bounding box height     * @return the appearance created     */    public PdfAppearance createAppearance(float width, float height) {        checkWriter();        PdfAppearance template = new PdfAppearance(writer);        template.setWidth(width);        template.setHeight(height);        writer.addDirectTemplateSimple(template);        return template;    }        /**     * Adds a template to this content.     *     * @param template the template     * @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     */    public void addTemplate(PdfTemplate template, float a, float b, float c, float d, float e, float f) {        checkWriter();        checkNoPattern(template);        PdfName name = pdf.addTemplateToPage(template);        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);    }        /**     * Adds a template to this content.     *     * @param template the template     * @param x the x location of this template     * @param y the y location of this template     */    public void addTemplate(PdfTemplate template, float x, float y) {        addTemplate(template, 1, 0, 0, 1, x, y);    }        /**     * Changes the current color for filling paths (device dependent colors!).     * <P>     * Sets the color space to <B>DeviceCMYK</B> (or the <B>DefaultCMYK</B> color space),     * and sets the color to use for filling paths.</P>     * <P>     * This method is described in the 'Portable Document Format Reference Manual version 1.3'     * section 8.5.2.1 (page 331).</P>     * <P>     * Following the PDF manual, each operand must be a number between 0 (no ink) and     * 1 (maximum ink). This method however accepts only integers between 0x00 and 0xFF.</P>     *     * @param cyan the intensity of cyan     * @param magenta the intensity of magenta     * @param yellow the intensity of yellow     * @param black the intensity of black     */        public void setCMYKColorFill(int cyan, int magenta, int yellow, int black) {        content.append((float)(cyan & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(magenta & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(yellow & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(black & 0xFF) / 0xFF);        content.append(" k").append_i(separator);    }    /**     * Changes the current color for stroking paths (device dependent colors!).     * <P>     * Sets the color space to <B>DeviceCMYK</B> (or the <B>DefaultCMYK</B> color space),     * and sets the color to use for stroking paths.</P>     * <P>     * This method is described in the 'Portable Document Format Reference Manual version 1.3'     * section 8.5.2.1 (page 331).</P>     * Following the PDF manual, each operand must be a number between 0 (miniumum intensity) and     * 1 (maximum intensity). This method however accepts only integers between 0x00 and 0xFF.     *     * @param cyan the intensity of red     * @param magenta the intensity of green     * @param yellow the intensity of blue     * @param black the intensity of black     */        public void setCMYKColorStroke(int cyan, int magenta, int yellow, int black) {        content.append((float)(cyan & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(magenta & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(yellow & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(black & 0xFF) / 0xFF);        content.append(" K").append_i(separator);    }        /**     * Changes the current color for filling paths (device dependent colors!).     * <P>     * Sets the color space to <B>DeviceRGB</B> (or the <B>DefaultRGB</B> color space),     * and sets the color to use for filling paths.</P>     * <P>     * This method is described in the 'Portable Document Format Reference Manual version 1.3'     * section 8.5.2.1 (page 331).</P>     * <P>     * Following the PDF manual, each operand must be a number between 0 (miniumum intensity) and     * 1 (maximum intensity). This method however accepts only integers between 0x00 and 0xFF.</P>     *     * @param red the intensity of red     * @param green the intensity of green     * @param blue the intensity of blue     */        public void setRGBColorFill(int red, int green, int blue) {        content.append((float)(red & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(green & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(blue & 0xFF) / 0xFF);        content.append(" rg").append_i(separator);    }        /**     * Changes the current color for stroking paths (device dependent colors!).     * <P>     * Sets the color space to <B>DeviceRGB</B> (or the <B>DefaultRGB</B> color space),     * and sets the color to use for stroking paths.</P>     * <P>     * This method is described in the 'Portable Document Format Reference Manual version 1.3'     * section 8.5.2.1 (page 331).</P>     * Following the PDF manual, each operand must be a number between 0 (miniumum intensity) and     * 1 (maximum intensity). This method however accepts only integers between 0x00 and 0xFF.     *     * @param red the intensity of red     * @param green the intensity of green     * @param blue the intensity of blue     */        public void setRGBColorStroke(int red, int green, int blue) {        content.append((float)(red & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(green & 0xFF) / 0xFF);        content.append(' ');        content.append((float)(blue & 0xFF) / 0xFF);        content.append(" RG").append_i(separator);    }        /** Sets the stroke color. <CODE>color</CODE> can be an     * <CODE>ExtendedColor</CODE>.     * @param color the color     */    public void setColorStroke(Color color) {        int type = ExtendedColor.getType(color);        switch (type) {            case ExtendedColor.TYPE_GRAY: {                setGrayStroke(((GrayColor)color).getGray());                break;            }            case ExtendedColor.TYPE_CMYK: {                CMYKColor cmyk = (CMYKColor)color;                setCMYKColorStrokeF(cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack());                break;            }            case ExtendedColor.TYPE_SEPARATION: {                SpotColor spot = (SpotColor)color;                setColorStroke(spot.getPdfSpotColor(), spot.getTint());                break;            }            case ExtendedColor.TYPE_PATTERN: {                PatternColor pat = (PatternColor) color;                setPatternStroke(pat.getPainter());                break;            }            case ExtendedColor.TYPE_SHADING: {                ShadingColor shading = (ShadingColor) color;                setShadingStroke(shading.getPdfShadingPattern());                break;            }            default:                setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());        }    }        /** Sets the fill color. <CODE>color</CODE> can be an     * <CODE>ExtendedColor</CODE>.     * @param color the color     */    public void setColorFill(Color color) {        int type = ExtendedColor.getType(color);        switch (type) {            case ExtendedColor.TYPE_GRAY: {                setGrayFill(((GrayColor)color).getGray());                break;            }            case ExtendedColor.TYPE_CMYK: {                CMYKColor cmyk = (CMYKColor)color;                setCMYKColorFillF(cmyk.getCyan(), cmyk.getMagenta(), cmyk.getYellow(), cmyk.getBlack());                break;            }            case ExtendedColor.TYPE_SEPARATION: {                SpotColor spot = (SpotColor)color;                setColorFill(spot.getPdfSpotColor(), spot.getTint());                break;            }            case ExtendedColor.TYPE_PATTERN: {                PatternColor pat = (PatternColor) color;                setPatternFill(pat.getPainter());                break;            }            case ExtendedColor.TYPE_SHADING: {                ShadingColor shading = (ShadingColor) color;                setShadingFill(shading.getPdfShadingPattern());                break;            }            default:                setRGBColorFill(color.getRed(), color.getGreen(), color.getBlue());        }    }        /** Sets the fill color to a spot color.     * @param sp the spot color     * @param tint the tint for the spot color. 0 is no color and 1     * is 100% color     */    public void setColorFill(PdfSpotColor sp, float tint) {        checkWriter();        state.colorDetails = writer.add(sp);        content.append(state.colorDetails.getColorName().toPdf(null)).append(" cs ").append(tint).append(" scn").append_i(separator);    }        /** Sets the stroke color to a spot color.     * @param sp the spot color     * @param tint the tint for the spot color. 0 is no color and 1     * is 100% color     */    public void setColorStroke(PdfSpotColor sp, float tint) {        checkWriter();        state.colorDetails = writer.add(sp);        content.append(state.colorDetails.getColorName().toPdf(null)).append(" CS ").append(tint).append(" SCN").append_i(separator);    }        /** Sets the fill color to a pattern. The pattern can be     * colored or uncolored.     * @param p the pattern     */    public void setPatternFill(PdfPatternPainter p) {        if (p.isStencil()) {            setPatternFill(p, p.getDefaultColor());            return;        }        checkWriter();        PdfName name = pdf.addPatternToPage(p);        content.append(PdfName.PATTERN.toPdf(null)).append(" cs ").append(name.toPdf(null)).append(" scn").append_i(separator);    }        /** Outputs the color values to the content.     * @param color The color     * @param tint the tint if it is a spot color, ignored otherwise     */    void outputColorNumbers(Color color, float tint) {        int type = ExtendedColor.getType(color);        switch (type) {            case ExtendedColor.TYPE_RGB:                content.append((float)(color.getRed()) / 0xFF);                content.append(' ');                content.append((float)(color.getGreen()) / 0xFF);                content.append(' ');                content.append((float)(color.getBlue()) / 0xFF);                break;            case ExtendedColor.TYPE_GRAY:                content.append(((GrayColor)color).getGray());                break;            case ExtendedColor.TYPE_CMYK: {                CMYKColor cmyk = (CMYKColor)color;                content.append(cmyk.getCyan()).append(' ').append(cmyk.getMagenta());                content.append(' ').append(cmyk.getYellow()).append(' ').append(cmyk.getBlack());                break;            }            case ExtendedColor.TYPE_SEPARATION:                content.append(tint);                break;            default:                throw new RuntimeException("Invalid color type.");        }    }        /** Sets the fill color to an uncolored pattern.     * @param p the pattern     * @param color the color of the pattern     */    public void setPatternFill(PdfPatternPainter p, Color color) {

⌨️ 快捷键说明

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