Fop
  1. Fop
  2. FOP-1294

[PATCH] Fix PDF Genaration for non ASCII compatibable locales

    Details

    • Type: Bug Bug
    • Status: Closed
    • Resolution: Fixed
    • Affects Version/s: trunk
    • Fix Version/s: None
    • Component/s: renderer/pdf
    • Labels:
      None
    • Environment:
      Operating System: other
      Platform: Other
    • External issue ID:
      41434

      Description

      Currently, the PDF library of FOP uses getBytes in various places. The behaviour
      of this functions depends on current locale. If the locale is not compatible
      with ASCII, an invalid PDF will be generated (eg. with default locale IBM-1047).

      To fix this, the getBytes call are replaced with a call to PDFDocument.encode.
      Patch is made for the 0.93 version. As the pdf library in the trunk version is
      the same, the patch should also be applied there.

      diff -urN fop-orig/fop-0.93/src/java/org/apache/fop/pdf/PDFDocument.java
      fop-brz/fop-0.93/src/java/org/apache/fop/
      pdf/PDFDocument.java
      — fop-orig/fop-0.93/src/java/org/apache/fop/pdf/PDFDocument.java
      2007-01-03 21:44:52.000000000 +0100
      +++ fop-brz/fop-0.93/src/java/org/apache/fop/pdf/PDFDocument.java
      2007-01-11 18:14:07.000000000 +0100
      @@ -849,7 +849,7 @@

      getProfile().verifyPDFVersion();

      • byte[] pdf = ("%PDF-" + getPDFVersionString() + "\n").getBytes();
        + byte[] pdf = encode("%PDF-" + getPDFVersionString() + "\n");
        stream.write(pdf);
        this.position += pdf.length;

      @@ -870,9 +870,9 @@
      try {
      MessageDigest digest = MessageDigest.getInstance("MD5");
      DateFormat df = new
      SimpleDateFormat("yyyy''MM''dd'T'HH':'mm':'ss'.'SSS");

      • digest.update(df.format(new Date()).getBytes());
        + digest.update(encode(df.format(new Date())));
        //Ignoring the filename here for simplicity even though it's
        recommended by the PDF spec
      • digest.update(String.valueOf(this.position).getBytes());
        + digest.update(encode(String.valueOf(this.position)));
        digest.update(getInfo().toPDF());
        byte[] res = digest.digest();
        String s = PDFText.toHex(res);
        diff -urN fop-orig/fop-0.93/src/java/org/apache/fop/pdf/PDFRectangle.java
        fop-brz/fop-0.93/src/java/org/apache/fop
        /pdf/PDFRectangle.java
          • fop-orig/fop-0.93/src/java/org/apache/fop/pdf/PDFRectangle.java
            2007-01-03 21:44:49.000000000 +0100
            +++ fop-brz/fop-0.93/src/java/org/apache/fop/pdf/PDFRectangle.java
            2007-01-11 18:20:50.000000000 +0100
            @@ -79,7 +79,7 @@
      • @return the PDF
        */
        public byte[] toPDF() { - return toPDFString().getBytes(); + return PDFDocument.encode(toPDFString()); }

      /**
      diff -urN fop-orig/fop-0.93/src/java/org/apache/fop/pdf/PDFStream.java
      fop-brz/fop-0.93/src/java/org/apache/fop/pd
      f/PDFStream.java
      — fop-orig/fop-0.93/src/java/org/apache/fop/pdf/PDFStream.java
      2007-01-03 21:44:44.000000000 +0100
      +++ fop-brz/fop-0.93/src/java/org/apache/fop/pdf/PDFStream.java 2007-01-11
      18:21:19.000000000 +0100
      @@ -57,7 +57,7 @@
      */
      public void add(String s) {
      try

      { - data.getOutputStream().write(s.getBytes()); + data.getOutputStream().write(PDFDocument.encode(s)); }

      catch (IOException ex) {
      //TODO throw the exception and catch it elsewhere
      ex.printStackTrace();

        Activity

        Hide
        Jeremias Maerki added a comment -

        Thank you for this patch, Martin. I've just applied it. Sorry for the delay.
        http://svn.apache.org/viewvc?view=rev&rev=533986

        Show
        Jeremias Maerki added a comment - Thank you for this patch, Martin. I've just applied it. Sorry for the delay. http://svn.apache.org/viewvc?view=rev&rev=533986
        Hide
        Glenn Adams added a comment -

        batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed

        Show
        Glenn Adams added a comment - batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed

          People

          • Assignee:
            fop-dev
            Reporter:
            Martin K
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development