Example usage for com.itextpdf.text.pdf PdfWriter getInstance

List of usage examples for com.itextpdf.text.pdf PdfWriter getInstance

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfWriter getInstance.

Prototype


public static PdfWriter getInstance(final Document document, final OutputStream os) throws DocumentException 

Source Link

Document

Use this method to get an instance of the PdfWriter.

Usage

From source file:com.solidmaps.webapp.report.MapExercitoPdfGenerator.java

License:Open Source License

private String createDocument(Document doc, PdfWriter docWriter)
        throws FileNotFoundException, DocumentException {

    String fileName = "Mapa - " + company.getCnpj() + " - " + mapProduct.getNumTrimester() + " "
            + mapProduct.getYear() + ".pdf";

    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(filePath + fileName));

    // document header attributes
    doc.addAuthor("Solid Maps");
    doc.addCreationDate();//from   w  ww. j ava  2 s  . com
    doc.addProducer();
    doc.addCreator("solidmaps");
    doc.addTitle("Mapa de Produtos Controlados: " + company.getCnpjFormatted());
    doc.setPageSize(PageSize.A4.rotate());

    // open document
    doc.open();

    return fileName;
}

From source file:com.solidmaps.webapp.report.RenovationRequireExercitoPDF.java

private String createDocument(Document doc, PdfWriter docWriter, LicenseEXEntity license)
        throws FileNotFoundException, DocumentException {

    String fileName = "REQUERIMENTO PARA CONCESSO E REVALIDAO DE CERTIFICADO DE REGISTRO "
            + license.getNumRegister() + ".pdf";

    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(filePath + fileName));

    // document header attributes
    doc.addAuthor("EnforceMaps");
    doc.addCreationDate();/*from  w  ww .j  a v  a 2 s .c o m*/
    doc.addProducer();
    doc.addCreator("EnforceMaps");
    doc.addTitle("REQUERIMENTO PARA CONCESSO E REVALIDAO DE CERTIFICADO DE REGISTRO "
            + license.getNumRegister() + ".pdf");
    doc.setPageSize(PageSize.A4);

    // open document
    doc.open();

    return fileName;
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseExercitoPDF.java

private String createDocument(Document doc, PdfWriter docWriter, LicenseEXEntity license)
        throws FileNotFoundException, DocumentException {

    String fileName = "REQUERIMENTO PARA APOSTILAMENTO DE CERTIFICADO DE REGISTRO " + license.getNumRegister()
            + ".pdf";

    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(filePath + fileName));

    // document header attributes
    doc.addAuthor("EnforceMaps");
    doc.addCreationDate();/*www.  ja v  a2  s.  c  o  m*/
    doc.addProducer();
    doc.addCreator("EnforceMaps");
    doc.addTitle(
            "REQUERIMENTO PARA APOSTILAMENTO DE CERTIFICADO DE REGISTRO " + license.getNumRegister() + ".pdf");
    doc.setPageSize(PageSize.A4);

    // open document
    doc.open();

    return fileName;
}

From source file:com.solidmaps.webapp.report.RequerimentAlterLicenseFederalPDF.java

private String createDocument(Document doc, PdfWriter docWriter, LicensePFEntity license)
        throws FileNotFoundException, DocumentException {

    String fileName = "Comunicado de alterao cadastral - Cnpj: " + license.getCompany().getCnpj() + ".pdf";

    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(filePath + fileName));

    // document header attributes
    doc.addAuthor("EnforceMaps");
    doc.addCreationDate();//ww w  .jav  a  2s .  c o  m
    doc.addProducer();
    doc.addCreator("EnforceMaps");
    doc.addTitle("Comunicado de alterao cadastral: ");
    doc.setPageSize(PageSize.A4);

    // open document
    doc.open();

    return fileName;
}

From source file:com.sparksoftsolutions.com.pdfcreator.MainActivity.java

private File generatePDFFromImages(ArrayList<ImageItem> images) {
    Document document = new Document();

    File sdcard = Environment.getExternalStorageDirectory();
    File file = new File(sdcard, generateFileName());

    try {//from www  . j a  v  a  2  s  .  co m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
    } catch (Exception ex) {
        return null;
    }

    // document = new PdfDocument();
    Boolean opened = false;
    for (ImageItem img : images) {

        Bitmap bitmap = BitmapFactory.decodeFile(img.path);

        try {

            Image image = Image.getInstance(img.path);
            document.setPageSize(new Rectangle(image.getWidth(), image.getHeight()));

            if (!opened) {
                document.open();
                opened = true;
            } else
                document.newPage();
            document.add(image);

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    document.close();
    return file;
}

From source file:com.sreekanth.duelist.FirstPdf.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first_pdf);
    try {// w w  w  .  j  a  v a2  s  . c  om
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(yourFile));
        document.open();
        addMetaData(document);
        addTitlePage(document);
        addContent(document);
        document.close();
        Toast.makeText(FirstPdf.this, "First Pdf File Created in download directory", Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.suyati.androidpdf.FirstPDFActivity.java

public void PrintDocument(String dest) throws IOException, java.io.IOException {
    try {/*from   w w  w  .j a va 2s.  co m*/

        //            Document document = new Document();
        Document document = new Document(PageSize.PENGUIN_SMALL_PAPERBACK, 10f, 10f, 100f, 0f);//PENGUIN_SMALL_PAPERBACK used to set the paper size
        PdfWriter.getInstance(document, new FileOutputStream(dest));
        document.open();
        addMetaData(document);
        addTitlePage(document);
        addContent(document);
        document.close();

        File file = new File(dest);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "application/pdf");
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        startActivity(intent);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.swayam.bhasha.engine.io.writers.impl.PDFGenerator.java

License:Apache License

private void makePDFPage(HTMLDocModel htmlDoc, String fileName) throws DocGenerationException {

    Rectangle pageSize = PageSize.A4;

    if (pageDim.height > pageSize.getHeight()) {
        pageSize = new Rectangle(pageDim.width, pageDim.height);
    }/* www  .  j a  v a2 s  . c o  m*/

    Document pdfDoc = new Document(pageSize, MARGINS, MARGINS, MARGINS, MARGINS);

    FileOutputStream pdfStream = null;

    try {
        pdfStream = new FileOutputStream(fileName);

        PdfWriter.getInstance(pdfDoc, pdfStream);

        pdfDoc.addAuthor("Bhasha PDF Generator (Powered by IText)");

        pdfDoc.open();

        List<Para> paraList = htmlDoc.getParaList();

        for (Para para : paraList) {
            pdfDoc.add(getParagraph(para));
        }

        pdfDoc.close();

    } catch (Exception e) {
        throw new DocGenerationException(e);
    } finally {

        if (pdfStream != null) {
            try {
                pdfStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}

From source file:com.swayam.bhasha.engine.io.writers.impl.PDFImageGenerator.java

License:Apache License

private void makePDFPage(HTMLDocModel htmlDoc, String fileName) throws DocGenerationException, IOException {

    BufferedImage image = getImage(pageDim, htmlDoc);

    /*//from  w  ww . j  a  va 2 s  . com
     * ByteArrayOutputStream bos = new ByteArrayOutputStream();
     * 
     * ImageIO.write(image, "JPG", bos);
     * 
     * byte[] imageData = bos.toByteArray();
     * 
     * System.out.println("PDFImageGenerator.makePDFPage() " +
     * imageData.length);
     */

    Rectangle pageSize = PageSize.A4;

    if (image.getHeight() > pageSize.getHeight()) {
        pageSize = new Rectangle(image.getWidth(), image.getHeight());
    }

    Document pdfDoc = new Document(pageSize, MARGINS, MARGINS, MARGINS, MARGINS);

    FileOutputStream pdfStream = null;

    try {
        pdfStream = new FileOutputStream(fileName);

        PdfWriter pdfWriter = PdfWriter.getInstance(pdfDoc, pdfStream);

        pdfDoc.addAuthor("Bhasha PDF Generator (Powered by IText)");

        pdfDoc.open();

        PdfContentByte contentByte = pdfWriter.getDirectContent();

        Image pdfImage = Image.getInstance(image, null);

        pdfImage.setAbsolutePosition(0, 0);
        contentByte.addImage(pdfImage);

    } catch (Exception e) {
        throw new DocGenerationException(e);
    } finally {

        pdfDoc.close();

        if (pdfStream != null) {
            try {
                pdfStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}

From source file:com.systemevent.jsfclass.util.PdfEvento.java

public void imprimirPdf(Evento events) {
    Evento event = events;//from   w ww .j  a  va2s  .  c  om

    //buscarPDF(n);
    try {
        //Generamos el archivo PDF
        String directorioArchivos;
        ServletContext ctx = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
                .getContext();
        directorioArchivos = ctx.getRealPath("\'") + "reports";
        String name = directorioArchivos + "\'document-report.pdf";
        //String name="C:\\Users\\Jose_Gascon\\Documents\\NetBeansProjects\\SystemEvent\\target\\SystemEvent-1.0-SNAPSHOT\\reports\\document-report.pdf";
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(name));
        FormatoPDF encabezado = new FormatoPDF("");
        Paragraph parrafo, datos, datos1;
        int i;

        // indicamos que objecto manejara los eventos al escribir el Pdf
        writer.setPageEvent(encabezado);

        document.open();
        document.addAuthor("Erick Ramirez");
        document.addTitle("Reporte");

        //Creamos una cantidad significativa de paginas para probar el encabezado

        //for (i = 0; i < 4; i++) {
        parrafo = new Paragraph("Presupuesto de Evento");
        parrafo.setAlignment(Element.ALIGN_CENTER);

        document.add(parrafo);
        //  document.newPage();
        //}

        datos = new Paragraph("Ubicacion: " + event.getUbicacion());
        datos1 = new Paragraph("Pais: " + event.getCodigoPais().getNombre());
        datos.setAlignment(Element.ALIGN_RIGHT);
        datos1.setAlignment(Element.ALIGN_RIGHT);
        document.add(datos1);
        document.add(datos);
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));
        document.add(new Paragraph(""));
        //              PdfPTable table = new PdfPTable(2);
        //              
        //              table.addCell("Cliente: ");
        //              table.addCell(event.getIdCliente().getNombre());
        //              
        //              table.addCell("Descripcion del Evento: ");
        //              table.addCell(event.getDescripcion());
        //              
        //              document.add(table);

        document.add(Tabla_compleja());

        document.close();
        //----------------------------
        //Abrimos el archivo PDF
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
        response.setContentType("application/pdf");
        response.setHeader("Content-disposition", "inline=filename=" + name);
        try {
            response.getOutputStream().write(Util.getBytesFromFile(new File(name)));
            response.getOutputStream().flush();
            response.getOutputStream().close();
            context.responseComplete();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}