Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-1294

[PATCH] Fix PDF Genaration for non ASCII compatibable locales

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Resolution: Fixed
    • 2.5
    • None
    • renderer/pdf
    • None
    • Operating System: other
      Platform: Other
    • 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();

      Attachments

        Activity

          People

            fop-dev@xmlgraphics.apache.org fop-dev
            martin.koegler@brz.gv.at Martin K
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: