use of com.itextpdf.layout.Document in project jExifToolGUI by hvdwolf.
the class ExportToPDF method WriteToPDF.
/**
* This method writes the pdf and is called from the CompareImagesWindow for the there displayed info
* @param allMetadata
*/
public static void WriteToPDF(List<String[]> allMetadata) {
List<String[]> imageMetadata = new ArrayList<String[]>();
File[] files = MyVariables.getLoadedFiles();
int[] selectedIndices = MyVariables.getSelectedFilenamesIndices();
File tmpfile;
String filename;
String pdfnamepath = "";
Document doc = null;
String producedDocs = "";
boolean isWindows = Utils.isOsFromMicrosoft();
for (int index : selectedIndices) {
// First get the data belonging to this file (index)
for (String[] row : allMetadata) {
if (Integer.valueOf(row[1]) == index) {
imageMetadata.add(row);
logger.trace("index {} rowdata {}", index, Arrays.toString(row));
}
}
filename = files[index].getName();
tmpfile = files[index];
pdfnamepath = tmpfile.getParent() + File.separator + Utils.getFileNameWithoutExtension(filename) + ".pdf";
logger.debug("pdfnamepath {}", pdfnamepath);
try {
PdfWriter writer = new PdfWriter(pdfnamepath);
PdfDocument pdfDoc = new PdfDocument(writer);
doc = new Document(pdfDoc);
// Creating the top table
doc.add(topTable(tmpfile));
Paragraph paragraph1 = new Paragraph("\n\n" + ResourceBundle.getBundle("translations/program_strings").getString("exppdf.metadata") + " " + filename);
doc.add(paragraph1);
// Now writing the metadata table
doc.add(fillMetadataTable(imageMetadata));
doc.close();
producedDocs += pdfnamepath + "<br>";
} catch (FileNotFoundException e) {
logger.error("pdf file not found error {}", e);
e.printStackTrace();
doc.close();
}
MyVariables.setpdfDocs(producedDocs);
logger.debug("producedDocs {}", producedDocs);
}
}
use of com.itextpdf.layout.Document in project commons by mosip.
the class PDFGeneratorImpl method mergePDF.
/*
* (non-Javadoc)
*
* @see
* io.mosip.kernel.core.pdfgenerator.spi.PDFGenerator#mergePDF(java.util.List)
*/
@Override
public byte[] mergePDF(List<URL> pdfFiles) throws IOException {
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
com.itextpdf.text.Document document = new com.itextpdf.text.Document();
PdfCopy pdfCopy = new PdfCopy(document, byteArrayOutputStream);
document.open();
for (URL file : pdfFiles) {
PdfReader reader = new PdfReader(file);
pdfCopy.addDocument(reader);
pdfCopy.freeReader(reader);
reader.close();
}
document.close();
return byteArrayOutputStream.toByteArray();
} catch (IOException | DocumentException e) {
throw new PDFGeneratorException(PDFGeneratorExceptionCodeConstant.PDF_EXCEPTION.getErrorCode(), e.getMessage());
}
}
use of com.itextpdf.layout.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 InterruptedException, ExecutionException, IOException, ImageOpException {
long start_time = System.currentTimeMillis();
// create document object
PdfWriter writer = new PdfWriter(outstream);
PdfDocument pdfdoc = new PdfDocument(writer);
doc = new Document(pdfdoc, PageSize.A4);
logger.debug("PDF: {} doc.open()ed ({}ms)", outstream, (System.currentTimeMillis() - start_time));
// add title page
PDFTitlePage titlepage = new PDFTitlePage(job_info);
titlepage.createPage(doc);
// add pages
NumRange pgs = job_info.getPages();
for (int p : pgs) {
// start new page
doc.add(new AreaBreak());
logger.debug("PDF: adding Image {} to {}", p, outstream);
// copy request and set page number (as new Parameter)
DigilibRequest pageRequest = new DigilibRequest(dlConfig, job_info);
pageRequest.put("pn", new Parameter("pn", p, p));
// create ImageJobInformation
ImageJobDescription iji = ImageJobDescription.getRawInstance(pageRequest, job_info.getDlConfig());
iji.prepareScaleParams();
addImage(doc, iji);
logger.debug("PDF: done adding Image {} to {}", p, outstream);
}
logger.debug("PDF: done adding all Images to {}", outstream);
doc.close();
logger.debug("PDF: {} doc.close() ({}ms)", outstream, (System.currentTimeMillis() - start_time));
writer.flush();
writer.close();
return outstream;
}
use of com.itextpdf.layout.Document in project ComponentManagement by Bac3Phi.
the class InventoriesReportController method printData.
public void printData() {
DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle("BÁO CÁO HÀNG TỒN");
File defaultDirectory = new File("c:/");
chooser.setInitialDirectory(defaultDirectory);
File selectedDirectory = chooser.showDialog(Main.window);
try {
PdfWriter writer;
writer = new PdfWriter(selectedDirectory.getAbsolutePath() + "/BaoCaoThuChi_Thang" + cbbMonth.getSelectionModel().getSelectedItem() + "_2018.pdf");
// Creating a PdfDocument
PdfDocument pdfDoc = new PdfDocument(writer);
// Adding a new page
pdfDoc.addNewPage();
// Creating a Document
Document document = new Document(pdfDoc);
addTitlePage(document);
addDate(document);
addInfo(document);
addContent(document);
// Closing the document
document.close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.itextpdf.layout.Document in project ComponentManagement by Bac3Phi.
the class ReportInventoriesController method printData.
public void printData() {
DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle("BÁO CÁO HÀNG TỒN");
File defaultDirectory = new File("c:/");
chooser.setInitialDirectory(defaultDirectory);
File selectedDirectory = chooser.showDialog(Main.window);
try {
PdfWriter writer;
writer = new PdfWriter(selectedDirectory.getAbsolutePath() + "/BaoCaoHangTon_Thang" + cbbMonth.getSelectionModel().getSelectedItem() + "_2018.pdf");
// Creating a PdfDocument
PdfDocument pdfDoc = new PdfDocument(writer);
// Adding a new page
pdfDoc.addNewPage();
// Creating a Document
Document document = new Document(pdfDoc);
addTitlePage(document);
addDate(document);
addInfo(document);
addContent(document);
// Closing the document
document.close();
SmileNotification.creatingNotification("Thông Báo", "Xuất File thành công!!", NotificationType.SUCCESS);
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations