Exploring pdfsam source code

This is first time I dig into opensource sw this much.

All I want is a script that extract pdf pages. pdfsam GUI can do this, but I have to key inputs into text field for each file I want to extracted. This is painful and certainly not a job for human.

With my programmer’s pride, I decide to jump into pdfsam source-code and find the part I can reuse myself.

…and 3 hours passed…

I can finally run the source code – -”

This is the list problems I found. As always, you would not understand it since it’s my reminder😛

– most of errors come from log4j

  • add this line “org.apache.log4j.BasicConfigurator.configure();” into main() of GuiClient
  • open  .jar file in your installed (mine is pdfsam-1.0.2.jar)
  • copy “config.xml” “log4j.xml” “pdfsam.properties” into your default package
  • copy “config.xml”  into your default package
  • Your log4j should work now

– Next step is to load your plugin

  • Split and Merge&Extract are plugins, they have to be a jar file
  • find you can find the jar file in <pdfsam_path>/plugins/<plugin_name> but it doesn’t contain source code. If you want to use debugger to look at source code, put the source in the jar file. The source of each plugin can be found in pdfsam-<plugin_name>-<version>-src.zip  in source code Ex. “pdfsam-merge-0.6.6-build-src.zip”
  • copy the jar file to org.pdfsam.plugins
  • But it still can’t find plugins folder !!
  • Find PlugInsLoader.java. At the line ### this.pluginsDirectory = new File(config.getMainJarPath(), “plugins”); ### change  the path to  “org/pdfsam/plugin”
  • JSaveListAsMenuItem in the plugin will throw null exception because it can’t find image. You can fix it if you wish. But i just catch the exception and print the stacktrace, since it doesn’t effect the extract function.

– To sniff merging arguments

  • “MergeMainGUI.java”  find “runButton.addActionListener(“
  • variable “args” is the list that contain merging arguments, use foreach loop print them
  • The logic of this method:
  1. get destination of out put from destinationTextField
  2. get PdfSelectionTableItem (from selectPanel)
  3. get each input file’s location & process the “pages” it’d be extracted
  4. put those into “args” variable
  5. check options in overwriteCheckbox, outputCompressed, and CheckmergeTypeCheck
  6. get output pdf’s version, put it into “args” too
  7. get WorkExecutor’s instance to run this in new WorkThread, throw the ‘args’ as a parameter

Phew…. no wonder why I take 3 hours…

, , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: