Search in sources :

Example 21 with Document

use of com.itextpdf.text.Document in project bamboobsc by billchen198318.

the class PersonalReportPdfCommand method createPdf.

private String createPdf(Context context) throws Exception {
    BscReportPropertyUtils.loadData();
    String visionOid = (String) context.get("visionOid");
    VisionVO vision = null;
    BscStructTreeObj treeObj = (BscStructTreeObj) this.getResult(context);
    for (VisionVO visionObj : treeObj.getVisions()) {
        if (visionObj.getOid().equals(visionOid)) {
            vision = visionObj;
        }
    }
    FontFactory.register(BscConstants.PDF_ITEXT_FONT);
    String fileName = UUID.randomUUID().toString() + ".pdf";
    String fileFullPath = Constants.getWorkTmpDir() + "/" + fileName;
    OutputStream os = new FileOutputStream(fileFullPath);
    Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10);
    document.left(100f);
    document.top(150f);
    PdfWriter writer = PdfWriter.getInstance(document, os);
    document.open();
    PdfPTable table = new PdfPTable(MAX_COLSPAN);
    table.setWidthPercentage(100f);
    PdfPTable signTable = new PdfPTable(1);
    signTable.setWidthPercentage(100f);
    this.createHead(table, vision, context);
    this.createBody(table, vision);
    this.createFoot(table, context);
    this.putSignature(signTable, context);
    document.add(table);
    document.add(signTable);
    document.close();
    writer.close();
    os.flush();
    os.close();
    os = null;
    File file = new File(fileFullPath);
    String oid = UploadSupportUtils.create(Constants.getSystem(), UploadTypes.IS_TEMP, false, file, "personal-report.pdf");
    file = null;
    return oid;
}
Also used : PdfWriter(com.itextpdf.text.pdf.PdfWriter) PdfPTable(com.itextpdf.text.pdf.PdfPTable) BscStructTreeObj(com.netsteadfast.greenstep.bsc.model.BscStructTreeObj) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Document(com.itextpdf.text.Document) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) File(java.io.File)

Example 22 with Document

use of com.itextpdf.text.Document in project summer-bean by cn-cerc.

the class ExportPdf method export.

public void export(String message) throws DocumentException, IOException {
    // 清空输出流
    response.reset();
    // 第一步
    Document document = new Document(PageSize.A4.rotate());
    // 第二步
    // PdfWriter.getInstance(pdf, new FileOutputStream("Hello.pdf"));
    ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
    // 第三步
    document.open();
    // 第四步
    document.addAuthor("地藤系统");
    document.addSubject("地藤系统报表文件");
    document.addCreationDate();
    document.add(new Chunk(message));
    // 第五步
    document.close();
    // 第六步
    response.setContentType("application/pdf");
    response.setContentLength(pdfStream.size());
    ServletOutputStream out = response.getOutputStream();
    pdfStream.writeTo(out);
    out.flush();
    response.flushBuffer();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.itextpdf.text.Document) Chunk(com.itextpdf.text.Chunk)

Example 23 with Document

use of com.itextpdf.text.Document in project summer-bean by cn-cerc.

the class Template method getDocument.

public Document getDocument() {
    if (document == null) {
        // document = new Document(PageSize.A4.rotate());
        // 分辨率是72像素/英寸,A4纸的尺寸的图像的像素是595×842
        Rectangle rectangle = createRectangle(pageWidth, pageHeight);
        if (broadwise) {
            rectangle = rectangle.rotate();
        }
        document = new Document(rectangle, marginLeft, marginRight, marginTop, marginBottom);
    }
    return document;
}
Also used : Rectangle(com.itextpdf.text.Rectangle) Document(com.itextpdf.text.Document)

Example 24 with Document

use of com.itextpdf.text.Document in project Java-Matrix-Benchmark by lessthanoptimal.

the class UtilPlotPdf method saveAsPdf.

public static void saveAsPdf(LegendTitle legend, String FILENAME, int width, int height) {
    Document document = new Document(new Rectangle(width, height));
    try {
        FileOutputStream file = new FileOutputStream(FILENAME);
        PdfWriter writer = PdfWriter.getInstance(document, file);
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(width, height);
        Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());
        Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
        legend.draw(g2d, r2d);
        g2d.dispose();
        cb.addTemplate(tp, 0, 0);
        document.close();
        g2d.dispose();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PdfWriter(com.itextpdf.text.pdf.PdfWriter) FileOutputStream(java.io.FileOutputStream) Rectangle(com.itextpdf.text.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte) DefaultFontMapper(com.itextpdf.text.pdf.DefaultFontMapper) Document(com.itextpdf.text.Document) PdfTemplate(com.itextpdf.text.pdf.PdfTemplate) IOException(java.io.IOException)

Example 25 with Document

use of com.itextpdf.text.Document in project opentheso by miledrousset.

the class BaseDeDonnesBean method pdf.

/**
 * permet de generer une document pour pouvoir le telecharger
 * le format c'est pdf
 * @return
 * @throws SQLException
 * @throws Exception
 */
public StreamedContent pdf() throws SQLException, Exception {
    Thesaurus thesaurus = new Thesaurus();
    ExportStatistiques expo = new ExportStatistiques();
    expo.recuperatefils(connect.getPoolConnexion(), theso.getThesaurus().getId_thesaurus(), theso.getThesaurus().getLanguage(), 2);
    Document pdf = new Document(PageSize.LETTER);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer;
    Paragraph para = new Paragraph(expo.getDocument());
    writer = PdfWriter.getInstance(pdf, baos);
    if (!pdf.isOpen()) {
        pdf.open();
    }
    pdf.addTitle("theso");
    pdf.add(para);
    // Adding content to pdf
    pdf.close();
    InputStream stream = new ByteArrayInputStream(baos.toByteArray());
    fileDownload = new DefaultStreamedContent(stream, "application/pdf", "Thésaurus" + thesaurus.getId_thesaurus() + ".pdf");
    return fileDownload;
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) PdfWriter(com.itextpdf.text.pdf.PdfWriter) Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) ByteArrayInputStream(java.io.ByteArrayInputStream) ExportStatistiques(mom.trd.opentheso.core.exports.helper.ExportStatistiques) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(com.itextpdf.text.Document) Paragraph(com.itextpdf.text.Paragraph)

Aggregations

Document (com.itextpdf.text.Document)32 FileOutputStream (java.io.FileOutputStream)25 PdfWriter (com.itextpdf.text.pdf.PdfWriter)22 IOException (java.io.IOException)12 DocumentException (com.itextpdf.text.DocumentException)10 Rectangle (com.itextpdf.text.Rectangle)10 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)10 File (java.io.File)10 Font (com.itextpdf.text.Font)8 Paragraph (com.itextpdf.text.Paragraph)8 PdfTemplate (com.itextpdf.text.pdf.PdfTemplate)6 FileNotFoundException (java.io.FileNotFoundException)6 Graphics2D (java.awt.Graphics2D)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 PdfGraphics2D (com.itextpdf.awt.PdfGraphics2D)4 Chapter (com.itextpdf.text.Chapter)4 PdfPTable (com.itextpdf.text.pdf.PdfPTable)4 OutputStream (java.io.OutputStream)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Date (java.util.Date)4