Example usage for com.itextpdf.text Document setMargins

List of usage examples for com.itextpdf.text Document setMargins

Introduction

In this page you can find the example usage for com.itextpdf.text Document setMargins.

Prototype


public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) 

Source Link

Document

Sets the margins.

Usage

From source file:sipl.recursos.GenerarPDFtipomaterial.java

public void generarPDF(String titulo, String imge, Usuario usuario, String dir, String Filex)
        throws BadElementException, IOException {
    FILE = "";// w w  w.  j ava  2 s  .  c o  m
    Titulo = "";
    direc = "";
    imgG = "";
    imgG = imge;
    user = usuario;
    direc += dir;
    Titulo = titulo;
    FILE = Filex;
    try {
        Document document = new Document();
        FileOutputStream file = new FileOutputStream(dir + "PDF//" + FILE);
        PdfWriter.getInstance(document, file);
        document.open();
        document.setMargins(10, 10, 10, 10);
        addMetaData(document);
        addTitlePage(document);
        addContent(document);
        document.close();
    } catch (FileNotFoundException | DocumentException e) {
    }
    try {
        con.Close_DB();
    } catch (SQLException e) {
        System.out.print("No cerr");
    }
}

From source file:storehausimport.SaveToPdf.java

public boolean save(String inputFilePath, String outputFilePath) throws Exception {
    if (outputFilePath.isEmpty()) {
        throw new Exception("Trkst parametrs outputFilePath");
    }//from  w ww .  ja v  a  2 s  . co m
    if (inputFilePath.isEmpty()) {
        throw new Exception("Trkst parametrs inputFilePath");
    }
    File inputFile = new File(inputFilePath);
    Document pdfDoc = new Document();
    try {
        PdfWriter writer = PdfWriter.getInstance(pdfDoc, new FileOutputStream(outputFilePath));
        pdfDoc.open();
        pdfDoc.setMarginMirroring(true);
        pdfDoc.setMargins(36, 72, 108, 180);
        pdfDoc.topMargin();

        BaseFont helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1257, BaseFont.NOT_EMBEDDED);
        Font normal_font = new Font(helvetica, 10, Font.NORMAL);
        Font bold_font = new Font();
        bold_font.setStyle(Font.BOLD);
        bold_font.setSize(10);
        pdfDoc.add(new Paragraph("\n"));
        if (inputFile.exists()) {
            iStream = new FileInputStream(inputFile);
            in = new DataInputStream(iStream);
            is = new InputStreamReader(in);
            br = new BufferedReader(is);
            String strLine;
            while ((strLine = br.readLine()) != null) {
                Paragraph para = new Paragraph(strLine + "\n", normal_font);
                para.setAlignment(Element.ALIGN_LEFT);
                pdfDoc.add(para);
            }
        } else {
            pdfDoc.close();
            throw new Exception("Trkst parametrs inputFilePath");
        }
        pdfDoc.close();
    } catch (Exception ex) {
        throw new Exception(ex);
    }
    return true;
}

From source file:Utility.PDFDemo.java

public void cretePDF(String name, String rpor) throws FileNotFoundException {

    try {/*w  w w  . j  ava  2s.c  o  m*/

        //Create document for pdf
        Document doc = new Document();

        //PDF writer to write into document
        PdfWriter docwriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        try {
            // //file path
            //String path = "docs/" + name;
            docwriter = PdfWriter.getInstance(doc, new FileOutputStream(rpor + ".pdf"));
        } catch (DocumentException ex) {
            Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
        }

        //document header attributes
        doc.addAuthor("CHED CU");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("Grant Monitor");
        doc.addTitle(rpor);
        doc.setPageSize(PageSize.A4.rotate()); //This sets page size to A4 and orientation to Landscape
        //doc.setPageSize(PageSize.A4);
        doc.setMargins(30f, 30f, 20f, 20f);

        //open document
        doc.open();

        //Creating a paragraphs and chunks
        Paragraph pp = new Paragraph("Cocoa Health And Extension", forTitle);
        pp.setAlignment(Element.ALIGN_CENTER);

        Paragraph palaglapgh = new Paragraph("(Cocobod)", bfBold12);
        palaglapgh.setAlignment(Element.ALIGN_CENTER);

        Chunk chk = new Chunk("From GIS Office, Accra", bfBold12);
        chk.setUnderline(.1f, -2f); // 0.1 thickness and -2 position
        Paragraph underText = new Paragraph(chk);
        underText.setAlignment(Element.ALIGN_CENTER);

        Chunk chuk1 = new Chunk("Lot No:", bfBold12);
        chuk1.setUnderline(.1f, -2f);
        Chunk chuk2 = new Chunk(name, bfBold12);

        Paragraph regionText = new Paragraph(rpor, bfBold12);
        regionText.setAlignment(Element.ALIGN_CENTER);
        String rporx = "";
        //            ResultSet dir = manager.PDFdemos(name);
        //            try {
        //                if (dir.next()) {
        //                    rporx = dir.getString(12);
        //
        //                }
        //            } catch (SQLException ex) {
        //                Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
        //            }

        Paragraph regionTexts = new Paragraph(rporx, bfBold12);
        regionText.setAlignment(Element.ALIGN_CENTER);
        //add the PDF table to the paragraph
        //palaglapgh.add(table);
        //Table Generation block
        regionText.add(reports());

        //SECTION TO ADD ELEMENTS TO PDF
        // add the paragraph to the document
        doc.add(pp);
        //doc.add(Chunk.NEWLINE);       //Adds a new blank line
        doc.add(palaglapgh);
        doc.add(underText);

        doc.add(chuk1);
        doc.add(chuk2);

        //Current Date and time insertion
        Paragraph newDate = new Paragraph(new Date().toString(), bf12);
        newDate.setAlignment(Element.ALIGN_RIGHT);
        doc.add(newDate);
        doc.add(regionTexts);
        doc.add(regionText);

        //close the document
        doc.close();

        //close the writer
        docwriter.close();

    } catch (DocumentException ex) {
        Logger.getLogger(PDFDemo.class.getName()).log(Level.SEVERE, null, ex);
    }

}