Example usage for com.itextpdf.text PageSize A4_LANDSCAPE

List of usage examples for com.itextpdf.text PageSize A4_LANDSCAPE

Introduction

In this page you can find the example usage for com.itextpdf.text PageSize A4_LANDSCAPE.

Prototype

Rectangle A4_LANDSCAPE

To view the source code for com.itextpdf.text PageSize A4_LANDSCAPE.

Click Source Link

Document

This is the a4 format

Usage

From source file:com.cts.ptms.carrier.ups.UPSHTTPClient.java

public String createInvoicePDF(String imagePath, String OUTPUT_FILEPATH)
        throws FileNotFoundException, IOException, DocumentException, InterruptedException, URISyntaxException {

    float currPosition = 0;
    String sFilepath = OUTPUT_FILEPATH;
    Image image = Image.getInstance(imagePath);
    //create a paragraph
    Paragraph paragraph = new Paragraph();
    Document d = new Document(PageSize.A4_LANDSCAPE.rotate());
    PdfWriter w = PdfWriter.getInstance(d, new FileOutputStream(sFilepath));
    d.open();//from  w  w w. ja v a2 s. c  o  m
    PdfContentByte cb = w.getDirectContent();
    ByteArrayOutputStream stampedBuffer;
    URL resource = this.getClass().getClassLoader().getResource(ShippingConstants.INVOICE_TEMPLATE);
    File file = new File(resource.toURI());
    PdfReader templateReader = new PdfReader(new FileInputStream(file));
    stampedBuffer = new ByteArrayOutputStream();
    PdfStamper stamper = new PdfStamper(templateReader, stampedBuffer);
    stamper.setFormFlattening(true);
    AcroFields form = stamper.getAcroFields();
    float[] columnWidths = { 1f, 1f, 1f, 3f };
    //create PDF table with the given widths
    PdfPTable table = new PdfPTable(columnWidths);
    // form.setField("field1", String.format("Form Text %d", i+1));
    form.setField("OBName", "Ragav");
    form.setField("OBCompany", "Ragav");
    form.setField("OBAddress", "2002 SW Sarazen Cr");
    form.setField("OBCity", "Bentonville");
    form.setField("OBPhone", "1234567890");
    form.setField("STName", "Ragav");
    form.setField("STCompany", "Ragav");
    form.setField("STAddress", "2002 SW Sarazen Cr");
    form.setField("STCity", "Bentonville");
    form.setField("STPhone", "1234567890");
    form.setField("itemNo", "12334535");
    form.setField("itemDesc", "Laundry Bag");
    stamper.close();
    templateReader.close();
    form = null;
    stamper.close();
    templateReader.close();
    PdfReader stampedReader = new PdfReader(stampedBuffer.toByteArray());
    PdfImportedPage page = w.getImportedPage(stampedReader, 1);
    cb.addTemplate(page, 0, currPosition);
    image.scaleAbsoluteHeight(325);
    image.scaleAbsoluteWidth(550);
    image.setRotationDegrees(270);
    image.setAbsolutePosition(450, 20);
    d.add(image);
    d.close();
    w.close();

    return sFilepath;
}