Package com.itextpdf.text.pdf

Examples of com.itextpdf.text.pdf.PdfContentByte


            edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
            edgeElem.setAttribute("fill", "none");
            svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem);
        } else if (renderTarget instanceof PDFTarget) {
            PDFTarget pdfTarget = (PDFTarget) renderTarget;
            PdfContentByte cb = pdfTarget.getContentByte();
            cb.moveTo(x1, -y1);
            cb.curveTo(v1.x, -v1.y, v2.x, -v2.y, x2, -y2);
            cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
            cb.setLineWidth(thickness);
            if (color.getAlpha() < 255) {
                cb.saveState();
                float alpha = color.getAlpha() / 255f;
                PdfGState gState = new PdfGState();
                gState.setStrokeOpacity(alpha);
                cb.setGState(gState);
            }
            cb.stroke();
            if (color.getAlpha() < 255) {
                cb.restoreState();
            }
        }
    }
View Full Code Here


            edgeElem.setAttribute("stroke-opacity", (color.getAlpha() / 255f) + "");
            edgeElem.setAttribute("fill", "none");
            svgTarget.getTopElement(SVGTarget.TOP_EDGES).appendChild(edgeElem);
        } else if (renderTarget instanceof PDFTarget) {
            PDFTarget pdfTarget = (PDFTarget) renderTarget;
            PdfContentByte cb = pdfTarget.getContentByte();
            cb.moveTo(x1, -y1);
            cb.lineTo(x2, -y2);
            cb.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());
            cb.setLineWidth(thickness);
            if (color.getAlpha() < 255) {
                cb.saveState();
                float alpha = color.getAlpha() / 255f;
                PdfGState gState = new PdfGState();
                gState.setStrokeOpacity(alpha);
                cb.setGState(gState);
            }
            cb.stroke();
            if (color.getAlpha() < 255) {
                cb.restoreState();
            }
        }
    }
View Full Code Here

            writer = PdfWriter.getInstance(document, fos);
        } catch (DocumentException e) {
            throw new RuntimeException("An error occurred while creating a PdfWriter object.", e);
        }
        document.open();
        PdfContentByte contentByte = writer.getDirectContent();
        Graphics2D g = new PdfGraphics2D(contentByte, (float) bounds.getWidth(), (float) bounds.getHeight(), fontMapper);
        g.translate(-bounds.getX(), -bounds.getY());
        drawable.draw(g);
        g.dispose();
        document.close();
View Full Code Here

           Document doc = new Document();
           try{
             PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(file));
             doc.open();

            PdfContentByte cb = writer.getDirectContent();

            // create a template
            PdfTemplate tp = cb.createTemplate(pw,ph);
            Graphics2D g2 = tp.createGraphicsShapes(pw,ph);

            // scale the template to fit the page
            AffineTransform at = new AffineTransform();
            float s = (float) Math.min(pw/w,ph/h);
            at.scale(s,s);
            g2.setTransform(at);

            // print the image to the template
            // turning off setUseGreekThreshold allows small text to print
            Text.setUseGreekThreshold(false);
            universe.paint(g2);
            Text.setUseGreekThreshold(true);
            g2.dispose();

            // add the template
            cb.addTemplate(tp,20,0);

            // clean up everything
            doc.close();
           } catch (DocumentException e) {
             e.printStackTrace();
View Full Code Here

TOP

Related Classes of com.itextpdf.text.pdf.PdfContentByte

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.