use of com.itextpdf.text.Document in project digilib by robcast.
the class PDFStreamWorker method renderPDF.
/**
* @throws DocumentException
* @throws InterruptedException
* @throws ExecutionException
* @throws IOException
* @throws ImageOpException
*/
protected OutputStream renderPDF() throws DocumentException, InterruptedException, ExecutionException, IOException, ImageOpException {
// create document object
doc = new Document(PageSize.A4, 0, 0, 0, 0);
PdfWriter docwriter = null;
long start_time = System.currentTimeMillis();
docwriter = PdfWriter.getInstance(doc, outstream);
setPDFProperties(doc);
doc.open();
addTitlePage(doc);
logger.debug("PDF: " + outstream + " doc.open()ed (" + (System.currentTimeMillis() - start_time) + "ms)");
NumRange pgs = job_info.getPages();
for (int p : pgs) {
logger.debug("PDF: adding Image " + p + " to " + outstream);
// set page number
job_info.setValue("pn", p);
// create ImageJobInformation
ImageJobDescription iji = ImageJobDescription.getInstance(job_info, job_info.getDlConfig());
addImage(doc, iji);
logger.debug("PDF: done adding Image " + p + " to " + outstream);
}
logger.debug("PDF: done adding all Images to " + outstream);
doc.close();
logger.debug("PDF: " + outstream + " doc.close() (" + (System.currentTimeMillis() - start_time) + "ms)");
docwriter.flush();
docwriter.close();
return outstream;
}
use of com.itextpdf.text.Document in project saga by timurstrekalov.
the class PdfReporter method writeReportInternal.
@Override
public void writeReportInternal(final File outputFile, final TestRunCoverageStatistics runStats) throws IOException {
try {
document = new Document(PageSize.A4.rotate());
writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
document.open();
addMetaData(runStats);
addContent(runStats);
document.close();
} catch (final Exception e) {
throw new IOException(e);
}
}
use of com.itextpdf.text.Document in project carina by qaprosoft.
the class AbstractPage method savePageAsPdf.
public String savePageAsPdf(boolean scaled) throws IOException, DocumentException {
String pdfName = "";
// Define test screenshot root
String test = TestNamingService.getTestName();
File testRootDir = ReportContext.getTestDir();
File artifactsFolder = ReportContext.getArtifactsFolder();
String fileID = test.replaceAll("\\W+", "_") + "-" + System.currentTimeMillis();
pdfName = fileID + ".pdf";
String fullPdfPath = artifactsFolder.getAbsolutePath() + "/" + pdfName;
// TODO: test this implementation and change back to capture if necessary
Image image = Image.getInstance(testRootDir.getAbsolutePath() + "/" + Screenshot.capture(getDriver(), "", true));
Document document = null;
if (scaled) {
document = new Document(PageSize.A4, 10, 10, 10, 10);
if (image.getHeight() > (document.getPageSize().getHeight() - 20) || image.getScaledWidth() > (document.getPageSize().getWidth() - 20)) {
image.scaleToFit(document.getPageSize().getWidth() - 20, document.getPageSize().getHeight() - 20);
}
} else {
document = new Document(new RectangleReadOnly(image.getScaledWidth(), image.getScaledHeight()));
}
PdfWriter.getInstance(document, new FileOutputStream(fullPdfPath));
document.open();
document.add(image);
document.close();
return fullPdfPath;
}
use of com.itextpdf.text.Document in project mzmine2 by mzmine.
the class ChartExportUtil method writeChartToPDF.
/**
* This method saves a chart as a PDF with given dimensions
*
* @param chart
* @param width
* @param height
* @param fileName is a full path
*/
public static void writeChartToPDF(JFreeChart chart, int width, int height, File fileName) throws Exception {
PdfWriter writer = null;
Document document = new Document(new Rectangle(width, height));
try {
writer = PdfWriter.getInstance(document, new FileOutputStream(fileName));
document.open();
PdfContentByte contentByte = writer.getDirectContent();
PdfTemplate template = contentByte.createTemplate(width, height);
Graphics2D graphics2d = template.createGraphics(width, height, new DefaultFontMapper());
Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, width, height);
chart.draw(graphics2d, rectangle2d);
graphics2d.dispose();
contentByte.addTemplate(template, 0, 0);
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
document.close();
}
}
use of com.itextpdf.text.Document in project bamboobsc by billchen198318.
the class OrganizationReportPdfCommand 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.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, "department-report.pdf");
file = null;
return oid;
}
Aggregations