I have an agent (imported Java) that creates pdf from Notes document using Apache Fop. In case of success I would like to write to agentsOutput contents of my pdf.
I use this code to get agent output:
PrintWriter pw = getAgentOutput();
And this is my method that prints to output:
public void writeFileToPw(PrintWriter pw, String fileName) {
String s;
try {
BufferedReader in = new BufferedReader(new FileReader(fileName));
while ((s = in.readLine()) != null) {
pw.write(s);
pw.println();
}
in.close();
pw.close();
} catch (Exception e) {
logger.fatal("Error writing AgentOutput", e);
}
}
The problem is that this methos outputs the file as html (treats the contents of my pdf as text) not as application/pdf (binary data).
If I write to AgentOutput url of a file (for example if I put it in Domino/html folder to be publicly accessed over http), works fine but the problem is that these documents must not be publicly accessed.
But, Mr Frunobulax is right, the PrintWriter that getAgentOutput returns is only used for characters, not bytes, and I do believe PDF files have raw byte codes. (From the JavaDocs - “It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams.”)
An alternative way of getting this to work would be to write the PDF as an attachment to a document, and then redirect the browser to the $FILE element for that attachment.
Another way of doing this would be to write the file to the /domino/html folder under your servers notes data directory, and point the user to that. You just have to make sure you clean up the old PDF files occasionally.