Example usage for com.itextpdf.text.pdf PdfContentByte saveState

List of usage examples for com.itextpdf.text.pdf PdfContentByte saveState

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte saveState.

Prototype

public void saveState() 

Source Link

Document

Saves the graphic state.

Usage

From source file:com.devox.GUI.PDF.ExportarAPDF.java

private static void drawLine2(PdfContentByte contentByte) {
    contentByte.saveState();
    contentByte.moveTo(45, 35);//from   w w  w. j  ava  2  s. c o m
    contentByte.lineTo(795, 35);
    contentByte.moveTo(45, 550);
    contentByte.lineTo(795, 550);
    contentByte.setLineWidth(3);
    contentByte.setColorStroke(new BaseColor(252, 204, 41));
    contentByte.stroke();
    contentByte.restoreState();

}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

@Override
protected void run(AbstractResult ret) throws Exception {
    Map<String, String> i18n = (Map) LightUtil.parseJson(getStr("i18n", "{}"));
    ThreadHelper.set("_i18n_", i18n);

    Map rpt = getRpt();//from w  w w.ja  va2  s . c  o  m

    File temp = File.createTempFile("tmp", ".pdf");

    String name = MapUtil.getStr(rpt, "title", "No-Name");
    HttpServletResponse resp = Upload.getUpload().getResponse();
    resp.setHeader("Content-Disposition", "attachment;filename=\"report.pdf\"");
    resp.setContentType("application/pdf");
    LightUtil.doCache(resp);
    createPdf(rpt, i18n, temp);

    FileInputStream is = new FileInputStream(temp);
    PdfReader reader = new PdfReader(is);
    int pages = reader.getNumberOfPages();
    File temp2 = File.createTempFile("pdf", ".pdf");

    OutputStream out = new FileOutputStream(temp2);
    PdfStamper stamp = new PdfStamper(reader, out);
    for (int i = 1; i <= pages; i++) {
        PdfContentByte c = stamp.getOverContent(i);
        Rectangle ps = reader.getPageSize(i);
        ThreadHelper.set("pageNumber", i);
        ThreadHelper.set("pageCount", pages);
        c.saveState();

        List<Map> items = (List) rpt.get("overlays");
        if (items != null) {
            for (Map item : items) {
                getDirectContent(c, ps, item);
            }
        }

        c.restoreState();
    }
    stamp.close();

    ReportFile df = new ReportFile();
    df.setOwnerId(getSession().getUserId());
    df.setName(name);
    df.setCreateTime(LightUtil.longDate());
    ExternalFile.newExternalFile(getDs(), getFs(), df.getFile(), temp2);
    getDs().insertBean(df);

    temp.delete();
    temp2.delete();

    Map m = new HashMap();
    m.put("externalId", df.getFile().getExternalId());
    ret.setResult(m);
}

From source file:com.qmetric.document.watermark.strategy.MessageWatermarkStrategy.java

License:Open Source License

private void applyTextTransparency(final PdfContentByte overContent) {
    // Make transparent - see http://itext-general.2136553.n4.nabble.com/Insert-transparent-Text-td2158904.html
    final PdfGState gstate = new PdfGState();
    gstate.setFillOpacity(OPACITY);//from   w w  w  .j a  v a  2s  .c om
    gstate.setStrokeOpacity(OPACITY);

    overContent.saveState();
    overContent.setGState(gstate);
}

From source file:com.vectorprint.report.itext.style.stylers.AdvancedImpl.java

License:Open Source License

/**
 * get a canvas for drawing, prepared according to settings
 *
 * @see #draw(com.itextpdf.text.Rectangle, java.lang.String) 
 * @return//from  w w  w  .jav  a  2 s  .co  m
 */
protected final PdfContentByte getPreparedCanvas(float opacity) {
    needRestore = false;
    PdfContentByte canvas = (tableForeground != null) ? tableForeground
            : (isBg()) ? getWriter().getDirectContentUnder() : getWriter().getDirectContent();
    String layerName = getLayerName();
    BLENDMODE blend = getBlend();
    if (getWriter().getPDFXConformance() == PdfWriter.PDFX1A2001) {
        // check blend, opacity, layers
        if (!PdfGState.BM_NORMAL.equals(blend.getBlend())
                && !PdfGState.BM_COMPATIBLE.equals(blend.getBlend())) {
            throw new VectorPrintRuntimeException("blend not supported in PDF/X-1a: " + blend);
        }
        if (layerName != null) {
            throw new VectorPrintRuntimeException("layers not supported in PDF/X-1a: " + layerName);
        }
        if (opacity < 1) {
            throw new VectorPrintRuntimeException("opacity not supported in PDF/X-1a: " + opacity);
        }
    }
    if (layerName != null) {
        layerManager.startLayerInGroup(layerName, canvas);
    }
    //                pgs.setAlphaIsShape(true);
    if (opacity <= 1) {
        //                        PdfShading shading = PdfShading.simpleAxial(getWriter(), 0, 0, getDocument().right() - getDocument().getPageSize().getWidth() * 0.6f, getDocument().top() - getDocument().getPageSize().getHeight() * 0.6f, Color.green, Color.orange,true,true);
        //                        canvas.paintShading(shading);
        canvas.saveState();
        needRestore = true;
        PdfGState pgs = new PdfGState();
        pgs.setFillOpacity(opacity);
        pgs.setStrokeOpacity(opacity);
        canvas.setGState(pgs);
    }
    if (!BLENDMODE.NORMAL.equals(blend)) {
        if (!needRestore) {
            canvas.saveState();
            needRestore = true;
        }
        PdfGState pgs = new PdfGState();
        pgs.setBlendMode(blend.getBlend());
        canvas.setGState(pgs);
    }
    if (getTransform() != null && !(this instanceof Image)) {
        canvas.transform(new AffineTransform(getTransform()));
    }
    return canvas;
}

From source file:ConexionBD.CreaPrefichaPDF.java

public static void drawRectangle(PdfContentByte content, float x, float y, float width, float height) {
    content.saveState();
    PdfGState state = new PdfGState();
    content.setGState(state);/*w w  w  .  ja  v  a 2  s .co  m*/
    content.setRGBColorFill(232, 232, 232);
    content.setColorStroke(BaseColor.BLUE);
    content.setLineWidth((float) .5);
    content.rectangle(x, y, width, height);
    content.fillStroke();
    content.restoreState();
}

From source file:ConexionBD.CreaPrefichaPDF.java

public static void drawRectangleSC(PdfContentByte content, float x, float y, float width, float height) {
    content.saveState();
    PdfGState state = new PdfGState();
    content.setGState(state);//  ww  w  .j  av a 2 s  . c om
    content.setRGBColorFill(0xFF, 0xFF, 0xFA);
    content.setColorStroke(BaseColor.BLUE);
    content.setLineWidth((float) .5);
    content.rectangle(x, y, width, height);
    content.fillStroke();
    content.restoreState();
}

From source file:ConexionBD.CreaPrefichaPDF.java

public static void drawRectangleText(PdfContentByte content, float x, float y, float width, float height) {
    content.saveState();
    PdfGState state = new PdfGState();
    content.setGState(state);/*from  w ww  .  j  av a2s . c o m*/
    content.setRGBColorFill(0, 230, 255);
    content.setColorStroke(BaseColor.BLUE);
    content.setLineWidth((float) .5);
    content.rectangle(x, y, width, height);
    content.fillStroke();
    content.restoreState();
}

From source file:Controlador.ControladorCrearPase.java

private static void absText(PdfWriter writer, String text, int x, int y) throws DocumentException, IOException {

    PdfContentByte cb = writer.getDirectContent();
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    cb.saveState();
    cb.beginText();//from   ww w.  j  a  v  a 2 s  .com
    cb.moveText(x, y);
    cb.setFontAndSize(bf, 12);
    cb.showText(text);
    cb.endText();
    cb.restoreState();

}

From source file:de.drippinger.cytricHelper.CytricHelper.java

License:Open Source License

public void manipulatePdf(String sourceFile, String expenseID) throws IOException, DocumentException {
    PdfReader reader = new PdfReader(sourceFile);
    PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(getOutputName(sourceFile)));

    PdfContentByte over = stamper.getOverContent(1);
    Phrase p = new Phrase(String.format("Cytric ID: %s", expenseID));
    ColumnText.showTextAligned(over, Element.ALIGN_CENTER, p, 500, reader.getPageSize(1).getHeight() - 30, 0);
    over.saveState();

    stamper.close();/* ww  w .  j  av  a  2 s  .  c o  m*/
    reader.close();
}

From source file:edu.cornell.mannlib.vitro.webapp.visualization.visutils.PDFDocument.java

License:Open Source License

private void createTransparencyShapes(Document document, PdfWriter writer) throws Exception {
    PdfContentByte cb = writer.getDirectContent();

    pictureBackdrop(document.leftMargin(), 350, cb);
    cb.saveState();
    PdfGState gs1 = new PdfGState();
    gs1.setFillOpacity(0.5f);//ww w  . j  a va  2  s  .  c  o m
    cb.setGState(gs1);
    pictureCircles(document.leftMargin(), 350, cb);
    cb.restoreState();

    cb.resetRGBColorFill();
}