0

So Weird, I am generating a PDF using FlyingSaucer, then adding a footer to the PDF. The footer works in Chrome and FF, but not IE. But if I download the PDF, even from Chrome, where the text is there, open it locally with Adobe, it is not... I dont get it.

Code:

    ByteArrayOutputStream os = originalPDF.getOutputStream();
    ByteArrayOutputStream newos = new ByteArrayOutputStream();
    PdfReader reader = new PdfReader(os.toByteArray());
    PdfStamper stamper  = new PdfStamper(reader, newos);

    for(int i=1; i<= reader.getNumberOfPages(); i++){
        Rectangle pageSize = reader.getPageSize(i);
        PdfContentByte content = stamper.getUnderContent(i);
        BaseFont baseFont = BaseFont.createFont(BaseFont.HELVETICA, "utf8", false);
        content.setFontAndSize(baseFont, 15);
        content.setRGBColorFill(0, 0, 0);
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Page "+i, 3, 5, 0);
        content.showTextAligned(PdfContentByte.ALIGN_RIGHT, " - Printed: "+DateUtil.date2str_MM_dd_yyyy(new Date()), pageSize.getWidth()-3, 5, 0);
    }

    stamper.close();

    request.getSession().setAttribute("file", newos.toByteArray());

Any Ideas?

@mkl EDIT: I cannot post the PDF, sensitive information and all that BUT, if I change the code to:

      PdfContentByte content = stamper.getUnderContent(i);
        String msg = "Page "+i+" - Printed: "+DateUtil.datetime2str_MM_dd_yyyy_h_mm_a(new Timestamp(new Date().getTime()));
        ColumnText.showTextAligned(content, PdfContentByte.ALIGN_CENTER, new Phrase(msg), center, 5, 0);

It works on all browsers and Adobe. So clearly my font and/or encoding is wrong. Any suggestions for proper encoding?

mmaceachran
  • 3,178
  • 7
  • 53
  • 102
  • 1
    Please provide a sample result pdf. That been said, utf8 is a weird encoding for Helvetica; underContent might be hidden; xfa forms in PDFs might make things interesting. – mkl Jan 25 '14 at 22:36
  • Concerning your edit: the encoding utf8 is not applicable here. Helvetica is one of the standard 14 fonts every viewer knows but only with a WinAnsiEncoding style character set. – mkl Jan 26 '14 at 08:50

0 Answers0