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:net.mitnet.tools.pdf.book.pdf.util.PdfPageSizeHelper.java

License:Open Source License

/**
 * Returns the default page size for the current locale.
 * @return/*from  w w w . j  a v a  2  s .  c o m*/
 */
public static final Rectangle getDefaultPageSizeByLocale(Locale locale, Rectangle defaultPageSize) {

    Rectangle pageSize = PdfPageValues.DEFAULT_PAGE_SIZE;
    if (defaultPageSize != null) {
        pageSize = defaultPageSize;
    }

    if (locale != null) {
        if (LocaleHelper.isUsaLocale()) {
            pageSize = PageSize.LETTER;
        }
    }

    return pageSize;
}

From source file:net.refractions.udig.printing.ui.internal.template.LegalPortraitTemplate.java

License:Open Source License

protected Rectangle getPaperSize() {
    Rectangle letter = PageSize.LETTER;
    return letter;
}

From source file:net.refractions.udig.printing.ui.internal.template.LetterLandscapeTemplate.java

License:Open Source License

protected Rectangle getPaperSize() {
    Rectangle letter = PageSize.LETTER;
    Rectangle letterLandscape = new Rectangle(0f, 0f, letter.getHeight(), letter.getWidth());
    return letterLandscape;
}

From source file:org.apache.cocoon.serialization.iTextSerializer.java

License:Apache License

private Rectangle getPageSize(final String s) throws ConfigurationException {
    // TC: we could use reflection here instead
    if ("letter".equalsIgnoreCase(s)) {
        return PageSize.LETTER;
    } else if ("a4".equalsIgnoreCase(s)) {
        return PageSize.A4;
    } else if ("a5".equalsIgnoreCase(s)) {
        return PageSize.A5;
    } else {//  w  w  w. j  a  v  a2  s  .  c o  m
        throw new ConfigurationException("page size [" + String.valueOf(s) + "] is not yet recognized");
    }
}

From source file:org.apache.maven.doxia.module.itext.ITextUtil.java

License:Apache License

/**
 * Set the default page size for the document depending the user's country.
 * TODO Maybe more generic?//from   ww w  .  jav a 2 s .  com
 *
 * @return the page size
 * @see com.lowagie.text.PageSize
 */
public static Rectangle getDefaultPageSize() {
    String defaultCountry = Locale.getDefault().getCountry();
    if (defaultCountry != null && (defaultCountry.equals(Locale.US.getCountry())
            || defaultCountry.equals(Locale.CANADA.getCountry()))) {
        return PageSize.LETTER;
    }

    return PageSize.A4;
}

From source file:org.apache.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");
    GenericValue userLogin = (GenericValue) context.get("userLogin");

    try {/*from www . ja va 2 s . c  om*/
        List<EntityCondition> exprList = new LinkedList<EntityCondition>();
        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);
        PdfCopy writer = new PdfCopy(document, baos);
        document.open();
        int pgCnt = 0;
        for (GenericValue contentAssocRevisionItemView : compDocParts) {
            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 {
                return ServiceUtil.returnError(
                        UtilProperties.getMessage(resource, "ContentMimeTypeNotSupported", locale));
            }
            if (reader != null) {
                int n = reader.getNumberOfPages();
                for (int i = 0; i < n; i++) {
                    PdfImportedPage pg = writer.getImportedPage(reader, i + 1);
                    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.apache.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");
    GenericValue userLogin = (GenericValue) context.get("userLogin");

    try {/* w ww  . j  a va  2 s . co m*/
        Document document = new Document();
        document.setPageSize(PageSize.LETTER);
        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 {
            return ServiceUtil
                    .returnError(UtilProperties.getMessage(resource, "ContentMimeTypeNotSupported", locale));
        }

        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.caisi.tickler.web.TicklerPrinter.java

License:Open Source License

public void start() throws DocumentException, IOException {
    //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);

    document = new Document();
    writer = PdfWriterFactory.newInstance(document, os, FontSettings.HELVETICA_10PT);
    writer.setStrictImageSequence(true);

    document.setPageSize(PageSize.LETTER);
    document.open();/*from www .  j av  a  2s. c o  m*/
}

From source file:org.cytoscape.io.internal.write.graphics.PDFWriter.java

License:Open Source License

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    // TODO should be accomplished with renderer properties
    // view.setPrintingTextAsShape(!exportTextAsFont);

    taskMonitor.setProgress(0.0);/*w  w w  .  j  av  a2  s.  co  m*/
    taskMonitor.setStatusMessage("Creating PDF image...");

    logger.debug("PDF Rendering start");
    final Rectangle pageSize = PageSize.LETTER;
    final Document document = new Document(pageSize);

    logger.debug("Document created: " + document);

    final PdfWriter writer = PdfWriter.getInstance(document, stream);
    document.open();

    taskMonitor.setProgress(0.1);

    final PdfContentByte canvas = writer.getDirectContent();
    logger.debug("CB0 created: " + canvas.getClass());

    final float pageWidth = pageSize.getWidth();
    final float pageHeight = pageSize.getHeight();

    logger.debug("Page W: " + pageWidth + " Page H: " + pageHeight);
    final DefaultFontMapper fontMapper = new DefaultFontMapper();
    logger.debug("FontMapper created = " + fontMapper);
    Graphics2D g = null;
    logger.debug("!!!!! Enter block 2");

    engine.getProperties().setProperty("exportTextAsShape", new Boolean(!exportTextAsFont).toString());

    taskMonitor.setProgress(0.2);

    if (exportTextAsFont) {
        g = canvas.createGraphics(pageWidth, pageHeight, new DefaultFontMapper());
    } else {
        g = canvas.createGraphicsShapes(pageWidth, pageHeight);
    }

    taskMonitor.setProgress(0.4);

    logger.debug("##### G2D created: " + g);

    double imageScale = Math.min(pageSize.getWidth() / width, pageSize.getHeight() / height);
    g.scale(imageScale, imageScale);

    logger.debug("##### Start Rendering Phase 2: " + engine.toString());
    engine.printCanvas(g);
    logger.debug("##### Canvas Rendering Done: ");

    taskMonitor.setProgress(0.8);

    g.dispose();
    document.close();
    writer.close();

    stream.close();

    logger.debug("PDF rendering finished.");
    taskMonitor.setProgress(1.0);
}

From source file:org.eclipse.osee.framework.ui.skynet.util.TableWriterAdaptor.java

License:Open Source License

public TableWriterAdaptor(String writerId, OutputStream outputStream) throws Exception {
    this(writerId, PageSize.LETTER.rotate(), outputStream);
}