Search in sources :

Example 61 with Document

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);
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) File(java.io.File)

Example 62 with Document

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());
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) PdfReader(com.itextpdf.text.pdf.PdfReader) IOException(java.io.IOException) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) URL(java.net.URL) PDFGeneratorException(io.mosip.kernel.core.pdfgenerator.exception.PDFGeneratorException) PdfCopy(com.itextpdf.text.pdf.PdfCopy) DocumentException(com.itextpdf.text.DocumentException)

Example 63 with Document

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;
}
Also used : NumRange(digilib.util.NumRange) PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) ImageJobDescription(digilib.image.ImageJobDescription) DigilibRequest(digilib.conf.DigilibRequest) Parameter(digilib.util.Parameter) AreaBreak(com.itextpdf.layout.element.AreaBreak) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument)

Example 64 with Document

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();
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 65 with Document

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();
    }
}
Also used : PdfWriter(com.itextpdf.kernel.pdf.PdfWriter) Document(com.itextpdf.layout.Document) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) File(java.io.File) DirectoryChooser(javafx.stage.DirectoryChooser) PdfDocument(com.itextpdf.kernel.pdf.PdfDocument) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Aggregations

PdfDocument (com.itextpdf.kernel.pdf.PdfDocument)132 Document (com.itextpdf.layout.Document)132 PdfWriter (com.itextpdf.kernel.pdf.PdfWriter)130 Paragraph (com.itextpdf.layout.element.Paragraph)104 PdfFont (com.itextpdf.kernel.font.PdfFont)39 HyphenationConfig (com.itextpdf.layout.hyphenation.HyphenationConfig)31 BufferedReader (java.io.BufferedReader)26 FileReader (java.io.FileReader)26 AreaBreak (com.itextpdf.layout.element.AreaBreak)25 Image (com.itextpdf.layout.element.Image)25 Table (com.itextpdf.layout.element.Table)25 Cell (com.itextpdf.layout.element.Cell)21 List (java.util.List)20 CsvTo2DList (com.itextpdf.highlevel.util.CsvTo2DList)19 File (java.io.File)16 SolidBorder (com.itextpdf.layout.borders.SolidBorder)14 ArrayList (java.util.ArrayList)14 Tab (com.itextpdf.layout.element.Tab)13 Text (com.itextpdf.layout.element.Text)13 Rectangle (com.itextpdf.kernel.geom.Rectangle)12