private Document buildMetadata(Document document, String date) {
    String author =
        authHelper.getCurrentUser().getAgent().getNom()
            + " "
            + authHelper.getCurrentUser().getAgent().getPrenom();
    document.addAuthor(author);
    document.addCreationDate();
    document.addCreator(author);
    document.addTitle("FICHE EVENEMENTIELLE " + date);
    document.addSubject("FICHE EVENEMENTIELLE " + date);

    return document;
  }
  private Document buildMetadata(Document document, Fiche fiche) {
    Agent a = fiche.getHistoriques().iterator().next().getUtilisateur().getAgent();
    document.addAuthor(a.getNom() + " " + a.getPrenom());
    document.addCreationDate();
    document.addCreator(
        authHelper.getCurrentUser().getAgent().getNom()
            + " "
            + authHelper.getCurrentUser().getAgent().getPrenom());
    document.addTitle("MAIN COURANTE " + fiche.getReference());
    document.addSubject("MAIN COURANTE " + fiche.getReference());

    StringBuilder keywords = new StringBuilder();
    keywords.append(fiche.getReference());
    keywords.append(",");
    keywords.append(fiche.getAdresse().getNomVoie().getLibelle());
    keywords.append(",");
    for (Fait f : fiche.getFaits()) {
      keywords.append(f.getNature().getLibelleCourt());
      keywords.append(",");
    }
    document.addKeywords(keywords.toString());

    return document;
  }
  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();
  }