Package com.lowagie.text

Examples of com.lowagie.text.Document


public class PDFExporter extends Exporter {

  @Override
  public void export(FacesContext facesContext, DataTable table, String filename, boolean pageOnly, int[] excludeColumns, String encodingType, MethodExpression preProcessor, MethodExpression postProcessor) throws IOException {
    try {
          Document document = new Document(PageSize.A4.rotate());
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PdfWriter.getInstance(document, baos);
          document.open();
         
          if(preProcessor != null) {
          preProcessor.invoke(facesContext.getELContext(), new Object[]{document});
        }
         
      PdfPTable pdfTable = exportPDFTable(table, pageOnly,excludeColumns, encodingType);
        document.add(pdfTable);
       
        if(postProcessor != null) {
          postProcessor.invoke(facesContext.getELContext(), new Object[]{document});
        }
       
          document.close();
       
          writePDFToResponse(((HttpServletResponse) facesContext.getExternalContext().getResponse()), baos, filename);
         
    } catch (DocumentException e) {
      throw new IOException(e.getMessage());
View Full Code Here


       }
   
   
      
      
    Document doc=new Document();
    ByteArrayOutputStream ba=new ByteArrayOutputStream();
    try {
      //ManyToOne mo=new ManyToOne();
      //process s1;
      List<process> list=main.viewRecord(temp);
     
      System.out.println(list.size());
     
      PdfWriter writer=PdfWriter.getInstance(doc, ba);
//      com.lowagie.text.Image image = com.lowagie.text.Image
//          .getInstance("c:/smi-logo.gif");
//          image.setBorder(1);
//          image.scaleAbsolute(100, 100);
//          image.setAbsolutePosition(450, 730);
//          writer.addDirectImageSimple(image);
//     
     
      doc.open();
       PdfPTable headerTable= new PdfPTable(2);
          Image ii = Image.getInstance("c:/smi-logo.gif");
          ii.setAlignment(Element.ALIGN_RIGHT);
          ii.scalePercent(25);
      
          PdfPCell cell1 = new PdfPCell(ii,false);
          cell1.setBorder(0);
         
          headerTable.addCell(cell1);
      
       //   cell = borderlessCell("Code of Doom Order Form");
         

       

Date now = new Date();
System.out.println("date--> " + now);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
String s1 = df.format(now);
         
Chunk CONNECT = new Chunk(new LineSeparator(5.5f, 95, Color.BLUE, Element.ALIGN_CENTER, 3.5f));
  //  LineSeparator UNDERLINE =new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2);

//public HeaderFooter getMyHeader(String titulo) throws ServletException { 
//    Phrase p= new Phrase(); 
//    Chunk chunkTemp = new Chunk("My Company Name\n", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL); 
//    p.add(chunkTemp); 
//    chunkTemp = new Chunk("_____________________________________________________________________________________________________", FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL); 
//    p.add(chunkTemp); 
//    HeaderFooter header = new HeaderFooter(p, false); 
//    return header; 



          headerTable.addCell(main.borderlessCell(s1));
      
//          headerTable.addCell(borderlessCell("Customer Name"));
//          headerTable.addCell(borderlessCell(c.getName()));
//          headerTable.addCell(borderlessCell("Address"));
//          headerTable.addCell(borderlessCell(c.getAddress()));
//          headerTable.addCell(borderlessCell("Phone Number"));
//          headerTable.addCell(borderlessCell(c.getPhone()));
          doc.add(headerTable);
//              Phrase phrase = new Phrase(50);
//              doc.add(phrase);
          Paragraph paragraph = new Paragraph( "");
          main.addEmptyLine(paragraph,10);
         paragraph.add(CONNECT);
          doc.add( paragraph )
         
//          Chunk c = new Chunk( text, font );
//          c.setAction( new PdfAction( new URL( url ) ) );
//          c.setUnderline(0.8f, -0.8f);
//          doc.add( c );
         
         
         
         
          PdfPTable tab=new PdfPTable(6);
        PdfPCell cell = new PdfPCell(new Paragraph("Process Details"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(new Color(20,105,160));
        cell.setColspan(6);
        tab.addCell(cell);
        tab.addCell("id");
        tab.addCell("pid");
        tab.addCell("mid");
        tab.addCell("processname");
        tab.addCell("workingsetsize");
        tab.addCell("date");
        doc.add(tab);
       
     
     
     
      PdfPTable table=new PdfPTable(i);
      Iterator it =list.iterator();
            while(it.hasNext())
            {
              Object o[]=(Object [])it.next();
             
              //                   System.out.println(o[0] + "==" + o[1]);
                 
               //  String str=(String) it.next();
                 for(int j=0; j<i; j++ )
                 {
                   System.out.println(o[j]);
                  
        //table.addCell(o[j]);//String.valueOf(list.get(i).getProcessName()));
        table.addCell(String.valueOf(o[j]));
       
      }}
            System.out.println("loop complate");
      doc.add(table);
      System.out.println("add table complate");
     
      doc.close();
      System.out.println("document complate");
     
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
View Full Code Here

                    drawable.getWidth(), drawable.getHeight());
            PageFormat pf = new PageFormat();
            pf.setOrientation(PageFormat.PORTRAIT);
            pf.setPaper(paper);
            fmt.format(pf);
            Document document = new Document(new Rectangle(
                    (float) bounds.getWidth(), (float) bounds.getHeight()));
            PdfWriter writer = PdfWriter.getInstance(document, out);
            document.open();
            for (int i = 0; i < pageStore.getPageCount(); ++i) {
                document.newPage();
                PdfContentByte pcb = writer.getDirectContent();
                Graphics2D g = pcb.createGraphics(
                        (float) pf.getWidth(), (float) pf.getHeight());
                Page page = pageStore.getPage(i);
                page.resolveForwards(context);
                page.draw(g, drawable.getX(), drawable.getY(),
                        drawable.getHeight());
                g.dispose();
            }
            document.close();
            writer.close();
            pageStore.close();
        } catch (DocumentException e) {
            throw new IOException(e.getMessage());
        }
View Full Code Here


    public void export(File file, SketchDocument doc) {
        try {
            Rectangle pageSize = new Rectangle((int)doc.getWidth(),(int)doc.getHeight());
            Document pdf = new Document(pageSize);
            PdfWriter writer = PdfWriter.getInstance(pdf, new FileOutputStream(file));
            pdf.addCreator("Leonardo Sketch");
            pdf.open();
            ExportProcessor.process(new PDFExporter(pdf), writer, doc);
            pdf.close();
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
View Full Code Here

    public void configure(Configuration conf) throws ConfigurationException {
        this.setContentLength = conf.getChild("set-content-length").getValueAsBoolean(true);
        this.mimetype = conf.getAttribute("mime-type");
        getLogger().debug("iTextSerializer mime-type:" + mimetype);
        this.document = new Document();
    }
View Full Code Here

            Set<String> selectFields = UtilMisc.toSetArray(fields);
            List<String> orderByFields = UtilMisc.toList("sequenceNum");
            List<GenericValue> 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<GenericValue> iter = compDocParts.iterator();
            int pgCnt =0;
            while (iter.hasNext()) {
                GenericValue contentAssocRevisionItemView = 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<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;
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

        Map<String, Object> 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<GenericValue> responses = delegator.findByAnd("SurveyResponseAnswer", UtilMisc.toMap("surveyResponseId", surveyResponseId));
            Iterator<GenericValue> iter = responses.iterator();
            while (iter.hasNext()) {
                String value = null;
                GenericValue surveyResponseAnswer = 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

    public void writePDF(OutputStream out) {

        // TODO: Use i18n!

        Document document = new Document();

        try {
            PdfWriter.getInstance( document,
                                   out );

            HeaderFooter footer = DroolsDocsComponentFactory.createFooter( packageData.getName() );

            document.setFooter( footer );

            document.addTitle( packageData.getName().toUpperCase() );
            document.open();

            // First page, documentation info.           
            DroolsDocsComponentFactory.createFirstPage( document,
                                                        currentDate,
                                                        packageData );

            document.newPage();

            // List index of the rules           
            document.add( new Phrase( "Table of Contents" ) );
            document.add( DroolsDocsComponentFactory.createContents( packageData.getRules() ) );

            document.newPage();

            for ( DrlRuleParser ruleData : packageData.getRules() ) {
                DroolsDocsComponentFactory.newRulePage( document,
                                                        packageData.getName(),
                                                        ruleData );
            }

        } catch ( DocumentException de ) {
            System.err.println( de.getMessage() );
        }

        document.close();
    }
View Full Code Here

  }

  public Reporte(String title, OutputStream stream){
    this.title = title;
    Float margin = new Float(30);
    document = new Document(PageSize.A4.rotate(), margin, margin, margin, margin);
    //document = new Document(PageSize.A4.rotate());
    output = new ByteArrayOutputStream();
    try {
      this.writter = getDocWritter();
    } catch (DocumentException e) {
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.