Simon Kitching wrote: > I have a "c" application which has been generating PDFs by > executing the "fop.sh" script. I have now rewritten the > process in Java, and am using the o.a.f.apps.Driver class directly. > > However the old code used to produce PDFs which contained > only printable characters (some sections look like base64 encoding). > The new code produces sections which contain "binary" data. > > For various reasons I need to ensure that the PDF output > contains printable characters only, like the old solution did. > > The old PDFs include lines like this: > << /Length 1917 /Filter [ /ASCII85Decode /FlateDecode ] > while the new ones have lines like this: > << /Length 1474 /Filter /FlateDecode > > At a guess, I would say that with my old app (using fop.sh) > the non-printable data has been "deflated" then > "ascii85-encoded" to render it into all printable chars > (probably at a filesize penalty), while the new code (calling > Driver directly) skips the ascii85 encoding step. > Assuming this is the case, can anyone tell me how to enable > the ascii85-encoding of data within the PDF, using the > o.a.f.apps.Driver API or similar?? > > I'm using fop 0.20.5 in both the "old" and the "new" code, > though in the "new" case I'm possibly using some updated libs. > > Here's the java Code I currently use to invoke the Driver: > Driver driver = new Driver(); > driver.setLogger(fopLogger); > driver.setRenderer(Driver.RENDER_PDF); > > ByteArrayOutputStream baos = new ByteArrayOutputStream(); > driver.setOutputStream(baos); > > DocumentInputSource documentInputSource > = new DocumentInputSource(msg); > driver.setInputSource(documentInputSource); > > driver.run(); > > return baos.toByteArray(); >
This is not documented, but you can choose the filters applied using the following configuration file construct: <entry role="pdf"> <key>stream-filter-list</key> <list> <value>filter-keyword</value> </list> </entry> The filter keywords are: flate, ascii-85, and ascii-hex. To apply multiple filters, list them in the order they should be applied: <entry role="pdf"> <key>stream-filter-list</key> <list> <value>ascii-85</value> <value>flate</value> </list> </entry> To apply *no* filters: <entry role="pdf"> <key>stream-filter-list</key> <list> </list> </entry> Now, the second part of the question is how to set the configuration through your program. The beginnings of the answer are here: http://xml.apache.org/fop/embedding.html#config-internal However, that only documents setting the standard configuration. The method you will need is this one: public static void put(String key, Object value, int role) The valid "role" values above are Configuration.STANDARD, Configuration.PDF, and Configuration.AWT. You want Configuration.PDF. If you only have one filter to apply, skip the "list" concept and just drop the name of the filter in to the "value": Configuration.put("stream-filter-list", "ascii-85", Configuration.PDF); If you need the list, build a java.util.ArrayList with the multiple entries and use it in the method. Something like this: java.util.ArrayList list = new java.util.ArrayList; list.add("ascii-85"); list.add("flate"); Configuration.put("stream-filter-list", list, Configuration.PDF); There is a strong possibility that I have some of the details wrong here, but this is the gist of it. Let me know if this doesn't work or if you have to make changes to get it to work. Victor Mote --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]