コード例 #1
0
 private void applyPadding(Rectangle r, boolean isLeft) {
   if (isLeft) {
     r.setRight(r.getRight() - hPadding);
   } else {
     r.setLeft(r.getLeft() + hPadding);
   }
 }
コード例 #2
0
ファイル: RyspeGeneradorPdf.java プロジェクト: UAQ/ryspe
 // 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;
 }
コード例 #3
0
 /**
  * Implementation of the cellLayout method.
  *
  * @see com.itextpdf.text.pdf.PdfPCellEvent#cellLayout( com.itextpdf.text.pdf.PdfPCell,
  *     com.itextpdf.text.Rectangle, com.itextpdf.text.pdf.PdfContentByte[])
  */
 public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
   try {
     PdfAnnotation annotation =
         PdfAnnotation.createFileAttachment(
             writer,
             new Rectangle(
                 position.getLeft() - 20,
                 position.getTop() - 15,
                 position.getLeft() - 5,
                 position.getTop() - 5),
             description,
             fs);
     annotation.setName(description);
     writer.addAnnotation(annotation);
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #4
0
ファイル: PdfCalendar.java プロジェクト: anupkumardixit/book
 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();
 }
コード例 #5
0
ファイル: PdfCalendar.java プロジェクト: anupkumardixit/book
 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();
 }
コード例 #6
0
 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);
 }
コード例 #7
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);
   }
 }
コード例 #8
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);
   }
 }
コード例 #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();
  }
コード例 #10
0
 private float horCenter() {
   return (rectangle.getLeft() + rectangle.getRight()) / 2;
 }