tags:

views:

1617

answers:

2

Does anybody know a Java tool that can convert a pdf file to a swf file ?

To clarify, we are building a site to generate photo albums. The photo album editor is written in Flash (ActionScript 3.0) and then on the back-end is written in Java and it generates a pdf for the album. The problem is having two rendering engines (Flash for client side, and Java on the server) and their output must be identical. We think that having the back-end generate a pdf file and then converting it to swf gives the highest fidelity, so that's why this conversion tool is needed. However, if people have other solutions these are welcomed as well.

A: 

A solution that could be used:
- The server generates the pdf
- The server launches the conversion program (for instance this one)
- The client uses the flash file

Burkhard
I did it once, but the other way round. I.e. a C++ program launching a java gui. +1 for the java launch. Didn't know it was possible.
+3  A: 

Search

  1. http://tinyurl.com/mhovt6
  2. http://www.swftools.org

Implement

SWFTools is cross-platform. Compile it to a native binary then call it from Java using Runtime.exec. For example, on a Unix system you could write:

public class PDF2SWF extends FileFormatConverter {
  public PDF2SWF() {
  }

  public void convert() {
    Process process = Runtime.getRuntime().exec( getExecutablePath() + " " + getArguments() );
  }

  protected String getExecutablePath() {
    return "/usr/local/bin/pdf2swf";
  }

  protected String getArguments() {
    return getInputFilename() + " " + getOutputFilename();
  }

  protected String getInputFilename() {
    return getFilename() + getPDFExtension();
  }

  // And so forth.
}

Actual implementation details will depend on your architecture and integration with existing source.

Advantages

Quick and simple.

Disadvantages

External dependency on a third-party application. If the application becomes corrupt, changes location, or is not installed when migrating to a new server, the system breaks.

Alternatives

Ideally you would use a Java class that implements this functionality. (More searching might be in order.) You could write a native-interface wrapper class, but then you've moved the dependency from a third-party executable to a third-party library.

Dave Jarvis
+1 lmgtfy. :-) The rest is good too.
Stobor