Example usage for org.apache.pdfbox.pdmodel PDPageContentStream PDPageContentStream

List of usage examples for org.apache.pdfbox.pdmodel PDPageContentStream PDPageContentStream

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel PDPageContentStream PDPageContentStream.

Prototype

public PDPageContentStream(PDDocument document, PDPage sourcePage, AppendMode appendContent, boolean compress)
        throws IOException 

Source Link

Document

Create a new PDPage content stream.

Usage

From source file:org.fit.cssbox.render.PDFRenderer.java

License:Open Source License

/**
 * Changes recent page using PDFBox//from  w  ww. j  av  a2  s  .c om
 */
private int changeRecentPageToPDFBox(int i) {

    page = (PDPage) doc.getDocumentCatalog().getPages().get(i);

    try {
        content.close();
        content = new PDPageContentStream(doc, page, true, true);
    } catch (IOException e) {
        e.printStackTrace();
        return -1;
    }
    return 0;
}

From source file:org.nmrfx.processor.gui.graphicsio.PDFWriter.java

License:Open Source License

public void create(boolean landScape, double width, double height, String fileName) throws GraphicsIOException {
    // the document
    this.landScape = landScape;
    this.fileName = fileName;
    doc = new PDDocument();
    try {//from  w  ww . j a v  a  2 s  . co  m
        PDPage page = new PDPage(PDRectangle.LETTER);
        doc.addPage(page);
        PDRectangle pageSize = page.getMediaBox();
        pageWidth = pageSize.getWidth();
        pageHeight = pageSize.getHeight();
        contentStream = new PDPageContentStream(doc, page, false, false);
        // add the rotation using the current transformation matrix
        // including a translation of pageWidth to use the lower left corner as 0,0 reference
        if (landScape) {
            page.setRotation(90);
            contentStream.transform(new Matrix(0, 1, -1, 0, pageWidth, 0));
        }
    } catch (IOException ioE) {
        throw new GraphicsIOException(ioE.getMessage());
    }
}

From source file:pdf.DailyReportPDF.java

public String createDailyReport() throws IOException {
    PDDocument document = PDDocument.load(template);
    //prva strana
    PDPage page = document.getPage(0);/*  ww  w  . j a v a  2  s  . c  om*/
    contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false);

    this.insertProducts();
    this.dailyReportInfo();
    contentStream.close();
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy.");
    String path = "pdf_docs\\daily_reports\\" + "daily_report_" + dateOfDailyReport.getTime() + ".pdf";
    document.save(path);
    //createDailyReportPNG(path);
    document.close();

    return path;
}

From source file:pdf.NormativPDF.java

public String createNormativ() throws IOException {
    PDDocument document = PDDocument.load(template);
    //prva strana
    PDPage page = document.getPage(0);/*from   w w  w  .j a  va2 s  .co  m*/
    contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false);

    this.insertSupplies();
    this.insertProduct();
    this.normativInfo();
    contentStream.close();
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy.");
    String path = "pdf_docs\\norms\\" + "norm" + "_" + dateNormativ.getTime() + ".pdf";
    document.save(path);
    //createNormativPNG(path);
    document.close();
    return path;

}

From source file:pdf.StockItemsPDF.java

public String createStockItems() throws IOException {
    PDDocument document = PDDocument.load(template);
    //prva strana
    PDPage page = document.getPage(0);//from   ww  w  .  j  a v  a2 s. com
    contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false);

    this.insertProducts();
    this.stockItemsInfo();
    contentStream.close();
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy.");
    String path = "pdf_docs\\stock_items\\" + "stock_item_" + dateOfWriteOff.getTime() + ".pdf";
    document.save(path);
    //createStockItemsPNG(path);
    document.close();

    return path;
}

From source file:pdf.SuppliesListPDF.java

public String createSuppliesList() throws IOException {
    PDDocument document = PDDocument.load(template);
    //prva strana
    PDPage page = document.getPage(0);/* w  w w .ja  v  a  2s. com*/
    contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false);

    this.insertSupplies();
    this.suppliesListInfo();
    contentStream.close();
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy.");
    String path = "pdf_docs\\lager_lists\\" + "supplies_list_" + dateSuppliesList.getTime() + ".pdf";
    document.save(path);
    //createDailyReportPNG(path);
    document.close();
    return path;

}

From source file:pdf.WorkOrderPDF.java

public void createWorkOrder() throws IOException {
    PDDocument document = PDDocument.load(template);
    //prva strana
    PDPage page = document.getPage(0);// w  w w. j a v  a 2s . c  o  m
    contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false);

    this.insertProducts();
    this.insertSupplies();
    this.workOrderInfo();

    document.save("pdf_docs\\work_orders\\" + "work_order_" + numOfWorkOrder.split("\\/")[0] + "_"
            + numOfWorkOrder.split("/")[1] + ".pdf");
    document.close();

}

From source file:pdf.WriteOffMaterialsPDF.java

public void createWriteOffMaterials() throws IOException {
    PDDocument document = PDDocument.load(template);
    //prva strana
    PDPage page = document.getPage(0);/*from   w  w  w  .jav a  2 s . c o  m*/
    contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false);

    this.insertSupplies();
    this.writeOffMaterialsInfo();
    contentStream.close();
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy.");
    String path = "pdf_docs\\write_off_materials\\" + "write_off_materials-" + sdf.format(dateOfWriteOff)
            + ".pdf";
    document.save(path);
    createWriteOffMaterialsPNG(path);
    document.close();

}

From source file:pdf.WriteOffProductsPDF.java

public void createWriteOffProducts() throws IOException {
    PDDocument document = PDDocument.load(template);
    //prva strana
    PDPage page = document.getPage(0);//  w  w  w .  j  ava 2 s. c om
    contentStream = new PDPageContentStream(document, page, PDPageContentStream.AppendMode.PREPEND, false);

    this.insertProducts();
    this.writeOffProductsInfo();
    contentStream.close();
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy.");
    String path = "pdf_docs\\write_off_products\\" + "write_off_products-" + sdf.format(dateOfWriteOff)
            + ".pdf";
    document.save(path);
    createWriteOffProductsPNG(path);
    document.close();

}

From source file:src.view.controller.ContextMenuController.java

/**
 * Bouton de validation de l'ajout de tableau
 *
 * @param docFile//w w w. j  av  a2  s.co  m
 * @return
 */
public static MenuItem validateTable(DocFile docFile) {
    MenuItem validate = new MenuItem(TRANSLATOR.getString("VALIDATE"));
    validate.setOnAction((event) -> {
        try {
            PDDocument document = docFile.getDocument();
            PDPage page = docFile.getCurrentPage();
            PDPageContentStream contentStream = new PDPageContentStream(document, page,
                    PDPageContentStream.AppendMode.APPEND, true);

            TableController tc = new TableController();
            tc.printTable(contentStream, docFile.getTempTable(), true);

            contentStream.close();

            TabDisplayer.refreshOpenedTab();
        } catch (IOException e) {
            System.out.println(e.toString());
        }
    });
    return validate;
}