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:com.ainfosec.macresponse.report.PdfGenerator.java

License:Open Source License

public static void generateReport(String filename, TreeObject rootObject) {
    if ((rootObject == null) || (filename == null)) {
        return;//from w  w  w  . j a va 2 s. com
    }
    try {
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        document.setMargins(20f, 20f, 20f, 20f);
        addMetaData("CASEID", "AUTHOR", document);
        addTitlePage(document);
        //         addTables(document, rootObject);
        addContent(document, rootObject);
        document.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.algoboss.erp.util.report.PDFExporter2.java

License:Apache License

public void export(FacesContext context, DataTable table, String filename, String encodingType)
        throws IOException {
    try {/*from   ww w.j  a va 2 s.com*/
        Document document = new Document();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);

        if (!document.isOpen()) {
            document.open();
        }
        document.setMargins(1f, 1f, 1f, 1f);
        document.setPageSize(PageSize.A4);
        document.add(exportPDFTable(context, table, false, false, true, encodingType));
        document.setMargins(1f, 1f, 1f, 1f);
        document.setPageSize(PageSize.A4);

        document.close();

        //writePDFToResponse(context.getExternalContext(), baos, filename);
        writePDFToResponseNew(context.getExternalContext(), baos, filename);

    } catch (DocumentException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:com.app.gpo.pdf.utils.AbstractITextPdfView.java

License:Open Source License

protected Document newDocument() {

    Document document = new Document();

    Rectangle pageSize = new Rectangle(226, 141);
    //226,7206478
    //141,6984733

    document.setPageSize(pageSize);/*from  w ww  .  j  av  a  2s  .  com*/
    document.setMargins(2, 2, 2, 2);

    return document;

}

From source file:com.atacadao.almoxarifado.model.GerandoPDF.java

public void pdfDeSaida(ArrayList<Equipamento> equipamentos, String solicitante, String autorizante,
        String responsavel, String numeroSaida) {
    Document documento = new Document();

    try {/*  w w w .ja v  a2s . c om*/

        Path path = Paths.get("\\files\\saidas.pdf");

        if (!Files.isDirectory(path.getParent())) {
            Files.createDirectory(path.getParent());
            Files.createFile(path);
        }

        PdfWriter pdf;
        pdf = PdfWriter.getInstance(documento, new FileOutputStream("\\files\\saidas.pdf"));

        documento.open();
        documento.addTitle("SOLICITAO DE EQUIPAMENTOS E PRODUTOS");

        /**
         * Responsavel pelo cabealho do documento
         */
        Image imagem = Image.getInstance("atacadao.jpg");
        imagem.setAlignment(Element.ALIGN_CENTER);
        documento.add(imagem);

        Paragraph titulo = new Paragraph("SOLICITAO DE EQUIPAMENTOS E PRODUTOS", new com.itextpdf.text.Font(
                com.itextpdf.text.Font.FontFamily.UNDEFINED, 16, 0, BaseColor.BLACK));

        titulo.setAlignment(Element.ALIGN_CENTER);
        documento.add(titulo);

        documento.setMargins(0, 0, 18, 0);

        Date datas = new Date();
        Locale local = new Locale("pt", "BR");
        SimpleDateFormat sdf = new SimpleDateFormat("E dd/MM/yyyy", local);

        Paragraph espaco = new Paragraph(
                "\n\nDeclaro para os devidos fins que eu " + solicitante + " recebi na " + sdf.format(datas)
                        + " os equipamentos abaixo relacionados da empresa " + "Atacado dos Pisos por "
                        + autorizante + " e autorizado por " + responsavel + ".\n",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0,
                        BaseColor.BLACK));

        documento.add(espaco);

        documento.add(new Paragraph("\n Numero de registro : " + numeroSaida + "\n\n"));
        /**
         * Responsavel por cria a tabela da sada dos equipamentos
         */
        PdfPTable pdfT = new PdfPTable(4);
        PdfPCell celulas = new PdfPCell(new Paragraph(
                "Relao de equipamentos solicitados para seus devidos fins."
                        + " Favor caso haja devoluo manter o maximo possvel do estado atual dos mesmos. Grato !!!",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 11, 0,
                        BaseColor.GRAY)));
        celulas.setColspan(4);

        PdfPCell patrimonio = new PdfPCell(new Paragraph("PATRIMONIO", new com.itextpdf.text.Font(
                com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE)));
        patrimonio.setBackgroundColor(BaseColor.GRAY);
        patrimonio.setPadding((float) 1);

        PdfPCell Nome = new PdfPCell(new Paragraph("NOME", new com.itextpdf.text.Font(
                com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE)));
        Nome.setBackgroundColor(BaseColor.GRAY);
        Nome.setPadding((float) 1);

        PdfPCell Situacao = new PdfPCell(new Paragraph("SITUAO", new com.itextpdf.text.Font(
                com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE)));
        Situacao.setBackgroundColor(BaseColor.GRAY);
        Situacao.setPadding((float) 1);

        PdfPCell valor = new PdfPCell(new Paragraph("DESTINO", new com.itextpdf.text.Font(
                com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, 0, BaseColor.WHITE)));
        valor.setBackgroundColor(BaseColor.GRAY);
        valor.setPadding((float) 1);

        pdfT.addCell(celulas);
        pdfT.addCell(patrimonio);
        pdfT.addCell(Nome);
        pdfT.addCell(Situacao);
        pdfT.addCell(valor);

        for (Equipamento equipamento : equipamentos) {

            PdfPCell patrimonios = new PdfPCell(
                    new Paragraph(equipamento.getPatrimonio(), new com.itextpdf.text.Font(
                            com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK)));
            patrimonios.setBackgroundColor(BaseColor.WHITE);
            Situacao.setPadding((float) 0.8);
            pdfT.addCell(patrimonios);

            PdfPCell nomes = new PdfPCell(new Paragraph(equipamento.getNome(), new com.itextpdf.text.Font(
                    com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK)));
            nomes.setBackgroundColor(BaseColor.WHITE);
            nomes.setPadding((float) 0.8);
            pdfT.addCell(nomes);

            PdfPCell situacoes = new PdfPCell(
                    new Paragraph(equipamento.getSituacao(), new com.itextpdf.text.Font(
                            com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK)));
            situacoes.setBackgroundColor(BaseColor.WHITE);
            situacoes.setPadding((float) 0.8);
            pdfT.addCell(situacoes);

            PdfPCell valores = new PdfPCell(new Paragraph(equipamento.getCodigo(), new com.itextpdf.text.Font(
                    com.itextpdf.text.Font.FontFamily.UNDEFINED, 10, 0, BaseColor.BLACK)));
            valores.setBackgroundColor(BaseColor.WHITE);
            valores.setPadding((float) 0.8);
            pdfT.addCell(valores);

        }
        documento.add(pdfT);

        /**
         * Cria tabela para assinatura do solicitante e autorizado
         */
        PdfPTable pdfTs = new PdfPTable(5);

        Paragraph sol = new Paragraph("\n\n" + solicitante,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, Font.ITALIC));
        sol.setAlignment(Element.ALIGN_CENTER);
        PdfPCell ass = new PdfPCell(sol);
        ass.setBorder(0);
        ass.setBorderWidthTop(1);
        ass.setColspan(2);

        PdfPCell espacos = new PdfPCell();
        espacos.setBorder(0);

        Paragraph auth = new Paragraph("\n\n" + autorizante,
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.UNDEFINED, 12, Font.ITALIC));
        auth.setAlignment(Element.ALIGN_CENTER);
        PdfPCell ass2 = new PdfPCell(auth);
        ass2.setBorder(0);
        ass2.setBorderWidthTop(1);
        ass2.setColspan(2);

        pdfTs.addCell(ass);
        pdfTs.addCell(espacos);
        pdfTs.addCell(ass2);

        documento.add(new Paragraph("\n\n\n"));
        documento.add(pdfTs);

        documento.close();
        ImpressaoDeDocumentos imprimir = new ImpressaoDeDocumentos("\\files\\saidas.pdf");

        //            Desktop.getDesktop().open(new File("\\files\\saidas.pdf"));

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

From source file:com.atacadao.almoxarifado.model.GerandoPDF.java

public void pdfImpressaoBarraDeCodigo(String codigo) {
    Document documento = new Document(new Rectangle(90, 65));
    documento.setMargins(0, 0, 0, 0);

    PdfWriter pdf;//from  ww  w.j ava  2 s  .co  m

    try {
        pdf = PdfWriter.getInstance(documento, new FileOutputStream("codigodebarras.pdf"));
        documento.open();
        PdfContentByte contB = pdf.getDirectContent();
        Barcode128 barCode = new Barcode128();
        barCode.setCode(codigo);
        barCode.setCodeType(Barcode128.CODE128);

        Image image = barCode.createImageWithBarcode(contB, BaseColor.BLACK, BaseColor.BLACK);
        Paragraph titulo = new Paragraph("ATCADO DOS PISOS\n",
                new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA, 5));
        titulo.setPaddingTop(0);
        titulo.setAlignment(Element.ALIGN_CENTER);

        float scaler = ((documento.getPageSize().getWidth() - documento.leftMargin() - documento.rightMargin()
                - 0) / image.getWidth()) * 60;

        image.scalePercent(scaler);
        image.setPaddingTop(0);
        image.setAlignment(Element.ALIGN_CENTER);

        documento.add(titulo);
        documento.add(image);

        documento.close();

        Desktop.getDesktop().open(new File("codigodebarras.pdf"));

    } catch (DocumentException | FileNotFoundException ex) {
        Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(GerandoPDF.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.bdaum.zoom.email.internal.job.PdfJob.java

License:Open Source License

private Document createDocument() {
    Document document = new Document();
    document.addCreationDate();//from   w ww  . j a v  a 2  s . co  m
    document.addCreator(Constants.APPLICATION_NAME);
    document.addAuthor(System.getProperty("user.name")); //$NON-NLS-1$
    document.setPageSize(format);
    document.setMargins(Math.max(0, leftMargins - horizontalGap / 2),
            Math.max(0, rightMargins - horizontalGap / 2), topMargins, 0);
    document.setMarginMirroring(layout.getFacingPages());
    return document;
}

From source file:com.bdaum.zoom.ui.internal.dialogs.ExhibitionEditDialog.java

License:Open Source License

private static Document createDocument() {
    Document document = new Document();
    document.addCreationDate();/*from  w  w w.j a va 2  s. c  om*/
    document.addCreator(Constants.APPLICATION_NAME);
    document.addAuthor(System.getProperty("user.name")); //$NON-NLS-1$
    document.setPageSize(PageSize.A4);
    document.setMargins(20, 10, 10, 10);
    return document;
}

From source file:com.biblio.web.rest.PdfResources.java

@RequestMapping(value = "livre", method = RequestMethod.GET)
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException, WriterException {
    response.setContentType("application/pdf");
    GenerateQRCode ge = new GenerateQRCode();

    try {//from   w  ww .  ja  v a 2  s.c  o m

        Document document = new Document();
        String param = request.getParameter("isbn");
        Livre livre = livreRepository.findOneByIsbn(param).get();
        PdfWriter e = PdfWriter.getInstance(document, response.getOutputStream());

        document.open();

        Font font = new Font();

        font.setStyle(Font.BOLD);
        font.setSize(12);

        List list = new List(15);

        //  document.left(12);
        list.add(new ListItem("Titre  :" + livre.getTitre(), font));
        list.add(new ListItem("Categorie  :" + livre.getCategorie().getDescription(), font));
        list.add(new ListItem("Auteurs   :" + livre.getAuteurs(), font));
        list.add(new ListItem("Edition   :" + livre.getEdition(), font));
        list.add(new ListItem("Editeur   :" + livre.getEditeur(), font));
        list.add(new ListItem("Collection   :" + livre.getCollection(), font));
        list.add(new ListItem("Date parution   :" + livre.getDateParution(), font));
        list.add(new ListItem("Isbn   " + livre.getIsbn(), font));
        list.add(new ListItem("Resume   : " + livre.getResume(), font));

        document.add(list);
        document.addTitle(livre.getTitre());
        document.setMargins(100, 20, 0, 0);
        document.addCreationDate();
        System.out.println("TTT v " + document.addTitle(param));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(ge.createQRImage(param, 125), "jpg", baos);
        Image image = Image.getInstance(baos.toByteArray());
        document.add(image);
        document.close();

    } catch (DocumentException de) {
        throw new IOException(de.getMessage());
    }
}

From source file:com.coderbd.pos.pdf.OrderFileBuilder.java

public String makePdf(ShopOrder shopOrder) {
    Document document = new Document(new Rectangle(205, 800));
    String fileName = directory + "\\" + shopOrder.getCustomerOrder().getOrderBarcode() + ".pdf";
    String receiptText = receipt.getIndentedOrder(shopOrder);
    System.out.println(receiptText);

    document.setMargins(3, 2, 2, 2);

    Font courierFont = FontFactory.getFont("courier");
    courierFont.setSize(10f);//from  w ww  .j ava  2  s .c  om

    try {
        PdfWriter.getInstance(document, new FileOutputStream(fileName));

        document.open();
        document.add(new Paragraph(receiptText, courierFont));
        document.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return fileName;
}

From source file:com.devox.GUI.PDF.CrearReporteTarimas.java

@Override
public void crear(File file) {
    try {/*from   ww  w  .  jav a2  s.  c  o m*/
        Document document = new Document(PageSize.A4.rotate());
        file.createNewFile();
        PdfWriter w = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        setLogo();
        CabeceraPieDePagina event = new CabeceraPieDePagina();
        w.setPageEvent(event);
        document.setMargins(50, 50, 100, 50);
        document.newPage();
        document.add(configurarInformacion());
        PdfPTable table = crearTabla();
        agregarProductos(table);
        document.add(table);
        document.close();
    } catch (Exception ex) {
        Log.print(ex);
    }

    Object[] options = { "Abrir PDF", "No" };
    int open = JOptionPane.showOptionDialog(null, "Desea abrir el reporte?", "Reporte guardado",
            JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
            new javax.swing.ImageIcon(getClass().getResource("/com/devox/GUI/images/print.png")), options,
            options[0]);
    if (open == JOptionPane.YES_OPTION) {
        try {
            Desktop.getDesktop().open(file);
        } catch (IOException ex) {
            Log.print("No se encontr la ruta");
            JOptionPane.showMessageDialog(null, "Error en el archivo");
        }
    }
}