|
|
|
2.7 Can PDFreactor access documents form servers that require POST-data or cookies?
To set cookies and post-data in your java program that uses PDFreactor you can use a URLConnection object: URL url = new URL(...URL...); URLConnection urlConnection = url.openConnection(); urlConnection.setUseCaches(false);
urlConnection.setRequestProperty(key, value); // sets cookies
urlConnection.setDoOutput(true); PrintWriter printWriter = new PrintWriter(urlConnection.getOutputStream()); printWriter.println("key=value"); // sets POST-data printWriter.close();
urlConnection.connect(); InputSource inputSouce = new InputSource(urlConnection.getInputStream()); inputSouce.setSystemId(urlConnection.getURL().toString()); FileOutputStream fileOutputStream= new FileOutputStream("...file..."); (new PDFreactor()).renderDocument(inputSouce, new PDFreactorConfiguration(), fileOutputStream); out.fileOutputStream();
To be able to receive cookies from a server and store them like a browser you can use the free (LGPL) Java library "HTTPClient" by Innovation GmbH. For more information see www.innovation.ch/java/HTTPClient/ . It can replace the built-in http client of Java and so allow Java programs to receive and store cookies without changing the code. You can get the file from www.innovation.ch/java/HTTPClient/HTTPClient.zip . To use it set these 2 Java parameters: -Djava.protocol.handler.pkgs=HTTPClient -Xbootclasspath/a:*PATH*/HTTPClient.zip (replace *PATH* with your path to HTTPClient.zip)
|