Example usage for com.lowagie.text PageSize LETTER

List of usage examples for com.lowagie.text PageSize LETTER

Introduction

In this page you can find the example usage for com.lowagie.text PageSize LETTER.

Prototype

Rectangle LETTER

To view the source code for com.lowagie.text PageSize LETTER.

Click Source Link

Document

This is the letter format

Usage

From source file:org.freeeed.print.OfficePrint.java

License:Apache License

private void convertCSVToPdf(File officeDocFile, String originalFileName, File outputFile) {
    try {/*w  ww .j av a 2s  . co m*/
        BufferedReader input = new BufferedReader(new FileReader(officeDocFile));
        Document document = new Document(PageSize.LETTER);
        PdfWriter.getInstance(document, new FileOutputStream(outputFile));
        document.open();
        document.addSubject(originalFileName);
        document.addTitle(originalFileName);

        String line = "";
        while (null != (line = input.readLine())) {
            Paragraph p = new Paragraph(line);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            document.add(p);
        }
        document.close();
        input.close();

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

From source file:org.jboss.as.quickstarts.ejbinwar.ejb.GreeterEJB.java

License:Apache License

public ByteArrayOutputStream generatePDFDocumentBytes(String selectedTariff) throws DocumentException {
    java.util.Set<String> users = getRestUsers(selectedTariff);

    Document doc = new Document();

    ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
    PdfWriter docWriter = null;/*from ww  w.  j  a v a2 s  .c  o  m*/

    try {
        docWriter = PdfWriter.getInstance(doc, baosPDF);

        doc.addAuthor(this.getClass().getName());
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator(this.getClass().getName());
        doc.addTitle(selectedTariff + " clients");
        doc.addKeywords("pdf, itext, Java, ecare, http");

        doc.setPageSize(PageSize.LETTER);

        HeaderFooter footer = new HeaderFooter(new Phrase("E-Care report"), false);

        doc.setFooter(footer);

        doc.open();

        doc.add(new Paragraph(selectedTariff + " clients"));
        doc.add(new Paragraph("\n"));
        doc.add(new Paragraph("\n"));

        PdfPTable table = new PdfPTable(4); // 3 columns.

        PdfPCell cell1 = new PdfPCell(new Paragraph("Name"));
        PdfPCell cell2 = new PdfPCell(new Paragraph("Surname"));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Address"));
        PdfPCell cell4 = new PdfPCell(new Paragraph("Email"));

        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);
        table.addCell(cell4);

        for (Iterator<String> it = users.iterator(); it.hasNext();) {
            String user = it.next();

            table.addCell(new PdfPCell(new Paragraph(user.split(" ")[0])));
            table.addCell(new PdfPCell(new Paragraph(user.split(" ")[1])));
            table.addCell(new PdfPCell(new Paragraph(user.split(" ")[2])));
            table.addCell(new PdfPCell(new Paragraph(user.split(" ")[3])));
        }

        doc.add(table);

    } catch (DocumentException dex) {
        baosPDF.reset();
        throw dex;
    } finally {
        if (doc != null) {
            doc.close();
        }
        if (docWriter != null) {
            docWriter.close();
        }
    }

    if (baosPDF.size() < 1) {
        throw new DocumentException("document has " + baosPDF.size() + " bytes");
    }
    return baosPDF;

}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerInvoiceWriteoffBatchServiceImpl.java

License:Open Source License

protected com.lowagie.text.Document getPdfDoc() throws IOException, DocumentException {

    String reportDropFolder = reportsDirectory + "/"
            + ArConstants.CustomerInvoiceWriteoff.CUSTOMER_INVOICE_WRITEOFF_REPORT_SUBFOLDER + "/";
    String fileName = ArConstants.CustomerInvoiceWriteoff.BATCH_REPORT_BASENAME + "_"
            + new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(dateTimeService.getCurrentDate()) + ".pdf";

    //  setup the writer
    File reportFile = new File(reportDropFolder + fileName);
    FileOutputStream fileOutStream;
    fileOutStream = new FileOutputStream(reportFile);
    BufferedOutputStream buffOutStream = new BufferedOutputStream(fileOutStream);

    com.lowagie.text.Document pdfdoc = new com.lowagie.text.Document(PageSize.LETTER, 54, 54, 72, 72);
    PdfWriter.getInstance(pdfdoc, buffOutStream);

    pdfdoc.open();/*  w  w  w .  ja  va 2s.c  o  m*/

    return pdfdoc;
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.CustomerLoadServiceImpl.java

License:Open Source License

protected void writeReportPDF(List<CustomerLoadFileResult> fileResults) {

    if (fileResults.isEmpty()) {
        return;//from   w  w w  .j  a  v  a  2 s.c  om
    }

    //  setup the PDF business
    Document pdfDoc = new Document(PageSize.LETTER, 54, 54, 72, 72);
    try {
        getPdfWriter(pdfDoc);
        try {
            pdfDoc.open();

            if (fileResults.isEmpty()) {
                writeFileNameSectionTitle(pdfDoc, "NO DOCUMENTS FOUND TO PROCESS");
                return;
            }

            CustomerLoadResult result;
            String customerResultLine;
            for (CustomerLoadFileResult fileResult : fileResults) {

                //  file name title
                String fileNameOnly = fileResult.getFilename().toUpperCase();
                fileNameOnly = fileNameOnly.substring(fileNameOnly.lastIndexOf("\\") + 1);
                writeFileNameSectionTitle(pdfDoc, fileNameOnly);

                //  write any file-general messages
                writeMessageEntryLines(pdfDoc, fileResult.getMessages());

                //  walk through each customer included in this file
                for (String customerName : fileResult.getCustomerNames()) {
                    result = fileResult.getCustomer(customerName);

                    //  write the customer title
                    writeCustomerSectionTitle(pdfDoc, customerName.toUpperCase());

                    //  write a success/failure results line for this customer
                    customerResultLine = result.getResultString()
                            + (ResultCode.SUCCESS.equals(result.getResult())
                                    ? WORKFLOW_DOC_ID_PREFIX + result.getWorkflowDocId()
                                    : "");
                    writeCustomerSectionResult(pdfDoc, customerResultLine);

                    //  write any customer messages
                    writeMessageEntryLines(pdfDoc, result.getMessages());
                }
            }
        } finally {
            if (pdfDoc != null) {
                pdfDoc.close();
            }
        }
    } catch (IOException | DocumentException ex) {
        throw new RuntimeException("Could not open file for results report", ex);
    }
}

From source file:org.kuali.kfs.module.ar.batch.service.impl.LockboxServiceImpl.java

License:Open Source License

protected com.lowagie.text.Document getPdfDoc() throws IOException, DocumentException {

    String reportDropFolder = reportsDirectory + "/" + ArConstants.Lockbox.LOCKBOX_REPORT_SUBFOLDER + "/";
    String fileName = ArConstants.Lockbox.BATCH_REPORT_BASENAME + "_"
            + new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(dateTimeService.getCurrentDate()) + ".pdf";

    //  setup the writer
    File reportFile = new File(reportDropFolder + fileName);
    FileOutputStream fileOutStream;
    fileOutStream = new FileOutputStream(reportFile);
    BufferedOutputStream buffOutStream = new BufferedOutputStream(fileOutStream);

    com.lowagie.text.Document pdfdoc = new com.lowagie.text.Document(PageSize.LETTER, 54, 54, 72, 72);
    PdfWriter.getInstance(pdfdoc, buffOutStream);

    pdfdoc.open();/*from w ww  .j  a va  2 s.c  om*/

    return pdfdoc;
}

From source file:org.locationtech.udig.printing.ui.pdf.PrintWizard.java

License:Open Source License

/**
 * converts a page size "name" (such as "A3" or "A4" into a 
 * rectangle object that iText will understand.
 *//*from   www.j  ava  2s. com*/
private Rectangle getITextPageSize(String pageSizeName) {
    if (pageSizeName.equals("A3")) //$NON-NLS-1$
        return PageSize.A3;
    if (pageSizeName.equals("A4")) //$NON-NLS-1$
        return PageSize.A4;
    if (pageSizeName.equals("Letter"))
        return PageSize.LETTER;
    throw new IllegalArgumentException(pageSizeName + " is not a supported page size"); //$NON-NLS-1$
}

From source file:org.ofbiz.content.compdoc.CompDocServices.java

License:Apache License

public static Map<String, Object> renderCompDocPdf(DispatchContext dctx,
        Map<String, ? extends Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();

    Locale locale = (Locale) context.get("locale");
    String rootDir = (String) context.get("rootDir");
    String webSiteId = (String) context.get("webSiteId");
    String https = (String) context.get("https");

    Delegator delegator = dctx.getDelegator();

    String contentId = (String) context.get("contentId");
    String contentRevisionSeqId = (String) context.get("contentRevisionSeqId");
    String oooHost = (String) context.get("oooHost");
    String oooPort = (String) context.get("oooPort");
    GenericValue userLogin = (GenericValue) context.get("userLogin");

    try {/*  w  w  w. j  a v  a2s. co  m*/
        List<EntityCondition> exprList = FastList.newInstance();
        exprList.add(EntityCondition.makeCondition("contentIdTo", EntityOperator.EQUALS, contentId));
        exprList.add(
                EntityCondition.makeCondition("contentAssocTypeId", EntityOperator.EQUALS, "COMPDOC_PART"));
        exprList.add(EntityCondition.makeCondition("rootRevisionContentId", EntityOperator.EQUALS, contentId));
        if (UtilValidate.isNotEmpty(contentRevisionSeqId)) {
            exprList.add(EntityCondition.makeCondition("contentRevisionSeqId",
                    EntityOperator.LESS_THAN_EQUAL_TO, contentRevisionSeqId));
        }

        List<GenericValue> compDocParts = EntityQuery.use(delegator)
                .select("rootRevisionContentId", "itemContentId", "maxRevisionSeqId", "contentId",
                        "dataResourceId", "contentIdTo", "contentAssocTypeId", "fromDate", "sequenceNum")
                .from("ContentAssocRevisionItemView").where(exprList).orderBy("sequenceNum").filterByDate()
                .queryList();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        //Rectangle rect = document.getPageSize();
        //PdfWriter writer = PdfWriter.getInstance(document, baos);
        PdfCopy writer = new PdfCopy(document, baos);
        document.open();
        int pgCnt = 0;
        for (GenericValue contentAssocRevisionItemView : compDocParts) {
            //String thisContentId = contentAssocRevisionItemView.getString("contentId");
            //String thisContentRevisionSeqId = contentAssocRevisionItemView.getString("maxRevisionSeqId");
            String thisDataResourceId = contentAssocRevisionItemView.getString("dataResourceId");
            GenericValue dataResource = EntityQuery.use(delegator).from("DataResource")
                    .where("dataResourceId", thisDataResourceId).queryOne();
            String inputMimeType = null;
            if (dataResource != null) {
                inputMimeType = dataResource.getString("mimeTypeId");
            }
            byte[] inputByteArray = null;
            PdfReader reader = null;
            if (inputMimeType != null && inputMimeType.equals("application/pdf")) {
                ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, thisDataResourceId,
                        https, webSiteId, locale, rootDir);
                inputByteArray = byteBuffer.array();
                reader = new PdfReader(inputByteArray);
            } else if (inputMimeType != null && inputMimeType.equals("text/html")) {
                ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, thisDataResourceId,
                        https, webSiteId, locale, rootDir);
                inputByteArray = byteBuffer.array();
                String s = new String(inputByteArray);
                Debug.logInfo("text/html string:" + s, module);
                continue;
            } else if (inputMimeType != null && inputMimeType.equals("application/vnd.ofbiz.survey.response")) {
                String surveyResponseId = dataResource.getString("relatedDetailId");
                String surveyId = null;
                String acroFormContentId = null;
                GenericValue surveyResponse = null;
                if (UtilValidate.isNotEmpty(surveyResponseId)) {
                    surveyResponse = EntityQuery.use(delegator).from("SurveyResponse")
                            .where("surveyResponseId", surveyResponseId).queryOne();
                    if (surveyResponse != null) {
                        surveyId = surveyResponse.getString("surveyId");
                    }
                }
                if (UtilValidate.isNotEmpty(surveyId)) {
                    GenericValue survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId)
                            .queryOne();
                    if (survey != null) {
                        acroFormContentId = survey.getString("acroFormContentId");
                        if (UtilValidate.isNotEmpty(acroFormContentId)) {
                            // TODO: is something supposed to be done here?
                        }
                    }
                }
                if (surveyResponse != null) {
                    if (UtilValidate.isEmpty(acroFormContentId)) {
                        // Create AcroForm PDF
                        Map<String, Object> survey2PdfResults = dispatcher.runSync("buildPdfFromSurveyResponse",
                                UtilMisc.toMap("surveyResponseId", surveyId));
                        if (ServiceUtil.isError(survey2PdfResults)) {
                            return ServiceUtil.returnError(UtilProperties.getMessage(resource,
                                    "ContentSurveyErrorBuildingPDF", locale), null, null, survey2PdfResults);
                        }

                        ByteBuffer outByteBuffer = (ByteBuffer) survey2PdfResults.get("outByteBuffer");
                        inputByteArray = outByteBuffer.array();
                        reader = new PdfReader(inputByteArray);
                    } else {
                        // Fill in acroForm
                        Map<String, Object> survey2AcroFieldResults = dispatcher.runSync(
                                "setAcroFieldsFromSurveyResponse",
                                UtilMisc.toMap("surveyResponseId", surveyResponseId));
                        if (ServiceUtil.isError(survey2AcroFieldResults)) {
                            return ServiceUtil
                                    .returnError(
                                            UtilProperties.getMessage(resource,
                                                    "ContentSurveyErrorSettingAcroFields", locale),
                                            null, null, survey2AcroFieldResults);
                        }

                        ByteBuffer outByteBuffer = (ByteBuffer) survey2AcroFieldResults.get("outByteBuffer");
                        inputByteArray = outByteBuffer.array();
                        reader = new PdfReader(inputByteArray);
                    }
                }
            } else {
                ByteBuffer inByteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator,
                        thisDataResourceId, https, webSiteId, locale, rootDir);

                Map<String, Object> convertInMap = UtilMisc.<String, Object>toMap("userLogin", userLogin,
                        "inByteBuffer", inByteBuffer, "inputMimeType", inputMimeType, "outputMimeType",
                        "application/pdf");
                if (UtilValidate.isNotEmpty(oooHost))
                    convertInMap.put("oooHost", oooHost);
                if (UtilValidate.isNotEmpty(oooPort))
                    convertInMap.put("oooPort", oooPort);

                Map<String, Object> convertResult = dispatcher.runSync("convertDocumentByteBuffer",
                        convertInMap);

                if (ServiceUtil.isError(convertResult)) {
                    return ServiceUtil.returnError(
                            UtilProperties.getMessage(resource, "ContentConvertingDocumentByteBuffer", locale),
                            null, null, convertResult);
                }

                ByteBuffer outByteBuffer = (ByteBuffer) convertResult.get("outByteBuffer");
                inputByteArray = outByteBuffer.array();
                reader = new PdfReader(inputByteArray);
            }
            if (reader != null) {
                int n = reader.getNumberOfPages();
                for (int i = 0; i < n; i++) {
                    PdfImportedPage pg = writer.getImportedPage(reader, i + 1);
                    //cb.addTemplate(pg, left, height * pgCnt);
                    writer.addPage(pg);
                    pgCnt++;
                }
            }
        }
        document.close();
        ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray());

        Map<String, Object> results = ServiceUtil.returnSuccess();
        results.put("outByteBuffer", outByteBuffer);
        return results;
    } catch (GenericEntityException e) {
        return ServiceUtil.returnError(e.toString());
    } catch (IOException e) {
        Debug.logError(e, "Error in CompDoc operation: ", module);
        return ServiceUtil.returnError(e.toString());
    } catch (Exception e) {
        Debug.logError(e, "Error in CompDoc operation: ", module);
        return ServiceUtil.returnError(e.toString());
    }
}

From source file:org.ofbiz.content.compdoc.CompDocServices.java

License:Apache License

public static Map<String, Object> renderContentPdf(DispatchContext dctx,
        Map<String, ? extends Object> context) {
    LocalDispatcher dispatcher = dctx.getDispatcher();
    Map<String, Object> results = ServiceUtil.returnSuccess();
    String dataResourceId = null;

    Locale locale = (Locale) context.get("locale");
    String rootDir = (String) context.get("rootDir");
    String webSiteId = (String) context.get("webSiteId");
    String https = (String) context.get("https");

    Delegator delegator = dctx.getDelegator();

    String contentId = (String) context.get("contentId");
    String contentRevisionSeqId = (String) context.get("contentRevisionSeqId");
    String oooHost = (String) context.get("oooHost");
    String oooPort = (String) context.get("oooPort");
    GenericValue userLogin = (GenericValue) context.get("userLogin");

    try {//w ww .j  a  va 2 s . c  om
        //Timestamp nowTimestamp = UtilDateTime.nowTimestamp();
        //ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        //Rectangle rect = document.getPageSize();
        //PdfCopy writer = new PdfCopy(document, baos);
        document.open();

        GenericValue dataResource = null;
        if (UtilValidate.isEmpty(contentRevisionSeqId)) {
            GenericValue content = EntityQuery.use(delegator).from("Content").where("contentId", contentId)
                    .cache().queryOne();
            dataResourceId = content.getString("dataResourceId");
            Debug.logInfo("SCVH(0b)- dataResourceId:" + dataResourceId, module);
            dataResource = EntityQuery.use(delegator).from("DataResource")
                    .where("dataResourceId", dataResourceId).queryOne();
        } else {
            GenericValue contentRevisionItem = EntityQuery.use(delegator).from("ContentRevisionItem")
                    .where("contentId", contentId, "itemContentId", contentId, "contentRevisionSeqId",
                            contentRevisionSeqId)
                    .cache().queryOne();
            if (contentRevisionItem == null) {
                throw new ViewHandlerException("ContentRevisionItem record not found for contentId=" + contentId
                        + ", contentRevisionSeqId=" + contentRevisionSeqId + ", itemContentId=" + contentId);
            }
            Debug.logInfo("SCVH(1)- contentRevisionItem:" + contentRevisionItem, module);
            Debug.logInfo("SCVH(2)-contentId=" + contentId + ", contentRevisionSeqId=" + contentRevisionSeqId
                    + ", itemContentId=" + contentId, module);
            dataResourceId = contentRevisionItem.getString("newDataResourceId");
            Debug.logInfo("SCVH(3)- dataResourceId:" + dataResourceId, module);
            dataResource = EntityQuery.use(delegator).from("DataResource")
                    .where("dataResourceId", dataResourceId).queryOne();
        }
        String inputMimeType = null;
        if (dataResource != null) {
            inputMimeType = dataResource.getString("mimeTypeId");
        }
        byte[] inputByteArray = null;
        if (inputMimeType != null && inputMimeType.equals("application/pdf")) {
            ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, dataResourceId, https,
                    webSiteId, locale, rootDir);
            inputByteArray = byteBuffer.array();
        } else if (inputMimeType != null && inputMimeType.equals("text/html")) {
            ByteBuffer byteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, dataResourceId, https,
                    webSiteId, locale, rootDir);
            inputByteArray = byteBuffer.array();
            String s = new String(inputByteArray);
            Debug.logInfo("text/html string:" + s, module);
        } else if (inputMimeType != null && inputMimeType.equals("application/vnd.ofbiz.survey.response")) {
            String surveyResponseId = dataResource.getString("relatedDetailId");
            String surveyId = null;
            String acroFormContentId = null;
            GenericValue surveyResponse = null;
            if (UtilValidate.isNotEmpty(surveyResponseId)) {
                surveyResponse = EntityQuery.use(delegator).from("SurveyResponse")
                        .where("surveyResponseId", surveyResponseId).queryOne();
                if (surveyResponse != null) {
                    surveyId = surveyResponse.getString("surveyId");
                }
            }
            if (UtilValidate.isNotEmpty(surveyId)) {
                GenericValue survey = EntityQuery.use(delegator).from("Survey").where("surveyId", surveyId)
                        .queryOne();
                if (survey != null) {
                    acroFormContentId = survey.getString("acroFormContentId");
                    if (UtilValidate.isNotEmpty(acroFormContentId)) {
                        // TODO: is something supposed to be done here?
                    }
                }
            }

            if (surveyResponse != null) {
                if (UtilValidate.isEmpty(acroFormContentId)) {
                    // Create AcroForm PDF
                    Map<String, Object> survey2PdfResults = dispatcher.runSync("buildPdfFromSurveyResponse",
                            UtilMisc.toMap("surveyResponseId", surveyResponseId));
                    if (ServiceUtil.isError(survey2PdfResults)) {
                        return ServiceUtil.returnError(
                                UtilProperties.getMessage(resource, "ContentSurveyErrorBuildingPDF", locale),
                                null, null, survey2PdfResults);
                    }

                    ByteBuffer outByteBuffer = (ByteBuffer) survey2PdfResults.get("outByteBuffer");
                    inputByteArray = outByteBuffer.array();
                } else {
                    // Fill in acroForm
                    Map<String, Object> survey2AcroFieldResults = dispatcher.runSync(
                            "setAcroFieldsFromSurveyResponse",
                            UtilMisc.toMap("surveyResponseId", surveyResponseId));
                    if (ServiceUtil.isError(survey2AcroFieldResults)) {
                        return ServiceUtil
                                .returnError(
                                        UtilProperties.getMessage(resource,
                                                "ContentSurveyErrorSettingAcroFields", locale),
                                        null, null, survey2AcroFieldResults);
                    }

                    ByteBuffer outByteBuffer = (ByteBuffer) survey2AcroFieldResults.get("outByteBuffer");
                    inputByteArray = outByteBuffer.array();
                }
            }
        } else {
            ByteBuffer inByteBuffer = DataResourceWorker.getContentAsByteBuffer(delegator, dataResourceId,
                    https, webSiteId, locale, rootDir);

            Map<String, Object> convertInMap = UtilMisc.<String, Object>toMap("userLogin", userLogin,
                    "inByteBuffer", inByteBuffer, "inputMimeType", inputMimeType, "outputMimeType",
                    "application/pdf");
            if (UtilValidate.isNotEmpty(oooHost))
                convertInMap.put("oooHost", oooHost);
            if (UtilValidate.isNotEmpty(oooPort))
                convertInMap.put("oooPort", oooPort);

            Map<String, Object> convertResult = dispatcher.runSync("convertDocumentByteBuffer", convertInMap);

            if (ServiceUtil.isError(convertResult)) {
                return ServiceUtil.returnError(
                        UtilProperties.getMessage(resource, "ContentConvertingDocumentByteBuffer", locale),
                        null, null, convertResult);
            }

            ByteBuffer outByteBuffer = (ByteBuffer) convertResult.get("outByteBuffer");
            inputByteArray = outByteBuffer.array();
        }

        ByteBuffer outByteBuffer = ByteBuffer.wrap(inputByteArray);
        results.put("outByteBuffer", outByteBuffer);
    } catch (GenericEntityException e) {
        return ServiceUtil.returnError(e.toString());
    } catch (IOException e) {
        Debug.logError(e, "Error in PDF generation: ", module);
        return ServiceUtil.returnError(e.toString());
    } catch (Exception e) {
        Debug.logError(e, "Error in PDF generation: ", module);
        return ServiceUtil.returnError(e.toString());
    }
    return results;
}

From source file:org.openepics.discs.names.ui.ReportManager.java

License:Open Source License

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.setPageSize(PageSize.LETTER.rotate());
    // pdf.open();
    // pdf.setPageSize(PageSize.LETTER.rotate());
    pdf.addCreationDate();/*from   ww w.ja va  2  s. com*/
    pdf.addHeader("Header", "Proteus: Naming Convention Rep");
    pdf.addTitle("Proteus: Naming Convention Report");

    // ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
    // String logo = servletContext.getRealPath("") + File.separator + "images" + File.separator + "prime_logo.png";

    // pdf.add(Image.getInstance(logo));
}

From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java

License:Open Source License

public OscarChartPrinter(HttpServletRequest request, OutputStream os) throws DocumentException, IOException {
    this.request = request;
    this.os = os;

    document = new Document();
    writer = PdfWriter.getInstance(document, os);
    writer.setPageEvent(new EndPage());
    document.setPageSize(PageSize.LETTER);
    document.open();//  w ww . jav a2s.c om
    //Create the font we are going to print to
    bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
    font = new Font(bf, FONTSIZE, Font.NORMAL);
    boldFont = new Font(bf, FONTSIZE, Font.BOLD);
}