Package com.lowagie.text

Examples of com.lowagie.text.Document


    private final PdfContentByte contentByte;
    private final int scale = 1;

    public PDFBoletoWriter(double width, double height) {
        this.bytes = new ByteArrayOutputStream();
        this.document = new Document();

        try {
            this.writer = PdfWriter.getInstance(this.document, this.bytes);

            this.fonteSimples = BaseFont.createFont(BaseFont.HELVETICA,
View Full Code Here


        Map results = ServiceUtil.returnSuccess();
        String surveyResponseId = (String)context.get("surveyResponseId");
        String contentId = (String)context.get("contentId");
        String surveyId = null;

        Document document = new Document();
        try {
            if (UtilValidate.isNotEmpty(surveyResponseId)) {
                GenericValue surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                if (surveyResponse != null) {
                    surveyId = surveyResponse.getString("surveyId");
                }
            }
            if (UtilValidate.isNotEmpty(surveyId) && UtilValidate.isEmpty(contentId)) {
                GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
                if (survey != null) {
                    String acroFormContentId = survey.getString("acroFormContentId");
                    if (UtilValidate.isNotEmpty(acroFormContentId)) {
                        context.put("contentId", acroFormContentId);
                    }
                }
            }

            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            PdfWriter.getInstance(document, baos);

            List responses = delegator.findByAnd("SurveyResponseAnswer", UtilMisc.toMap("surveyResponseId", surveyResponseId));
            Iterator iter = responses.iterator();
            while (iter.hasNext()) {
                String value = null;
                GenericValue surveyResponseAnswer = (GenericValue) iter.next();
                String surveyQuestionId = (String) surveyResponseAnswer.get("surveyQuestionId");
                GenericValue surveyQuestion = delegator.findByPrimaryKey("SurveyQuestion", UtilMisc.toMap("surveyQuestionId", surveyQuestionId));
                String questionType = surveyQuestion.getString("surveyQuestionTypeId");
                // DEJ20060227 this isn't used, if needed in the future should get from SurveyQuestionAppl.externalFieldRef String fieldName = surveyQuestion.getString("description");
                if ("OPTION".equals(questionType)) {
                    value = surveyResponseAnswer.getString("surveyOptionSeqId");
                } else if ("BOOLEAN".equals(questionType)) {
                    value = surveyResponseAnswer.getString("booleanResponse");
                } else if ("NUMBER_LONG".equals(questionType) || "NUMBER_CURRENCY".equals(questionType) || "NUMBER_FLOAT".equals(questionType)) {
                    Double num = surveyResponseAnswer.getDouble("numericResponse");
                    if (num != null) {
                        value = num.toString();
                    }
                } else if ("SEPERATOR_LINE".equals(questionType) || "SEPERATOR_TEXT".equals(questionType)) {
                    // not really a question; ingore completely
                } else {
                    value = surveyResponseAnswer.getString("textResponse");
                }
                Chunk chunk = new Chunk(surveyQuestion.getString("question") + ": " + value);
                Paragraph p = new Paragraph(chunk);
                document.add(p);
            }
            ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray());
            results.put("outByteBuffer", outByteBuffer);
        } catch (GenericEntityException e) {
            System.err.println(e.getMessage());
View Full Code Here

        Map results = ServiceUtil.returnSuccess();
        String surveyResponseId = (String)context.get("surveyResponseId");
        String surveyId = null;
        List qAndA = FastList.newInstance();

        Document document = new Document();
        try {
            if (UtilValidate.isNotEmpty(surveyResponseId)) {
                GenericValue surveyResponse = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                if (surveyResponse != null) {
                    surveyId = surveyResponse.getString("surveyId");
View Full Code Here

            Set selectFields = UtilMisc.toSetArray(fields);
            List orderByFields = UtilMisc.toList("sequenceNum");
            List compDocParts = delegator.findList("ContentAssocRevisionItemView", conditionList, selectFields, orderByFields, null, false);

            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();
            Iterator iter = compDocParts.iterator();
            int pgCnt =0;
            while (iter.hasNext()) {
                GenericValue contentAssocRevisionItemView = (GenericValue)iter.next();
                //String thisContentId = contentAssocRevisionItemView.getString("contentId");
                //String thisContentRevisionSeqId = contentAssocRevisionItemView.getString("maxRevisionSeqId");
                String thisDataResourceId = contentAssocRevisionItemView.getString("dataResourceId");
                GenericValue dataResource = delegator.findByPrimaryKey("DataResource", UtilMisc.toMap("dataResourceId", thisDataResourceId));
                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 = delegator.findByPrimaryKey("SurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                        if (surveyResponse != null) {
                            surveyId = surveyResponse.getString("surveyId");
                        }
                    }
                    if (UtilValidate.isNotEmpty(surveyId)) {
                        GenericValue survey = delegator.findByPrimaryKey("Survey", UtilMisc.toMap("surveyId", surveyId));
                        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 survey2PdfResults = dispatcher.runSync("buildPdfFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyId));
                            if (ServiceUtil.isError(survey2PdfResults)) {
                                return ServiceUtil.returnError("Error building PDF from SurveyResponse: ", null, null, survey2PdfResults);
                            }

                            ByteBuffer outByteBuffer = (ByteBuffer) survey2PdfResults.get("outByteBuffer");
                            inputByteArray = outByteBuffer.array();
                            reader = new PdfReader(inputByteArray);
                        } else {
                            // Fill in acroForm
                            Map survey2AcroFieldResults = dispatcher.runSync("setAcroFieldsFromSurveyResponse", UtilMisc.toMap("surveyResponseId", surveyResponseId));
                            if (ServiceUtil.isError(survey2AcroFieldResults)) {
                                return ServiceUtil.returnError("Error setting AcroFields from SurveyResponse: ", 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 convertInMap = UtilMisc.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 convertResult = dispatcher.runSync("convertDocumentByteBuffer", convertInMap);

                    if (ServiceUtil.isError(convertResult)) {
                        return ServiceUtil.returnError("Error in Open", 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 results = ServiceUtil.returnSuccess();
            results.put("outByteBuffer", outByteBuffer);
            return results;
View Full Code Here

        GenericValue userLogin = (GenericValue) context.get("userLogin");

        try {
            //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 = delegator.findByPrimaryKeyCache("Content", UtilMisc.toMap("contentId", contentId));
                dataResourceId = content.getString("dataResourceId");
View Full Code Here

    this.document = document;
  }

  public void open () throws DocumentException
  {
    setDocument(new Document());
    //pageSize, marginLeft, marginRight, marginTop, marginBottom));

    writer = PdfWriter.getInstance(getDocument(), out);
    writer.setLinearPageMode();
View Full Code Here

      transformer.transform(src, res);

      // Add Javascript code using iText to read/update PDF stream
      // --Create a reader and a writer to tranfer/update content
      PdfReader reader = new PdfReader(fopout.toByteArray());
      Document document = new Document(reader.getPageSizeWithRotation(1));
      PdfWriter writer = PdfWriter.getInstance(document, response
          .getOutputStream());
      // --Tranfer content
      int n = reader.getNumberOfPages();
      document.open();
      PdfContentByte cb = writer.getDirectContent();
      PdfImportedPage page;
      int rotation;
      int i = 0;
      while (i < n) {
        i++;
        document.setPageSize(reader.getPageSizeWithRotation(i));
        document.newPage();
        page = writer.getImportedPage(reader, i);
        rotation = reader.getPageRotation(i);
        if (rotation == 90 || rotation == 270) {
          cb.addTemplate(page, 0, -1f, 1f, 0, 0, reader
              .getPageSizeWithRotation(i).getHeight());
        } else {
          cb.addTemplate(page, 1f, 0, 0, 1f, 0, 0);
        }
        System.out.printf("Processed page %s\n", i);
      }
      // --Add JS code
      writer
          .addJavaScript(
              "this.print({bUI: false, bSilent: true, bShrinkToFit: true});",
              false);
      // --Close document and stream
      document.close();
      writer.close();
      reader.close();
      System.out.printf("Generated in %s ms\n", (System
          .currentTimeMillis() - start));
    } catch (Exception e) {
View Full Code Here

            Logger.getLogger(InvoiceToPdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void write(Invoice invoice, OutputStream out) {
        Document document = new Document();
        try {
            // step 2:
            // we create a writer that listens to the document and directs a PDF-stream to System.out (and a txt file)
            PdfWriter.getInstance(document, out);
            // step 3: we open the document
            document.open();

            addLogo(document);

            addCompanyInfo(document);

            document.add(blankSpace());

            //TITTLE
            Paragraph p = new Paragraph("FACTURA", new Font(Font.HELVETICA, 16, Font.BOLD));
            p.setAlignment(Element.ALIGN_CENTER);
            document.add(p);

            document.add(blankSpace());
            document.add(blankSpace());

            addHeader(document, invoice);

            document.add(blankSpace());
            document.add(blankSpace());

            addDetailHeader(document);
            addDetail(document, invoice);

            document.close();

        } catch (DocumentException ex) {
            Logger.getLogger(InvoiceToPdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here

            Logger.getLogger(ReceiptFormatToPdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void write(Payment payment, OutputStream out) {
        Document document = new Document();
        try {
            // step 2:
            // we create a writer that listens to the document and directs a PDF-stream to System.out (and a txt file)
            PdfWriter.getInstance(document, out);
            // step 3: we open the document
            document.open();

            document.add(blankSpace());
            document.add(blankSpace());
            document.add(blankSpace());
            document.add(blankSpace());
            document.add(blankSpace());
            document.add(blankSpace());

            addHeader(document, payment);

            document.close();

        } catch (DocumentException ex) {
            Logger.getLogger(ReceiptFormatToPdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here

            Logger.getLogger(QuotationToPdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void write(Quotation quotation, OutputStream out) {
        Document document = new Document();
        try {
            // step 2:
            // we create a writer that listens to the document and directs a PDF-stream to System.out (and a txt file)
            PdfWriter.getInstance(document, out);
            // step 3: we open the document
            document.open();

            addLogo(document);

            addCompanyInfo(document);

            document.add(blankSpace());

            //TITTLE
            Paragraph p = new Paragraph("COTIZACION", new Font(Font.HELVETICA, 16, Font.BOLD));
            p.setAlignment(Element.ALIGN_CENTER);
            document.add(p);

            document.add(blankSpace());
            document.add(blankSpace());

            addHeader(document, quotation);

            document.add(blankSpace());
            document.add(blankSpace());

            addDetailHeader(document);
            addDetail(document, quotation);
            addFooter(document, quotation);

            document.close();

        } catch (DocumentException ex) {
            Logger.getLogger(QuotationToPdf.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
View Full Code Here

TOP

Related Classes of com.lowagie.text.Document

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.