Exemplo n.º 1
0
 // FIXME: Manage Exceptions
 private OutputStream marcarReporteProgramaRechazado(final Programa programa, InputStream src)
     throws IOException, DocumentException {
   PdfReader reader = null;
   reader = new PdfReader(src);
   int n = reader.getNumberOfPages();
   ByteArrayOutputStream os = new ByteArrayOutputStream();
   PdfStamper stamper = null;
   stamper = new PdfStamper(reader, os);
   // text watermark
   Font f = new Font(Font.FontFamily.HELVETICA, 65);
   Phrase p = new Phrase("RECHAZADO", f);
   // transparency
   PdfGState gs1 = new PdfGState();
   gs1.setFillOpacity(0.3f);
   // properties
   PdfContentByte over;
   Rectangle pagesize;
   float x, y;
   // loop over every page
   for (int i = 1; i <= n; i++) {
     pagesize = reader.getPageSizeWithRotation(i);
     x = (pagesize.getLeft() + pagesize.getRight()) / 2;
     y = (pagesize.getTop() + pagesize.getBottom()) / 2;
     over = stamper.getOverContent(i);
     over.saveState();
     over.setGState(gs1);
     ColumnText.showTextAligned(over, Element.ALIGN_CENTER, p, x, y, 45);
   }
   stamper.close();
   reader.close();
   return os;
 }
Exemplo n.º 2
0
 public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
   PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
   cb.roundRectangle(
       rect.getLeft() + 1.5f,
       rect.getBottom() + 1.5f,
       rect.getWidth() - 3,
       rect.getHeight() - 3,
       4);
   cb.setCMYKColorFill(0x00, 0x00, 0x00, 0x00);
   cb.fill();
 }
Exemplo n.º 3
0
 public void cellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
   PdfContentByte cb = canvas[PdfPTable.LINECANVAS];
   cb.roundRectangle(
       rect.getLeft() + 1.5f,
       rect.getBottom() + 1.5f,
       rect.getWidth() - 3,
       rect.getHeight() - 3,
       4);
   cb.setLineWidth(1.5f);
   cb.setCMYKColorStrokeF(color[0], color[1], color[2], color[3]);
   cb.stroke();
 }
 public void onEndPage(PdfWriter writer, Document document) {
   Rectangle rect = writer.getBoxSize("art");
   // ColumnText.showTextAligned(writer.getDirectContent(),Element.ALIGN_CENTER, new
   // Phrase(grupo), rect.getRight(), rect.getBottom(), 0);
   ColumnText.showTextAligned(
       writer.getDirectContent(),
       Element.ALIGN_CENTER,
       new Phrase("Pagina " + pages),
       rect.getLeft(),
       rect.getBottom(),
       0);
 }
 /**
  * Draws the info about the movie.
  *
  * @throws DocumentException
  */
 protected void drawMovieInfo(Screening screening, PdfContentByte directcontent)
     throws DocumentException {
   if (screening.isPress()) {
     Rectangle rect = getPosition(screening);
     ColumnText.showTextAligned(
         directcontent,
         Element.ALIGN_CENTER,
         press,
         (rect.getLeft() + rect.getRight()) / 2,
         rect.getBottom() + rect.getHeight() / 4,
         0);
   }
 }
Exemplo n.º 6
0
 public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
   try {
     PdfContentByte cb = canvases[PdfPTable.BACKGROUNDCANVAS];
     PdfPatternPainter patternPainter =
         cb.createPattern(image.getScaledWidth(), image.getScaledHeight());
     image.setAbsolutePosition(0, 0);
     patternPainter.addImage(image);
     cb.saveState();
     cb.setPatternFill(patternPainter);
     cb.rectangle(
         position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight());
     cb.fill();
     cb.restoreState();
   } catch (DocumentException e) {
     throw new ExceptionConverter(e);
   }
 }
  private boolean addToTwoColumns(boolean simulate, float height) {
    ColumnTextBuilder ctb;
    int status;
    ctb = b.reuseColumnTextBuilder();

    b.reuseRectangleBuilder(tempR).copyPositionsFrom(rectangle);

    final float horCenter = horCenter();

    setColumn(height, horCenter, true, ctb, simulate);

    contentAdder.add(ctb, simulate);

    status = ctb.go(simulate);

    yLine = ctb.getYLine();

    if (!ColumnText.hasMoreText(status) && simulate) {
      return true;
    }

    setColumn(height, horCenter, false, ctb, simulate);

    status = ctb.go(simulate);

    yLine = Math.min(yLine, ctb.getYLine());

    // right column may not fit the rect, check if does fit the page
    if (simulate) {
      if (yLine < rectangle.getBottom()) {
        return false;
      }
    }

    return !ColumnText.hasMoreText(status);
  }
Exemplo n.º 8
0
    @Override
    public void onEndPage(PdfWriter writer, Document document) {
      Rectangle rect = writer.getBoxSize("art");

      Image imghead = null;
      PdfContentByte cbhead = null;

      try {
        imghead = Image.getInstance("LogoSapito5.png");
        imghead.setAbsolutePosition(0, 0);
        imghead.setAlignment(Image.ALIGN_CENTER);
        imghead.scalePercent(10f);
        cbhead = writer.getDirectContent();
        PdfTemplate tp = cbhead.createTemplate(100, 150);
        tp.addImage(imghead);
        cbhead.addTemplate(tp, 100, 715);

      } catch (BadElementException e) {
        e.printStackTrace();
      } catch (DocumentException e) {
        e.printStackTrace();
      } catch (IOException ex) {
        Logger.getLogger(Cuentaspagar.class.getName()).log(Level.SEVERE, null, ex);
      }

      Phrase headPhraseImg =
          new Phrase(cbhead + "", FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.NORMAL));

      Calendar c1 = Calendar.getInstance();
      Calendar c2 = new GregorianCalendar();
      String dia, mes, annio;
      dia = Integer.toString(c1.get(Calendar.DATE));
      mes = Integer.toString(c1.get(Calendar.MONTH));
      annio = Integer.toString(c1.get(Calendar.YEAR));
      java.util.Date fecha = new Date();
      String fechis = dia + "/" + mes + "/" + annio;
      Paragraph parrafo5 =
          new Paragraph(
              fechis,
              FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_CENTER,
          new Phrase(parrafo5),
          rect.getRight(450),
          rect.getTop(-80),
          0);

      Paragraph parrafo7 =
          new Paragraph(
              "Empresa Sapito S.A. de C.V.",
              FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK));
      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_CENTER,
          new Phrase(parrafo7),
          rect.getBottom(250),
          rect.getTop(-60),
          0);

      Paragraph parrafo8 =
          new Paragraph(
              "Cuentas por cobrar",
              FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_CENTER,
          new Phrase(parrafo8),
          rect.getBottom(250),
          rect.getTop(-40),
          0);

      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_BOTTOM,
          new Phrase(
              "      _________________________________________________________________________________    "),
          rect.getBorder(),
          rect.getTop(-24),
          0);

      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_BOTTOM,
          new Phrase(
              "      _________________________________________________________________________________    "),
          rect.getBorder(),
          rect.getTop(-20),
          0);

      Paragraph parrafo6 =
          new Paragraph(
              String.format("Pág %d", writer.getPageNumber()),
              FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
      ColumnText.showTextAligned(
          writer.getDirectContent(),
          Element.ALIGN_CENTER,
          new Phrase(parrafo6),
          rect.getRight(-35),
          rect.getTop(-80),
          0);
    }
Exemplo n.º 9
0
  private static PdfReader createPdf(
      String globalTitle, Date creationDate, ScrambleRequest scrambleRequest)
      throws DocumentException, IOException {
    azzert(scrambleRequest.scrambles.length > 0);
    ByteArrayOutputStream pdfOut = new ByteArrayOutputStream();
    Rectangle pageSize = PageSize.LETTER;
    Document doc = new Document(pageSize, 0, 0, 75, 75);
    PdfWriter docWriter = PdfWriter.getInstance(doc, pdfOut);

    docWriter.setBoxSize(
        "art", new Rectangle(36, 54, pageSize.getWidth() - 36, pageSize.getHeight() - 54));

    doc.addCreationDate();
    doc.addProducer();
    if (globalTitle != null) {
      doc.addTitle(globalTitle);
    }

    doc.open();
    // Note that we ignore scrambleRequest.copies here.
    addScrambles(docWriter, doc, scrambleRequest, globalTitle);
    doc.close();

    // TODO - is there a better way to convert from a PdfWriter to a PdfReader?
    PdfReader pr = new PdfReader(pdfOut.toByteArray());
    if (scrambleRequest.fmc) {
      // We don't watermark the FMC sheets because they already have
      // the competition name on them.
      return pr;
    }

    pdfOut = new ByteArrayOutputStream();
    doc = new Document(pageSize, 0, 0, 75, 75);
    docWriter = PdfWriter.getInstance(doc, pdfOut);
    doc.open();

    PdfContentByte cb = docWriter.getDirectContent();

    for (int pageN = 1; pageN <= pr.getNumberOfPages(); pageN++) {
      PdfImportedPage page = docWriter.getImportedPage(pr, pageN);

      doc.newPage();
      cb.addTemplate(page, 0, 0);

      Rectangle rect = pr.getBoxSize(pageN, "art");

      // Header
      ColumnText.showTextAligned(
          cb,
          Element.ALIGN_LEFT,
          new Phrase(Utils.SDF.format(creationDate)),
          rect.getLeft(),
          rect.getTop(),
          0);

      ColumnText.showTextAligned(
          cb,
          Element.ALIGN_CENTER,
          new Phrase(globalTitle),
          (pageSize.getLeft() + pageSize.getRight()) / 2,
          pageSize.getTop() - 60,
          0);

      ColumnText.showTextAligned(
          cb,
          Element.ALIGN_CENTER,
          new Phrase(scrambleRequest.title),
          (pageSize.getLeft() + pageSize.getRight()) / 2,
          pageSize.getTop() - 45,
          0);

      if (pr.getNumberOfPages() > 1) {
        ColumnText.showTextAligned(
            cb,
            Element.ALIGN_RIGHT,
            new Phrase(pageN + "/" + pr.getNumberOfPages()),
            rect.getRight(),
            rect.getTop(),
            0);
      }

      // Footer
      String generatedBy = "Generated by " + Utils.getProjectName() + "-" + Utils.getVersion();
      ColumnText.showTextAligned(
          cb,
          Element.ALIGN_CENTER,
          new Phrase(generatedBy),
          (pageSize.getLeft() + pageSize.getRight()) / 2,
          pageSize.getBottom() + 40,
          0);
    }

    doc.close();

    // TODO - is there a better way to convert from a PdfWriter to a PdfReader?
    pr = new PdfReader(pdfOut.toByteArray());
    return pr;

    //      The PdfStamper class doesn't seem to be working.
    //      pdfOut = new ByteArrayOutputStream();
    //      PdfStamper ps = new PdfStamper(pr, pdfOut);
    //
    //      for(int pageN = 1; pageN <= pr.getNumberOfPages(); pageN++) {
    //          PdfContentByte pb = ps.getUnderContent(pageN);
    //          Rectangle rect = pr.getBoxSize(pageN, "art");
    //          System.out.println(rect.getLeft());
    //          System.out.println(rect.getWidth());
    //          ColumnText.showTextAligned(pb,
    //                  Element.ALIGN_LEFT, new Phrase("Hello people!"), 36, 540, 0);
    ////            ColumnText.showTextAligned(pb,
    ////                    Element.ALIGN_CENTER, new Phrase("HELLO WORLD"),
    ////                    (rect.getLeft() + rect.getRight()) / 2, rect.getTop(), 0);
    //      }
    //      ps.close();
    //      return ps.getReader();
  }