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;
}
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();
}
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;
}
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();
}
}
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;
}
Aggregations