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

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

Introduction

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

Prototype

public void restoreState() 

Source Link

Document

Restores the graphic state.

Usage

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

private static void drawLine2(PdfContentByte contentByte) {
    contentByte.saveState();//from  w w  w  .j a  va 2s . co  m
    contentByte.moveTo(45, 35);
    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();/*  w w w.j  ava 2s.  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

@Override
public void apply(final PdfReader reader, final PdfStamper outputPdf) throws Exception {
    for (int pageNumber = 1; pageNumber <= reader.getNumberOfPages(); pageNumber++) {
        final PdfContentByte overContent = outputPdf.getOverContent(pageNumber);

        applyTextTransparency(overContent);

        addTextToPage(reader.getPageSizeWithRotation(pageNumber), overContent, watermarkText);

        overContent.restoreState();
    }//from  w  w  w.  jav  a  2  s  .  co  m
}

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

License:Open Source License

@Override
public void resetCanvas(PdfContentByte canvas) {
    if (needRestore) {
        canvas.restoreState();
        needRestore = false;/*from  w w  w  . j av a2 s . c om*/
    }
    if (getLayerName() != null) {
        canvas.endLayer();
    }
}

From source file:ConexionBD.CreaPrefichaPDF.java

public static void drawRectangle(PdfContentByte content, float x, float y, float width, float height) {
    content.saveState();//from  w ww .j  av  a 2 s . c o m
    PdfGState state = new PdfGState();
    content.setGState(state);
    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();//w  w  w .j  a  va  2  s.  c om
    PdfGState state = new PdfGState();
    content.setGState(state);
    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();/*from  www . j  a  v a 2  s .  c o m*/
    PdfGState state = new PdfGState();
    content.setGState(state);
    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();/*  w  w w .  j a v  a2s .  c  om*/
    cb.beginText();
    cb.moveText(x, y);
    cb.setFontAndSize(bf, 12);
    cb.showText(text);
    cb.endText();
    cb.restoreState();

}

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();/*from   ww  w .  j av a2  s  .c o  m*/
    PdfGState gs1 = new PdfGState();
    gs1.setFillOpacity(0.5f);
    cb.setGState(gs1);
    pictureCircles(document.leftMargin(), 350, cb);
    cb.restoreState();

    cb.resetRGBColorFill();
}

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

License:Open Source License

/**
 * Prints 3 circles in different colors that intersect with eachother.
 * @param x/* ww w  .  j a v  a  2 s  .  co  m*/
 * @param y
 * @param cb
 * @throws Exception
 */
public void pictureCircles(float x, float y, PdfContentByte cb) throws Exception {

    cb.saveState();
    PdfGState gs1 = new PdfGState();
    gs1.setFillOpacity(1.0f);
    cb.setGState(gs1);
    cb.setColorFill(new BaseColor(Color.red));
    cb.circle(x + 70, y + 70, 50);
    cb.fill();
    cb.restoreState();

    cb.setColorFill(new BaseColor(Color.yellow));
    cb.circle(x + 100, y + 130, 50);
    cb.fill();
    cb.setColorFill(new BaseColor(Color.blue));
    cb.circle(x + 130, y + 70, 50);
    cb.fill();
}