/**
  * Creates a PDF file: hello_mirrored_margins.pdf
  *
  * @param args no arguments needed
  */
 public static void main(String[] args) throws DocumentException, IOException {
   // step 1
   Document document = new Document();
   // step 2
   PdfWriter.getInstance(document, new FileOutputStream(RESULT));
   // setting page size, margins and mirrered margins
   document.setPageSize(PageSize.A5);
   document.setMargins(36, 72, 108, 180);
   document.setMarginMirroringTopBottom(true);
   // step 3
   document.open();
   // step 4
   document.add(
       new Paragraph(
           "The left margin of this odd page is 36pt (0.5 inch); "
               + "the right margin 72pt (1 inch); "
               + "the top margin 108pt (1.5 inch); "
               + "the bottom margin 180pt (2.5 inch)."));
   Paragraph paragraph = new Paragraph();
   paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
   for (int i = 0; i < 20; i++) {
     paragraph.add(
         "Hello World! Hello People! " + "Hello Sky! Hello Sun! Hello Moon! Hello Stars!");
   }
   document.add(paragraph);
   document.add(new Paragraph("The top margin 180pt (2.5 inch)."));
   // step 5
   document.close();
 }
示例#2
0
  public static void main(String[] args) throws FileNotFoundException, DocumentException {
    Document document = new Document();
    @SuppressWarnings("unused")
    PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));
    document.open();

    Paragraph paragraph1 = new Paragraph("This is Paragraph 1");
    Paragraph paragraph2 = new Paragraph("This is Paragraph 2");
    paragraph1.setIndentationLeft(80);
    paragraph1.setIndentationRight(80);
    paragraph1.setAlignment(Element.ALIGN_CENTER);
    paragraph1.setSpacingAfter(15);
    paragraph2.setSpacingBefore(15);
    paragraph2.setAlignment(Element.ALIGN_LEFT);
    Phrase phrase = new Phrase("This is a large sentence.");
    for (int count = 0; count < 10; count++) {
      paragraph1.add(phrase);
      paragraph2.add(phrase);
    }

    document.add(paragraph1);
    document.add(paragraph2);

    document.close();
  }
 public Paragraph createDescriptionParagraph(String text) {
   Chunk chunk = new Chunk(text, utils.createDefaultFont(STANDARD_FONT_SIZE, NORMAL));
   Paragraph paragraph = new Paragraph(chunk);
   paragraph.setFirstLineIndent(DESCRIPTION_FIRST_LINE_INDENT);
   paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
   return paragraph;
 }
 /**
  * Adds a link to the current paragraph.
  *
  * @since 5.0.6
  */
 public void processLink() {
   if (currentParagraph == null) {
     currentParagraph = new Paragraph();
   }
   // The link provider allows you to do additional processing
   LinkProcessor i = (LinkProcessor) providers.get(HTMLWorker.LINK_PROVIDER);
   if (i == null || !i.process(currentParagraph, chain)) {
     // sets an Anchor for all the Chunks in the current paragraph
     String href = chain.getProperty(HtmlTags.HREF);
     if (href != null) {
       for (Chunk ck : currentParagraph.getChunks()) {
         ck.setAnchor(href);
       }
     }
   }
   // a link should be added to the current paragraph as a phrase
   if (stack.isEmpty()) {
     // no paragraph to add too, 'a' tag is first element
     Paragraph tmp = new Paragraph(new Phrase(currentParagraph));
     currentParagraph = tmp;
   } else {
     Paragraph tmp = (Paragraph) stack.pop();
     tmp.add(new Phrase(currentParagraph));
     currentParagraph = tmp;
   }
 }
  private PdfPTable cuerpo(final List<String> listaHeaderTable, final Map<String, String> mapa)
      throws DocumentException {

    PdfPTable body = new PdfPTable(12);
    body.setWidthPercentage(100);
    Font colorLetra = null;
    Paragraph aliniarTexto = null;
    PdfPCell cellCuerpoHeader = null;

    // pinta los header de la tabla
    for (String valorCelda : listaHeaderTable) {
      aliniarTexto = new Paragraph();
      aliniarTexto.setAlignment(Element.ALIGN_CENTER);
      colorLetra = new Font();
      colorLetra.setColor(new BaseColor(Color.white));

      cellCuerpoHeader = new PdfPCell(new Phrase(valorCelda, colorLetra));
      cellCuerpoHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
      cellCuerpoHeader.setBackgroundColor(new BaseColor(0, 0, 0));
      cellCuerpoHeader.setBorder(Rectangle.NO_BORDER);
      cellCuerpoHeader.setColspan(12);
      body.addCell(cellCuerpoHeader);
    }

    PdfPCell cellSaltoDeLinea = new PdfPCell();
    cellSaltoDeLinea = new PdfPCell(new Phrase(" "));
    cellSaltoDeLinea.setBorder(Rectangle.NO_BORDER);
    cellSaltoDeLinea.setColspan(12);
    body.addCell(cellSaltoDeLinea);

    for (Map.Entry<String, String> entry : mapa.entrySet()) {

      String key = entry.getKey();
      String value = entry.getValue();

      PdfPCell celdaEnBlanco = new PdfPCell(new Phrase(""));
      celdaEnBlanco.setColspan(2);
      celdaEnBlanco.setBorder(0);

      aliniarTexto = new Paragraph();
      aliniarTexto.setAlignment(Element.ALIGN_CENTER);
      colorLetra = new Font();
      colorLetra.setColor(new BaseColor(Color.BLACK));

      PdfPCell celdaKey = new PdfPCell(new Phrase(key, colorLetra));
      celdaKey.setColspan(3);
      celdaKey.setBorder(0);

      PdfPCell celdaValor = new PdfPCell(new Phrase(value, colorLetra));
      celdaValor.setColspan(5);
      celdaValor.setBorder(0);

      body.addCell(celdaEnBlanco);
      body.addCell(celdaKey);
      body.addCell(celdaValor);
      body.addCell(celdaEnBlanco);
    }

    return body;
  }
示例#6
0
  public void print(String filename) throws IOException, DocumentException {
    EventTree tree = app.getTimelines().getCurrentTree();
    if (tree == null || tree.isEmpty()) return;

    ComplexEvent parent = tree.getTopSelectionParent();
    if (parent == null) return;

    // Instantiation of document object
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    // Creation of PdfWriter object
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    document.open();

    // Creation of table
    Paragraph title =
        new Paragraph(
            "A sample output from Zeitline:",
            FontFactory.getFont(FontFactory.TIMES_BOLD, 14, BaseColor.BLUE));
    title.setSpacingAfter(20);
    document.add(title);

    // Setting width rations
    PdfPTable table = new PdfPTable(3);
    float[] tableWidth = {(float) 0.2, (float) 0.12, (float) 0.68};
    table.setWidths(tableWidth);

    // Setting the header
    java.util.List<PdfPCell> headerCells =
        asList(getHeaderCell("Date"), getHeaderCell("MACB"), getHeaderCell("Short Description"));

    for (PdfPCell cell : headerCells) table.addCell(cell);

    // Setting the body
    int max = parent.countChildren();
    for (int i = 0; i < max; i++) {
      AbstractTimeEvent entry = parent.getEventByIndex(i);
      table.addCell(getBodyCell(entry.getStartTime().toString()));

      String name = entry.getName();
      if (name != null && name.length() > 5) {
        String macb = name.substring(0, 4);
        String desc = name.substring(5);

        table.addCell(getBodyCell(macb));
        table.addCell(getBodyCell(desc));
      } else {
        table.addCell("");
        table.addCell("");
      }
    }
    document.add(table);

    // Closure
    document.close();
    writer.close();
  }
 private void addNotes(Document document) throws DocumentException {
   if (!mRecipe.getNotes().equals("")) {
     document.add(new Paragraph(mContext.getString(R.string.notes), HEADER_FONT));
     addLineSeparator(document);
     Paragraph notesPara = new Paragraph(mRecipe.getNotes(), NORMAL_FONT);
     notesPara.setLeading(NORMAL_POINT);
     document.add(notesPara);
   }
 }
 private void addHeader(Document document, Examination examination) throws DocumentException {
   Paragraph p;
   p = new Paragraph("SZÁMLA", headerFont);
   document.add(p);
   p = new Paragraph("Számlaszám: " + examination.getInvoice().getInvoiceId(), boldDataFont);
   p.setAlignment(Element.ALIGN_RIGHT);
   addEmptyLine(p, 2);
   document.add(p);
 }
  private PdfPCell getCell(String value, int alignment, Font font) {
    PdfPCell cell = new PdfPCell();
    cell.setUseAscender(true);
    cell.setUseDescender(true);
    Paragraph p = new Paragraph(value, font);
    p.setAlignment(alignment);
    cell.addElement(p);

    return cell;
  }
示例#10
0
 /**
  * Creates a PdfPCell with the name of the month
  *
  * @param calendar a date
  * @param locale a locale
  * @return a PdfPCell with rowspan 7, containing the name of the month
  */
 public PdfPCell getMonthCell(Calendar calendar, Locale locale) {
   PdfPCell cell = new PdfPCell();
   cell.setColspan(7);
   cell.setBorder(PdfPCell.NO_BORDER);
   cell.setUseDescender(true);
   Paragraph p = new Paragraph(String.format(locale, "%1$tB %1$tY", calendar), bold);
   p.setAlignment(Element.ALIGN_CENTER);
   cell.addElement(p);
   return cell;
 }
示例#11
0
 public void createPdf(String dest) throws IOException, DocumentException {
   Document document = new Document();
   PdfWriter.getInstance(document, new FileOutputStream(dest));
   document.open();
   Paragraph p = new Paragraph();
   String s =
       "all text is written in red, except the letters b and g; they are written in blue and green.";
   for (int i = 0; i < s.length(); i++) {
     p.add(returnCorrectColor(s.charAt(i)));
   }
   document.add(p);
   document.close();
 }
示例#12
0
  public void setHeader(Document document, String clientName)
      throws DocumentException, IOException {

    LineSeparator line = new LineSeparator(1, 80, null, Element.ALIGN_CENTER, -5);

    Image img = Image.getInstance(getClass().getResource("img/LISLogo.png"));
    // Image img = Image.getInstance("img/LISLogo.png");
    img.scaleAbsoluteHeight(80);
    img.scaleAbsoluteWidth(200);
    img.setAlignment(Element.ALIGN_CENTER);

    Paragraph clientNameParagraph = new Paragraph();
    clientNameParagraph.setAlignment(Element.ALIGN_CENTER);
    clientNameParagraph.add(clientName);
    clientNameParagraph.setSpacingAfter(12);

    Paragraph investmentRecommendations = new Paragraph("Your Legacy Investment Income Portfolio");
    investmentRecommendations.setAlignment(Element.ALIGN_CENTER);
    investmentRecommendations.add(line);
    investmentRecommendations.setSpacingAfter(4);

    document.add(clientNameParagraph);
    document.add(investmentRecommendations);
    document.add(img);
  }
示例#13
0
 /**
  * Main method.
  *
  * @param args no arguments needed
  * @throws DocumentException
  * @throws IOException
  */
 public static void main(String[] args) throws IOException, DocumentException {
   // step 1
   Document document = new Document(PageSize.POSTCARD, 30, 30, 30, 30);
   // step 2
   PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
   // step 3
   document.open();
   // step 4
   // Create and add a Paragraph
   Paragraph p = new Paragraph("Foobar Film Festival", new Font(FontFamily.HELVETICA, 22));
   p.setAlignment(Element.ALIGN_CENTER);
   document.add(p);
   // Create and add an Image
   Image img = Image.getInstance(RESOURCE);
   img.setAbsolutePosition(
       (PageSize.POSTCARD.getWidth() - img.getScaledWidth()) / 2,
       (PageSize.POSTCARD.getHeight() - img.getScaledHeight()) / 2);
   document.add(img);
   // Now we go to the next page
   document.newPage();
   document.add(p);
   document.add(img);
   // Add text on top of the image
   PdfContentByte over = writer.getDirectContent();
   over.saveState();
   float sinus = (float) Math.sin(Math.PI / 60);
   float cosinus = (float) Math.cos(Math.PI / 60);
   BaseFont bf = BaseFont.createFont();
   over.beginText();
   over.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE);
   over.setLineWidth(1.5f);
   over.setRGBColorStroke(0xFF, 0x00, 0x00);
   over.setRGBColorFill(0xFF, 0xFF, 0xFF);
   over.setFontAndSize(bf, 36);
   over.setTextMatrix(cosinus, sinus, -sinus, cosinus, 50, 324);
   over.showText("SOLD OUT");
   over.endText();
   over.restoreState();
   // Add a rectangle under the image
   PdfContentByte under = writer.getDirectContentUnder();
   under.saveState();
   under.setRGBColorFill(0xFF, 0xD7, 0x00);
   under.rectangle(5, 5, PageSize.POSTCARD.getWidth() - 10, PageSize.POSTCARD.getHeight() - 10);
   under.fill();
   under.restoreState();
   // step 4
   document.close();
 }
 /**
  * Processes an Image.
  *
  * @param img
  * @param attrs
  * @throws DocumentException
  * @since 5.0.6
  */
 public void processImage(final Image img, final Map<String, String> attrs)
     throws DocumentException {
   ImageProcessor processor = (ImageProcessor) providers.get(HTMLWorker.IMG_PROCESSOR);
   if (processor == null || !processor.process(img, attrs, chain, document)) {
     String align = attrs.get(HtmlTags.ALIGN);
     if (align != null) {
       carriageReturn();
     }
     if (currentParagraph == null) {
       currentParagraph = createParagraph();
     }
     currentParagraph.add(new Chunk(img, 0, 0, true));
     currentParagraph.setAlignment(HtmlUtilities.alignmentValue(align));
     if (align != null) {
       carriageReturn();
     }
   }
 }
示例#15
0
 private void applyAttributes(Element e, Attributes attributes) {
   String align = attributes.getString("align");
   if ("center".equalsIgnoreCase(align)) {
     if (e instanceof Image) {
       ((Image) e).setAlignment(Image.MIDDLE);
     } else if (e instanceof Paragraph) {
       ((Paragraph) e).setAlignment(Element.ALIGN_CENTER);
     }
   }
 }
示例#16
0
  private void getTransactionHeader(ArrayList<String> docList)
      throws DocumentException, IOException {

    //        Paragraph paragraph = new Paragraph(15, "", new Font(getcalibri(),
    // 11,Font.UNDERLINE));
    //        paragraph.setAlignment(Element.ALIGN_CENTER);
    //        document.add(new Chunk(paragraph, BOLD_UNDERLINED));

    //        paragraph.setAlignment(Element.ALIGN_RIGHT);

    Chunk underline = new Chunk("Document List", new Font(getcalibri(), 11, Font.BOLD));
    underline.setUnderline(0.4f, -2f); // 0.1 thick, -2 y-location

    Paragraph paragraph = new Paragraph(25, underline);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph);

    document.add(Chunk.NEWLINE);

    PdfPTable table21 = new PdfPTable(1);
    // table1.setWidths(new int[]{24, 24, 2});
    table21.setTotalWidth(507);
    table21.setLockedWidth(true);
    table21.getDefaultCell().setFixedHeight(20);
    table21.getDefaultCell().setBorder(Rectangle.BOTTOM);
    table21.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);

    Iterator<String> it = docList.iterator();
    int i = 1;
    while (it.hasNext()) {
      PdfPCell secondCell =
          new PdfPCell(
              new Phrase(25, i + ".  " + it.next(), new Font(getcalibri(), 11, Font.NORMAL)));
      secondCell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
      secondCell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
      secondCell.setBorder(Rectangle.NO_BORDER);
      secondCell.setPadding(15);
      table21.addCell(secondCell);
      i++;
    }

    table21.writeSelectedRows(0, -1, 34, 700, writer.getDirectContent());
  }
示例#17
0
 /**
  * Creates a PdfPCell for a specific day
  *
  * @param calendar a date
  * @param locale a locale
  * @return a PdfPCell
  */
 public PdfPCell getDayCell(Calendar calendar, Locale locale) {
   PdfPCell cell = new PdfPCell();
   // set the event to draw the background
   cell.setCellEvent(cellBackground);
   // set the event to draw a special border
   if (isSunday(calendar) || isSpecialDay(calendar)) cell.setCellEvent(roundRectangle);
   cell.setPadding(3);
   cell.setBorder(PdfPCell.NO_BORDER);
   // set the content in the language of the locale
   Chunk chunk = new Chunk(String.format(locale, "%1$ta", calendar), small);
   chunk.setTextRise(8);
   // a paragraph with the day
   Paragraph p = new Paragraph(chunk);
   // a separator
   p.add(new Chunk(new VerticalPositionMark()));
   // and the number of the day
   p.add(new Chunk(String.format(locale, "%1$te", calendar), normal));
   cell.addElement(p);
   return cell;
 }
示例#18
0
  private void addIngredient(Yeast yeast, Document document) throws DocumentException {
    Image image = loadDrawable(R.drawable.yeast_cap, 30);

    Paragraph namePara = new Paragraph();
    namePara.setSpacingBefore(0);
    namePara.add(new Phrase("1 Pkg. " + yeast.getName() + "\n", NORMAL_FONT));
    namePara.add(new Phrase("\n", new Font(Font.FontFamily.TIMES_ROMAN, 2)));
    namePara.add(new Phrase(IngredientInfo.getInfo(yeast), SMALL_FONT));

    PdfPTable table = new PdfPTable(new float[] {40, 400});
    table.setHorizontalAlignment(Element.ALIGN_LEFT);
    PdfPCell cellOne = new PdfPCell(image);
    cellOne.setBorder(Rectangle.NO_BORDER);
    PdfPCell cellTwo = new PdfPCell(namePara);
    cellTwo.setBorder(Rectangle.NO_BORDER);

    table.addCell(cellOne);
    table.addCell(cellTwo);
    document.add(table);
  }
示例#19
0
  private Map<String, Object> getMapSol() {

    final HashMap<String, Object> mapCarac = new HashMap<String, Object>();

    final Paragraph paraText = new Paragraph();
    paraText.setAlignment(Element.ALIGN_CENTER);

    final Font colorLetra = new Font();
    colorLetra.setColor(new BaseColor(Color.white));

    final Font colorRow = new Font();
    colorRow.setColor(new BaseColor(39, 40, 41));

    mapCarac.put(VUTramConstants.KEY_COLORF, colorLetra);
    mapCarac.put(VUTramConstants.KEY_PARG, paraText);
    mapCarac.put(VUTramConstants.KEY_COLORH, new BaseColor(57, 60, 62));
    mapCarac.put(VUTramConstants.KEY_COLORR, new BaseColor(84, 84, 84));
    mapCarac.put(VUTramConstants.KEY_COLORRF, colorRow);

    return mapCarac;
  }
  public ColumnText generateTableOfContent(ITextContext context) {
    ColumnText ct = new ColumnText(null);

    Styles styles = context.styles();
    Chunk CONNECT = connectChunk(styles);
    Paragraph paragraph = new Paragraph();
    paragraph.setSpacingBefore(20.0f); // first paragraph only

    ct.addElement(new Paragraph("Table of content", styles.sectionTitleFontForLevel(1)));
    ct.addElement(new Paragraph(""));

    Font entryFont = styles.getFontOrDefault(TOC_ENTRY_FONT);
    TableOfContents tableOfContents = context.tableOfContents();
    for (TableOfContents.Entry entry : tableOfContents.getEntries()) {
      // if (entry.isExtra())
      //    continue;

      Chunk chunk = new Chunk(entry.getText(), entryFont);
      paragraph.add(chunk);
      paragraph.add(CONNECT);
      paragraph.add(new Chunk("" + entry.getFormattedPageNumber(), entryFont));

      float indent = 10.0f * entry.getLevel();
      paragraph.setIndentationLeft(indent);

      ct.addElement(paragraph);
      paragraph = new Paragraph();
    }
    return ct;
  }
示例#21
0
  private static Paragraph createCleanParagraph(String txt1, float fontSize1, boolean bold1) {
    Phrase phrase = new Phrase(txt1);
    phrase.getFont().setSize(fontSize1);
    if (bold1) {
      phrase.getFont().setStyle(Font.BOLD);
      phrase.setLeading(fontSize1);
    }
    Paragraph paragraph = new Paragraph(phrase);

    paragraph.setLeading(fontSize1);
    paragraph.setSpacingBefore(0);
    paragraph.setSpacingAfter(0);
    paragraph.setExtraParagraphSpace(0);
    paragraph.setFirstLineIndent(0);
    paragraph.setIndentationLeft(0);
    paragraph.setIndentationRight(0);
    paragraph.setAlignment(Rectangle.ALIGN_CENTER);

    return paragraph;
  }
示例#22
0
  public void addTitlePage(Document document, CustomerOrder customerOrder)
      throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);
    Image image = null;
    try {
      image = Image.getInstance("img/gfcLogo.jpg");
      image.scaleAbsolute(100f, 100f);
      image.setAlignment(Image.ALIGN_LEFT);
    } catch (IOException e) {
      e.printStackTrace();
    }
    document.add(image);
    // Lets write a big header
    Phrase invoice = new Phrase();
    invoice.add(new Chunk("Generation For Christ", companyName));
    invoice.add(new Chunk("                                   Invoice", companyName));
    preface.add(new Paragraph(invoice));
    // preface.add(new Paragraph( "));

    preface.add(new Paragraph("                      We Make Disciples", companySlogan));
    // preface.add(new Paragraph( "                Invoice", companyName));
    // addEmptyLine(preface, 1);
    Date date = new Date();
    String dateFormat = new SimpleDateFormat("dd/MM/yyyy").format(date);
    preface.add(
        new Paragraph(
            "                                                                                                                                         DATE:   "
                + dateFormat,
            details));
    preface.add(
        new Paragraph(
            "25 James Street, Dandenong                                                                                   ORDER ID:    "
                + customerOrder.getOrderId(),
            details));
    preface.add(new Paragraph("Melbourne, Victoria, 3175", details));
    preface.add(new Paragraph("Phone # ", details));

    // Will create: Report generated by: _name, _date
    // preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " +
    // new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    //         smallBold));
    // addEmptyLine(preface, 3);
    // preface.add(new Paragraph("This document contains confidential information of GFC's member",
    //         smallBold));

    document.add(preface);
    // Start a new page
    // document.newPage();
  }
 /** @see com.itextpdf.text.xml.simpleparser.SimpleXMLDocHandler#text(java.lang.String) */
 public void text(String content) {
   if (skipText) return;
   if (currentParagraph == null) {
     currentParagraph = createParagraph();
   }
   if (!insidePRE) {
     // newlines and carriage returns are ignored
     if (content.trim().length() == 0 && content.indexOf(' ') < 0) {
       return;
     }
     content = HtmlUtilities.eliminateWhiteSpace(content);
   }
   Chunk chunk = createChunk(content);
   currentParagraph.add(chunk);
 }
  private void produireOrdreSortieBody(
      OrdreSortie os, Document doc, Date dateOrdre, int noChapitre, int noOrdre, String objet) {
    try {
      Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 8);
      Font bf12b = new Font(Font.FontFamily.TIMES_ROMAN, 7);
      Font bf12i = new Font(Font.FontFamily.TIMES_ROMAN, 7, Font.ITALIC);
      Font bf10 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
      Font bf1 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
      Font bf1b = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
      Font fontEntete = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
      Font fontBig = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD);
      Font fontBig2 = new Font(Font.FontFamily.TIMES_ROMAN, 14);

      //            float relativewidth[] = {4, 2, 6};
      //            PdfPTable firstTable = new PdfPTable(relativewidth);
      //            firstTable.setWidthPercentage(100);
      //            Phrase post = new Phrase("POSTE COMPTABLE
      // ........................................\n", fontEntete);
      //            Phrase postEng = new Phrase("ACCOUNTING POST\n
      // .................................................................", bf10);
      //            Phrase ph1 = new Phrase();
      //            ph1.add(post);
      //            ph1.add(postEng);
      //            PdfPCell cell1 = new PdfPCell(ph1);
      //            cell1.setBorderColor(BaseColor.WHITE);
      //            cell1.setColspan(2);
      //            //cell1.setPaddingBottom(2f);
      //            cell1.setPaddingTop(2f);
      //            firstTable.addCell(cell1);
      //
      //            Phrase code = new Phrase("CODE POSTE COMPTABLE\n", fontEntete);
      //            Phrase codeEng = new Phrase("ACCOUNTING POST CODE\n", bf10);
      //            Phrase codeA = new Phrase("CODE ANNEXE...............................\n",
      // fontEntete);
      //            Phrase codeAe = new Phrase("ANNEXE CODE", bf10);
      //            ph1 = new Phrase();
      //            ph1.add(code);
      //            ph1.add(codeEng);
      //            ph1.add(new Phrase("\n"));
      //            ph1.add(codeA);
      //            ph1.add(codeAe);
      //            cell1 = new PdfPCell(ph1);
      //            cell1.setRowspan(3);
      //            cell1.setBorderColor(BaseColor.WHITE);
      //            cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);
      //            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
      //            //cell1.setPaddingBottom(2f);
      //            cell1.setPaddingTop(2f);
      //            firstTable.addCell(cell1);
      //
      //            Phrase serv = new Phrase("SERVICE COMPTABLE AUPRES DE ..............\n",
      // fontEntete);
      //            Phrase serve = new Phrase("ACCOUNTING SERVICE TO \n
      // ...................................................................", bf10);
      //
      //            ph1 = new Phrase();
      //            ph1.add(serv);
      //            ph1.add(serve);
      //            cell1 = new PdfPCell(ph1);
      //            cell1.setBorderColor(BaseColor.WHITE);
      //            //cell1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
      //            cell1.setColspan(2);
      //            //cell1.setPaddingBottom(2f);
      //            cell1.setPaddingTop(2f);
      //            firstTable.addCell(cell1);
      //
      //            Phrase num = new Phrase("Numéro d'ordre au journal d'annexe :
      // ..................\n", fontEntete);
      //            Phrase nume = new Phrase("Order number in the journal of the store ", bf10);
      //            Chunk underline = new Chunk("               ", fontEntete);
      //            underline.setUnderline(0.2f, -2f);
      //            ph1 = new Phrase();
      //            ph1.add(num);
      //            ph1.add(nume);
      //            ph1.add(underline);
      //            cell1 = new PdfPCell();
      //            cell1.setBorderColor(BaseColor.WHITE);
      //            cell1.addElement(ph1);
      //            cell1.setColspan(2);
      //            // cell1.setPaddingBottom(2f);
      //            cell1.setPaddingTop(2f);
      //            firstTable.addCell(cell1);
      //            doc.add(firstTable);
      PdfPCell cell1;
      float relativewidth2[] = {5, 9};
      PdfPTable or = new PdfPTable(relativewidth2);
      or.setWidthPercentage(100);
      cell1 = new PdfPCell();
      cell1.setBorderColor(BaseColor.WHITE);
      or.addCell(cell1);
      Chunk ordre = new Chunk("ORDRE DE SORTIE N", fontBig);
      Chunk expo = new Chunk("o", fontEntete);
      expo.setTextRise(5f);
      Chunk un = new Chunk(String.valueOf(noOrdre) + "                 \n", fontBig);
      //    Chunk in = new Chunk("INCOMING ORDER No.", fontBig2);
      Chunk under = new Chunk("                            \n", fontBig);
      under.setUnderline(0.5f, -2f);
      Phrase ph = new Phrase();
      ph.add(ordre);
      ph.add(expo);
      ph.add(un);
      //   ph.add(in);
      ph.add(under);
      cell1 = new PdfPCell();
      cell1.setBorderColor(BaseColor.WHITE);
      cell1.addElement(ph);
      or.addCell(cell1);
      doc.add(or);
      StringBuilder stb = new StringBuilder();
      stb.append("EXERCICE ...................................................................\n")
          .append("CHAPITRE " + String.valueOf(noChapitre) + "                        DU BUDGET\n")
          .append("IMPUTATION BUDGETAIRE : ..................................\n")
          .append(
              "........................................................................................\n")
          .append(
              "........................................................................................\n")
          .append(
              "........................................................................................\n");
      Paragraph exer = new Paragraph(stb.toString(), bf10);
      exer.setAlignment(Element.ALIGN_CENTER);
      doc.add(exer);
      Calendar ca = Calendar.getInstance();
      // ca.setTime(dateFacture);
      String month = ca.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.FRANCE);
      month = WordUtils.capitalize(month);
      int year = ca.get(Calendar.YEAR);
      int day = ca.get(Calendar.DATE);
      Chunk seront =
          new Chunk(
              "Seront portés en sortie, dans les écritures du dépositaire comptable, les matières et objets ci-dessous désignés",
              bf12);
      exer = new Paragraph(seront);
      exer.setAlignment(Element.ALIGN_CENTER);
      doc.add(exer);
      Paragraph objetp = new Paragraph(new Chunk(objet, fontEntete));
      objetp.setAlignment(Element.ALIGN_CENTER);
      doc.add(objetp);

      doc.add(new Chunk("\n"));
      float relativewidth3[] = {1, 2, 7, 3, 3, 3, 4, 4, 3};
      PdfPTable table = new PdfPTable(relativewidth3);
      table.setWidthPercentage(100);
      // table.setHeaderRows(2);
      PdfPCell cell = new PdfPCell();
      Paragraph par = new Paragraph("NUMEROS", bf12b);
      par.setAlignment(Element.ALIGN_CENTER);
      Chunk numer = new Chunk();
      cell.addElement(par);
      cell.setColspan(2);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("DESIGNATION DES MATIERES ET OBJETS\n", bf12b);
      Chunk eng = new Chunk("DESCRIPTION OF MATERIAL", bf12i);
      Paragraph p = new Paragraph();
      p.add(numer);
      p.add(eng);
      p.setAlignment(Element.ALIGN_CENTER);
      cell = new PdfPCell();
      cell.addElement(p);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cell.setRowspan(2);
      table.addCell(cell);

      numer = new Chunk("ESPECES\nDES\nUNITES\n", bf12b);
      eng = new Chunk("UNIT OF\n MEASURE", bf12i);
      cell = new PdfPCell();
      p = new Paragraph();
      p.add(numer);
      p.add(eng);
      p.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(p);
      cell.setRowspan(2);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("QUANTITES\n", bf12b);
      eng = new Chunk("QUANTITIES", bf12i);
      p = new Paragraph();
      p.add(numer);
      p.add(eng);
      p.setAlignment(Element.ALIGN_CENTER);
      cell = new PdfPCell();
      cell.addElement(p);
      cell.setRowspan(2);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("PRIX DE L'UNITE\n", bf12b);
      cell = new PdfPCell();
      eng = new Chunk("UNIT PRICE", bf12i);
      p = new Paragraph();
      p.add(numer);
      p.add(eng);
      p.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(p);
      cell.setRowspan(2);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("VALEURS", bf12b);
      cell = new PdfPCell();
      p = new Paragraph(numer);
      p.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(p);
      cell.setColspan(2);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("NUMERO DE LA PIECE\n JUSTIFICATIVE\n D'ENTREE CORRESPONDANT", bf12b);
      cell = new PdfPCell();
      p = new Paragraph(numer);
      p.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(p);
      cell.setRowspan(2);
      cell.setRotation(90);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("DE FOLIO\n DU GRAND LIVRE JOURNAL", bf12b);
      cell = new PdfPCell();
      p = new Paragraph(numer);
      p.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(p);
      cell.setRotation(90);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("D'ORDRE\n DE LA CLASSE\n DE NOMENCLATURE\n SOMMAIRE", bf12b);
      cell = new PdfPCell();
      p = new Paragraph(numer);
      p.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(p);
      cell.setRotation(90);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("PARTIELLES", bf12b);
      cell = new PdfPCell();
      p = new Paragraph(numer);
      p.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(p);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      numer = new Chunk("PAR CLASSE DE LA NOMENCLATURE SOMMAIRE", bf12b);
      cell = new PdfPCell();
      p = new Paragraph(numer);
      p.setAlignment(Element.ALIGN_CENTER);
      cell.addElement(p);
      cell.setHorizontalAlignment(Element.ALIGN_MIDDLE);
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      table.addCell(cell);

      List<Affectation> affectations1 = affectationDao.findAllByOrdreSortie(os);
      System.out.println("=================================== Avant le merge");
      System.out.println(affectations1);
      List<Affectation> affectations = affectationDao.findAllByOrdreSortie(os);
      // List<Commande> commandes = commandeDao.findByBon(bc);
      //            if (os.getEtatType() == EtatType.Encour) {
      //                for (Affectation affectation : affectations) {
      //                    Article art = affectation.getArticle();
      //                    int qteI = art.getQuantite();
      //                    int qteF = affectation.getNombre();
      //                    art.setQuantite(-qteI + qteF);
      //                    articleDao.update(art);
      //                }
      //            }
      System.out.println(
          "\n\n\n JE SUIS ICI ============= " + affectations.size() + "pour l'id" + os.getId());
      System.out.println(affectations);
      System.out.println("\n========================================\n");
      Set<String> cat = new TreeSet<>();
      cat = getCategories(affectations);
      Map<String, List<Affectation>> data = transform(affectations);
      double prixFinal = 0.0;
      int index = 1;
      for (String cat1 : cat) {
        double prixTemp = 0.0;
        List<Affectation> temp = data.get(cat1);
        Collections.sort(
            temp,
            new Comparator<Affectation>() {

              @Override
              public int compare(Affectation t, Affectation t1) {
                return t.getArticle()
                    .getDesignation()
                    .compareToIgnoreCase(t1.getArticle().getDesignation());
              }
            });

        for (int i = 0; i < temp.size(); i++) {
          // int artQ = temp.get(i).getArticle().getQuantite();
          int nombrCommande = temp.get(i).getNombre();
          // Article art = new Article();
          // art = temp.get(i).getArticle();
          // art.setQuantite(artQ+nombrCommande);
          // articleDao.update(art);
          table.addCell(Util.createDotedValueCell("", bf12));
          table.addCell(Util.createDotedValueCell(temp.get(i).getCategorie(), bf12));
          table.addCell(Util.createDotedValueCell(temp.get(i).getArticle().getDesignation(), bf12));
          table.addCell(
              Util.createDotedValueCell(temp.get(i).getArticle().getConditionnement(), bf12));
          table.addCell(Util.createDotedValueCell(String.valueOf(nombrCommande), bf12));
          table.addCell(Util.createDotedValueCell(String.valueOf(temp.get(i).getPrix()), bf12));
          table.addCell(
              Util.createDotedValueCell(
                  String.valueOf(nombrCommande * temp.get(i).getPrix()), bf12));
          prixTemp += temp.get(i).getNombre() * temp.get(i).getPrix();
          if (i != temp.size() - 1) {
            table.addCell(Util.createDotedValueCell("", bf12));
            table.addCell(Util.createDotedValueCell("", bf12));
          } else {

            table.addCell(
                Util.createDotedValueCell(String.valueOf((int) Math.floor(prixTemp)), bf12));
            table.addCell(Util.createDotedValueCell("", bf12));
          }
        }
        prixFinal += prixTemp;
      }
      p = new Paragraph("TOTAL", fontEntete);
      cell1 = new PdfPCell();
      p.setAlignment(Element.ALIGN_CENTER);
      cell1.addElement(p);
      cell1.setColspan(6);
      table.addCell(cell1);
      p = new Paragraph(String.valueOf((int) Math.floor(prixFinal)), fontEntete);
      cell1 = new PdfPCell();
      p.setAlignment(Element.ALIGN_CENTER);
      cell1.addElement(p);
      // cell1.setColspan(6);
      table.addCell(cell1);
      p = new Paragraph(String.valueOf((int) Math.floor(prixFinal)), fontEntete);
      cell1 = new PdfPCell();
      p.setAlignment(Element.ALIGN_CENTER);
      cell1.addElement(p);
      // cell1.setColspan(6);
      table.addCell(cell1);

      table.completeRow();

      doc.add(table);
      int nombre = affectations.size();
      int prix = (int) Math.floor(prixFinal);
      String prixS = FrenchNumberToWords.convert(prix);
      Chunk arete = new Chunk("Arrêté le présent ordre de sortie à ", bf1);
      String nomc = FrenchNumberToWords.convert(nombre);
      Chunk art = new Chunk(nombre + " (" + nomc.toUpperCase() + ")", bf1b);
      Chunk article = new Chunk(" article(s), évalué(s) à la somme de: ", bf1);
      Chunk prixL = new Chunk(prixS.toUpperCase() + " FRANCS CFA", bf1b);
      p = new Paragraph();
      p.add(arete);
      p.add(art);
      p.add(article);
      p.add(prixL);
      doc.add(p);
      doc.add(new Chunk("\n"));

      float relativewidth4[] = {6, 1, 6};
      PdfPTable firstTable;
      firstTable = new PdfPTable(relativewidth4);
      firstTable.setWidthPercentage(100);
      // firstTable.ke
      firstTable.keepRowsTogether(0, firstTable.getLastCompletedRowIndex());
      Calendar c = Calendar.getInstance();
      c.setTime(dateOrdre);
      String moi = c.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.FRANCE);
      moi = WordUtils.capitalize(moi);
      int annee = c.get(Calendar.YEAR);
      int jour = c.get(Calendar.DATE);
      numer =
          new Chunk(
              " Le dépositaire comptable délivrera et portera en sortie dans ses écritures les matièrs et objets désignés ci dessus \n",
              bf1);
      Chunk date = new Chunk(" A Douala , le ", fontEntete);
      Chunk value = new Chunk(jour + " " + moi + " " + annee + "\n", fontEntete);
      Chunk ordo = new Chunk("L'Odonnateur-Matières", fontEntete);
      p = new Paragraph();
      p.add(numer);
      p.add(date);
      p.add(value);
      p.add(ordo);
      p.setAlignment(Element.ALIGN_JUSTIFIED);
      cell1 = new PdfPCell();
      cell1.addElement(p);
      cell1.setBorderColor(BaseColor.WHITE);
      cell1.setVerticalAlignment(Element.ALIGN_CENTER);
      cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
      firstTable.addCell(cell1);
      cell1 = new PdfPCell();
      cell1.setBorderColor(BaseColor.WHITE);
      firstTable.addCell(cell1);

      // numer = new Chunk("\n");
      // ordo = new Chunk("\n    DECLARATION DE PRISE EN CHARGE\n", fontEntete);
      numer =
          new Chunk(
              "     Les matières et objets désignés ci-dessus ont été délivrés et portés en sortie\n",
              bf1);
      Chunk chef = new Chunk("Le Dépositaire Comptable", fontEntete);
      p = new Paragraph();
      // p.add(ordo);
      p.add(numer);
      p.add(date);
      p.add(value);
      // p.add(ordo);
      p.add(chef);
      p.setAlignment(Element.ALIGN_JUSTIFIED);
      cell1 = new PdfPCell();
      cell1.addElement(p);
      cell1.setBorderColor(BaseColor.WHITE);
      cell1.setVerticalAlignment(Element.ALIGN_CENTER);
      cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
      firstTable.addCell(cell1);
      doc.add(firstTable);
      if (os.getEtatType() != EtatType.acheve) {
        os.setEtatType(EtatType.acheve);
        ordreSortieDao.update(os);
      }
    } catch (DocumentException | DataAccessException ex) {
      Logger.getLogger(CommandeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
示例#25
0
  public void export(
      HttpServletResponse response, Long id, List<DemandeValidationConsoTempsAccPers> dctap) {

    try {
      Connection con = ds.getConnection();
      Statement select = con.createStatement();
      ResultSet rs = select.executeQuery("SELECT user.* FROM user where id = " + id);
      Document document = new Document(PageSize.A4);

      try {
        OutputStream out = response.getOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, out);
        writer.setViewerPreferences(PdfWriter.PageLayoutSinglePage | PdfWriter.PageModeUseThumbs);

        document.open();

        rs.last();
        String eleve = "Nom : " + rs.getString("nom");
        eleve += "\nPrénom : " + rs.getString("prenom");
        int idClasse = rs.getInt("idClasse");
        rs.beforeFirst();
        ResultSet rs2 = select.executeQuery("SELECT classe.* from classe where id = " + idClasse);
        rs2.last();
        eleve += "\nClasse : " + rs2.getString("libelle") + "\n\n\n";
        rs2.beforeFirst();

        Paragraph paragraph = new Paragraph(eleve);
        paragraph.setAlignment(Element.ALIGN_LEFT);
        document.add(paragraph);

        com.itextpdf.text.Font fontbold = FontFactory.getFont("Times-Roman", 18, Font.BOLD);
        paragraph = new Paragraph("Les demandes de validations\n\n", fontbold);
        paragraph.setAlignment(Element.ALIGN_CENTER);
        document.add(paragraph);

        int timeTT = 0, timeVal = 0, timeAtt = 0, timeRef = 0;
        for (int i = 0; i < dctap.size(); i++) {
          timeTT += dctap.get(i).getMinutes();
          if (dctap.get(i).getEtat() == 1 || dctap.get(i).getEtat() == 32) {
            timeVal += dctap.get(i).getMinutes();
          } else if (dctap.get(i).getEtat() == 2
              || dctap.get(i).getEtat() == 8
              || dctap.get(i).getEtat() == 64) {
            timeRef += dctap.get(i).getMinutes();
          } else if (dctap.get(i).getEtat() == 0
              || dctap.get(i).getEtat() == 4
              || dctap.get(i).getEtat() > 1023) {
            timeAtt += dctap.get(i).getMinutes();
          }
        }
        double timeTTpercent = timeVal,
            timeValPercent = timeVal,
            timeAttPercent = timeAtt,
            timeRefPercent = timeRef;
        timeTTpercent =
            Math.round((timeTTpercent / (72 * 60) * 100) * Math.pow(10.0, 2)) / Math.pow(10.0, 2);
        timeValPercent =
            Math.round(((timeValPercent / timeTT) * 100) * Math.pow(10.0, 2)) / Math.pow(10.0, 2);
        timeAttPercent =
            Math.round(((timeAttPercent / timeTT) * 100) * Math.pow(10.0, 2)) / Math.pow(10.0, 2);
        timeRefPercent =
            Math.round(((timeRefPercent / timeTT) * 100) * Math.pow(10.0, 2)) / Math.pow(10.0, 2);

        PdfPTable table = new PdfPTable(4);

        PdfPCell c1 =
            new PdfPCell(
                new Phrase(
                    "Temps total effectué (72h)",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, com.itextpdf.text.Font.BOLD)));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(7);
        table.addCell(c1);
        c1 =
            new PdfPCell(
                new Phrase(
                    "Temps total validé",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, com.itextpdf.text.Font.BOLD)));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(7);
        table.addCell(c1);
        c1 =
            new PdfPCell(
                new Phrase(
                    "Temps total en attente",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, com.itextpdf.text.Font.BOLD)));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(7);
        table.addCell(c1);
        c1 =
            new PdfPCell(
                new Phrase(
                    "Temps total refusé",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 15, com.itextpdf.text.Font.BOLD)));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(7);
        table.addCell(c1);

        table.setHeaderRows(1);

        c1 =
            new PdfPCell(
                new Phrase((timeTT / 60 - (timeTT % 60 / 60)) + "h " + (timeTT % 60) + "min"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 =
            new PdfPCell(
                new Phrase((timeVal / 60 - (timeVal % 60 / 60)) + "h " + (timeVal % 60) + "min"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 =
            new PdfPCell(
                new Phrase((timeAtt / 60 - (timeAtt % 60 / 60)) + "h " + (timeAtt % 60) + "min"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 =
            new PdfPCell(
                new Phrase((timeRef / 60 - (timeRef % 60 / 60)) + "h " + (timeRef % 60) + "min"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);

        c1 = new PdfPCell(new Phrase(timeTTpercent + "%"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(timeValPercent + "%"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(timeAttPercent + "%"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);
        c1 = new PdfPCell(new Phrase(timeRefPercent + "%"));
        c1.setHorizontalAlignment(Element.ALIGN_CENTER);
        c1.setPaddingBottom(4);
        table.addCell(c1);

        document.add(table);

      } catch (DocumentException de) {
        de.printStackTrace();
      } catch (IOException ioe) {
        ioe.printStackTrace();
      }
      document.close();

    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
  private void produceBspTable(BonSortie bs, Document doc) {
    try {
      Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 12);
      Font bf1 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
      Font fontEntete = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
      List<Affectation> affectations = affectationDao.findByBonSortie(bs);

      doc.add(new Chunk("\n\n"));
      Chunk ch1 = new Chunk("BON DE SORTIE PROVISOIRE", bf12);
      Paragraph p1 = new Paragraph(ch1);
      p1.setAlignment(Element.ALIGN_CENTER);
      doc.add(p1);
      Chunk ch2 = new Chunk("DEMANDE DE MATERIEL (1)", bf1);
      Paragraph p2 = new Paragraph(ch2);
      p2.setAlignment(Element.ALIGN_CENTER);
      doc.add(p2);
      doc.add(new Chunk("\n\n"));

      float relativewiths[] = {2, 2, 3, 3, 7, 3, 2, 3, 3, 4};
      PdfPTable table = new PdfPTable(relativewiths);
      table.setWidthPercentage(100);
      Chunk ch = new Chunk(" N", bf1);
      Chunk expo = new Chunk("o", bf1);
      expo.setTextRise(4f);
      Chunk ch3 = new Chunk("d'ordre", bf1);
      Phrase ph = new Phrase(ch);
      ph.add(expo);
      ph.add(ch3);
      PdfPCell cellex = new PdfPCell(ph);
      cellex.setHorizontalAlignment(Element.ALIGN_CENTER);
      cellex.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cellex.setPaddingBottom(4f);
      cellex.setPaddingTop(5f);
      cellex.setBorderWidth(0.01f);
      table.addCell(cellex);

      Chunk ch4 = new Chunk(" N", bf1);
      Chunk expo1 = new Chunk("o", bf1);
      expo.setTextRise(4f);
      Chunk ch5 = new Chunk("NS", bf1);
      Phrase ph1 = new Phrase(ch4);
      ph1.add(expo1);
      ph1.add(ch5);

      cellex = new PdfPCell(ph1);
      cellex.setHorizontalAlignment(Element.ALIGN_CENTER);
      cellex.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cellex.setPaddingBottom(4f);
      cellex.setPaddingTop(5f);
      cellex.setBorderWidth(0.01f);
      table.addCell(cellex);

      table.addCell(Util.createBonDefaultFHeader("CODE MERCURIAL", bf1));
      table.addCell(Util.createBonDefaultFHeader("DATE D'ENT AU MAG", bf1));
      table.addCell(
          Util.createBonDefaultFHeader("DESIGNATION DES MATIERES, DENREES ET OBJETS", bf1));
      table.addCell(Util.createBonDefaultFHeader("QTE DEMANDEE", bf1));
      table.addCell(Util.createBonDefaultFHeader("QTE EN STOCK", bf1));
      table.addCell(Util.createBonDefaultFHeader("QTE ACCORDEE", bf1));
      Chunk che = new Chunk(" N", bf1);
      Chunk expoa = new Chunk("o", bf1);
      expoa.setTextRise(4f);
      Chunk chr = new Chunk(" FICHE DEMANDEUR", bf1);
      Phrase phf = new Phrase(che);
      phf.add(expoa);
      phf.add(chr);
      cellex = new PdfPCell(phf);
      cellex.setHorizontalAlignment(Element.ALIGN_CENTER);
      cellex.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cellex.setPaddingBottom(4f);
      cellex.setPaddingTop(5f);
      cellex.setBorderWidth(0.01f);
      table.addCell(cellex);

      Chunk cho = new Chunk(" OBSERVATION ET/OU N", bf1);
      Chunk expov = new Chunk("o", bf1);
      expov.setTextRise(5f);
      Chunk chg = new Chunk(" DE SERIE", bf1);
      Phrase phs = new Phrase(cho);
      phs.add(expov);
      phs.add(chg);
      table.addCell(new PdfPCell(phs));

      int i = 1;
      for (Affectation af : affectations) {

        table.addCell(Util.createBonDefaultFHeader(String.valueOf(i++), bf1));
        table.addCell(
            Util.createBonDefaultFHeader(
                af.getArticle().getCategorie().getNomenclatureSommaire(), bf1));
        table.addCell(Util.createBonDefaultFHeader(af.getArticle().getReference(), bf1));
        table.addCell(Util.createBonDefaultFHeader("", bf1));
        table.addCell(Util.createBonDefaultFHeader(af.getArticle().getDesignation(), bf1));
        table.addCell(Util.createBonDefaultFHeader(af.getQteDemandee() + "", bf1));
        table.addCell(Util.createBonDefaultFHeader(af.getArticle().getQuantite() + "", bf1));
        table.addCell(Util.createBonDefaultFHeader(af.getNombre() + "", bf1));
        table.addCell(Util.createBonDefaultFHeader("", bf1));
        table.addCell(Util.createBonDefaultFHeader(af.getObservation(), bf1));
        Article article = af.getArticle();
        article.setQuantite(article.getQuantite() - af.getNombre());
        articleDao.update(article);
      }

      doc.add(table);

      doc.add(new Chunk("\n"));

      float widths[] = {4, 5, 4};
      PdfPTable signature = new PdfPTable(widths);
      signature.setWidthPercentage(100);
      Chunk s1 = new Chunk("LE DEMANDEUR\n", bf1);
      Chunk s2 = new Chunk(bs.getPersonnel().getNom(), bf1);
      Paragraph para = new Paragraph(s1);
      para.add(s2);
      PdfPCell cell = new PdfPCell(para);
      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
      cell.setBorderColor(BaseColor.WHITE);
      // cell.se
      signature.addCell(cell);

      para = new Paragraph("AVIS ET SIGNATURE DE L'ORDONNATEUR-MATIERES OU SON REPRESENTANTS", bf1);
      cell = new PdfPCell(para);
      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
      cell.setBorderColor(BaseColor.WHITE);
      signature.addCell(cell);

      para = new Paragraph("LE COMPTABLE-MATIERES", bf1);
      cell = new PdfPCell(para);
      cell.setHorizontalAlignment(Element.ALIGN_LEFT);
      cell.setBorderColor(BaseColor.WHITE);
      signature.addCell(cell);
      doc.add(signature);

      doc.add(new Chunk("\n", bf1));
      PdfPTable date = new PdfPTable(widths);
      date.setWidthPercentage(100);
      PdfPCell cell1 =
          new PdfPCell(
              new Paragraph(
                  new Chunk(
                      "A ............................... Le ............................\n", bf1)));
      cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
      cell1.setBorderColor(BaseColor.WHITE);
      date.addCell(cell1);

      cell1 =
          new PdfPCell(
              new Paragraph(
                  new Chunk(
                      "A .............................. Le ..............................\n",
                      bf1)));
      cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
      cell1.setBorderColor(BaseColor.WHITE);
      date.addCell(cell1);

      cell1 =
          new PdfPCell(
              new Paragraph(
                  new Chunk(
                      "A .............................. Le ...............................\n",
                      bf1)));
      cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
      cell1.setBorderColor(BaseColor.WHITE);
      date.addCell(cell1);

      doc.add(date);

    } catch (DataAccessException | DocumentException ex) {
      Logger.getLogger(OrdreSortieServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
示例#27
0
  public static void main(String[] args) {
    Document document = new Document(PageSize.A4);

    try {

      PdfWriter.getInstance(document, new FileOutputStream("Relatorio.pdf"));
      document.open();

      Font font = new Font(FontFamily.TIMES_ROMAN, 7, Font.BOLD);

      Paragraph cabecalho = new Paragraph("Relatório UniChef");
      Paragraph sabor = new Paragraph("Sabor do Prato", font);
      Paragraph aparencia = new Paragraph("Aparência do Prato", font);
      Paragraph criatividadePrato = new Paragraph("Criatividade do Prato", font);
      Paragraph criatividadeBarraca = new Paragraph("Criatividade da Barraca", font);

      cabecalho.setAlignment(Element.ALIGN_CENTER);
      document.add(cabecalho);
      document.add(new Paragraph(" "));

      SubEvento subEvento = new SubEventoDAO().buscar(6);

      PdfPTable pTable = new PdfPTable(4);
      PdfPCell cellCabecalho =
          new PdfPCell(
              new Paragraph(
                  "Evento: "
                      + subEvento.getEvento().getNome()
                      + "     Barraca: "
                      + subEvento.getNome()));
      PdfPCell cellSabor = new PdfPCell(sabor);
      PdfPCell cellAparencia = new PdfPCell(aparencia);
      PdfPCell cellCriatividadePrato = new PdfPCell(criatividadePrato);
      PdfPCell cellCriatividadeBarraca = new PdfPCell(criatividadeBarraca);

      cellCabecalho.setHorizontalAlignment(Element.ALIGN_CENTER);
      cellSabor.setHorizontalAlignment(Element.ALIGN_CENTER);
      cellAparencia.setHorizontalAlignment(Element.ALIGN_CENTER);
      cellCriatividadePrato.setHorizontalAlignment(Element.ALIGN_CENTER);
      cellCriatividadeBarraca.setHorizontalAlignment(Element.ALIGN_CENTER);

      cellCabecalho.setColspan(4);

      pTable.addCell(cellCabecalho);
      pTable.addCell(cellSabor);
      pTable.addCell(cellAparencia);
      pTable.addCell(cellCriatividadePrato);
      pTable.addCell(cellCriatividadeBarraca);

      List<Avaliacao> avaliacoes = new AvaliacaoDAO().avaliacaoSubEvento(6);

      for (Avaliacao avaliacao : avaliacoes) {
        pTable.addCell(new PdfPCell(new Paragraph(avaliacao.getSabor().toString())));
        pTable.addCell(new PdfPCell(new Paragraph(avaliacao.getAparencia().toString())));
        pTable.addCell(new PdfPCell(new Paragraph(avaliacao.getCriatividade().toString())));
        pTable.addCell(new PdfPCell(new Paragraph(avaliacao.getCriatividadeBarraca().toString())));
      }

      document.add(pTable);

    } catch (DocumentException de) {
      de.printStackTrace();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      document.close();
    }
  }
  public PDFCreator(
      String name,
      String amount,
      String procedure,
      String dateIssued,
      String chargeDate,
      int patient_ID,
      int billing_ID) {

    this.name = name;
    this.amount = amount;
    this.procedure = procedure;
    this.dateIssued = dateIssued;
    this.chargeDate = chargeDate;
    this.patient_ID = patient_ID;
    this.billing_ID = billing_ID;

    Document document = new Document();
    try {
      PdfWriter writer =
          PdfWriter.getInstance(document, new FileOutputStream("Bill" + billing_ID + ".pdf"));
      document.open();

      /*     PdfPTable table = new PdfPTable(4); // 3 columns.
           table.setWidthPercentage(100); //Width 100%
           table.setSpacingBefore(10f); //Space before table
           table.setSpacingAfter(10f); //Space after table

           //Set Column widths
           float[] columnWidths = {1f, 1f, 1f, 1f};
           table.setWidths(columnWidths);

           PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1"));
           cell1.setBorderColor(BaseColor.BLUE);
           cell1.setPaddingLeft(10);
           cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
           cell1.setVerticalAlignment(Element.ALIGN_MIDDLE);

           PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2"));
           cell2.setBorderColor(BaseColor.GREEN);
           cell2.setPaddingLeft(10);
           cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
           cell2.setVerticalAlignment(Element.ALIGN_MIDDLE);

           PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3"));
           cell3.setBorderColor(BaseColor.RED);
           cell3.setPaddingLeft(10);
           cell3.setHorizontalAlignment(Element.ALIGN_CENTER);
           cell3.setVerticalAlignment(Element.ALIGN_MIDDLE);



           //To avoid having the cell border and the content overlap, if you are having thick cell borders
           //cell1.setUserBorderPadding(true);
           //cell2.setUserBorderPadding(true);
           //cell3.setUserBorderPadding(true);

           table.addCell(cell1);
           table.addCell(cell2);
           table.addCell(cell3);
           table.addCell("cell 4");
           table.addCell("Cell 5");
      */

      // Add Image
      Image image1 = Image.getInstance("Pictures\\Logo.PNG");
      // Fixed Positioning
      image1.setAbsolutePosition(150f, 750f);
      image1.scaleAbsolute(image1.getScaledWidth() / 2, image1.getScaledHeight() / 2);

      // Scale to new height and new width of image
      // image1.scaleAbsolute(500, 200);

      // Add to document
      document.add(image1);

      Paragraph companyInfo =
          new Paragraph(
              "Nimbus Clinical Management \n8421 West Forest Drive,\nFayetteville, Arkansas, 72701\n555-382-9876\n12/31/2016");
      companyInfo.setSpacingBefore(55f);
      companyInfo.setSpacingAfter(10f);

      Paragraph billingInvoice = new Paragraph("Billing Invoice");
      billingInvoice.setAlignment(Element.ALIGN_CENTER);

      document.add(companyInfo);
      document.add(billingInvoice);
      // document.add(paragraphTable1);
      document.add(createFirstTable());

      document.close();
      writer.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#29
0
 public void renderEmptyCell(PdfPCell cell) {
   Paragraph pr = new Paragraph();
   Chunk chunk = new Chunk(" ");
   pr.add(chunk);
   cell.addElement(pr);
 }
  @Override
  public ICardData[] getCards(ICharacter character, ICardReportResourceProvider resourceProvider) {
    IEquipmentAdditionalModel model =
        (IEquipmentAdditionalModel)
            character
                .getStatistics()
                .getCharacterContext()
                .getAdditionalModel(IEquipmentAdditionalModelTemplate.ID);
    List<ICardData> data = new ArrayList<ICardData>();
    for (IEquipmentItem item : model.getEquipmentItems()) {
      String title = item.getTitle();
      Paragraph headerText = new Paragraph();
      if (hasCustomTitle(item)) {
        headerText.add(new Phrase(item.getTemplateId(), resourceProvider.getNormalFont()));
      }
      if (item.getMaterialComposition() == MaterialComposition.Variable) {
        String itemMaterial = "";
        if (hasCustomTitle(item)) itemMaterial += " (";
        itemMaterial += item.getMaterial().getId();
        if (hasCustomTitle(item)) itemMaterial += ")";
        headerText.add(new Phrase(itemMaterial + "\n", resourceProvider.getNormalFont()));
      }
      if (item.getCost() != null) {
        headerText.add(new Phrase(item.getCost().toString(), resourceProvider.getNormalFont()));
      }

      List<Phrase> bodyText = new ArrayList<Phrase>();

      String description = item.getDescription();
      if (description != null && !description.isEmpty()) {
        bodyText.add(new Phrase(description, resourceProvider.getNormalFont()));
        bodyText.add(new Phrase("\n", resourceProvider.getNormalFont()));
      }
      for (IEquipmentStats stats : item.getStats()) {
        Paragraph statsParagraph = new Paragraph();
        if (stats instanceof IArtifactStats) {
          IArtifactStats artifactStats = (IArtifactStats) stats;
          if (artifactStats.getAttuneType() != ArtifactAttuneType.FullyAttuned) {
            continue;
          }
          statsParagraph.add(
              new Phrase(
                  resources.getString("Equipment.Stats.Short.AttuneCost").trim() + ": ",
                  resourceProvider.getBoldFont()));
          statsParagraph.add(
              new Phrase(artifactStats.getAttuneCost() + "m", resourceProvider.getNormalFont()));
        } else {
          String statsString = stringBuilder.createString(item, stats);
          statsParagraph.add(new Phrase(stats.getId() + ": ", resourceProvider.getBoldFont()));
          statsParagraph.add(
              new Phrase(
                  statsString.substring(statsString.indexOf(':') + 2),
                  resourceProvider.getNormalFont()));
        }

        bodyText.add(statsParagraph);
      }

      data.add(
          new EquipmentCardData(
              title, headerText, bodyText.toArray(new Phrase[0]), resourceProvider.getNullIcon()));
    }
    return data.toArray(new ICardData[0]);
  }