Tech Blog

Batch Convert PDF files to Flash Paper

Posted At : February 22, 2007 9:32 PM 16 Comments

For a current project I need to convert a whole heap of pdf files into FlashPaper so that we can display them inline in the site. After a quick google I found a useful example using ANT by Darron Schall.

ANT has been on my list of stuff to check out for the last while - however, it's real strength is that it is cross platform. For this project I found it a bit overkill so I just put together a little VB script to handle it.

This script is also simpler to set up on non-technical users machines as you don't need to have Java, Ant and Ant contrib set up.

The following script reads file in from a folder "in" and outputs them to a folder "out". It does very little error checking but works for me . Hope it helps.

' Script to convert PDF files to Flash Paper using the flash printer
' Reads files from folder "in" and outputs to folder "out"

flashPrinter= """C:\Program Files\Macromedia\FlashPaper 2\FlashPrinter.exe"""
inPath = "in\"
outPath = "out\"
delayMsec = 10000 'wait to let flashPrinter complete


If "CSCRIPT.EXE" <> UCase( Right( WScript.Fullname, 11 ) ) Then
'WScript.Interactive = false
WScript.Echo "To use this script enter: cscript " & WScript.ScriptName & vbcrlf & "or right click and select 'Open with Command Prompt'"
WScript.Quit 1
End If

Dim strMbox

Set objFileScripting = CreateObject("Scripting.FileSystemObject")
'Return folder object
Set objFolder = objFileScripting.GetFolder(inPath)
'return file collection In folder
Set filecollection = objFolder.Files

strMbox= MsgBox("Ready to process " & fileCollection.count & " files",1)
If strMbox = 2 Then
   Wscript.Echo "Cancelled"
   WScript.Quit
end if

   For Each filename In filecollection
      filename=right(filename,len(filename)-InStrRev(filename, "\"))
      if InStrRev(filename, ".") then 'remove extension if there is one
         FilenameNoExt=left(filename,InStrRev(filename, ".")-1)
      end if
      
      ' Run the flashprinter for each file
      command = flashPrinter & " " & inPath & filename & " -o " & outPath & filenameNoExt & ".swf"   
      Set objShell = CreateObject("WScript.Shell")
      'objShell.CurrentDirectory =
      Wscript.Echo "Processing: " & inPath & filename & " --> " & outPath & filenameNoExt & ".swf"
      objShell.Run(command)
      'Wait some for it to complete
      
      Wscript.Sleep delayMsec

   Next

Wscript.Echo "Done"
WScript.Quit

Feel free to use it and if you have any improvements please let me know.

Update: changed comment from // to ' which makes it barf. That will teach me to comment it after I write it.

16 Comments

Matt 3/6/07 12:07 AM

Great stuff!!!

I tried the ANT script but having never touched ANT it just took to long for me to set up and I left it.

This script works well for PDF to SWF.

How can I use it to convert the contents of a folder that might contain any printable file including pdf into two output directorys for pdf and swf respectivly.

Some submitted PDF's are rather large.. can flashpaper process them again to make them smaller?

- Matt

Matt 3/6/07 12:25 AM

Ok I thought it was working well but actually it done nothing at all. I wrote the previous message as it was processing but when it was finished the output folder did not contain any .swf files !?

I got this

C:\Staff>cscript pdf2flashpaper.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Processing: Book PDF's for Web\bk1933.pdf --> Book PDF's for Web\bk1933.swf
Processing: Book PDF's for Web\bk1963.pdf --> Book PDF's for Web\bk1963.swf
Processing: Book PDF's for Web\bk2005.pdf --> Book PDF's for Web\bk2005.swf
Processing: Book PDF's for Web\bk2010.pdf --> Book PDF's for Web\bk2010.swf
Done

--->

But nothing. Any ideas as to why Im getting no output?

Mark Lynch 3/6/07 6:12 AM

Hi Matt,
Not sure - are you getting any output at all? Are you seeing any flash paper screens? Flash paper is installed in the same location? It is flash paper 2 you are using?

Cheers,
Mark

Matt 3/6/07 1:55 PM

No output at all,
Im not seeing any flashpaper screens when running the script,
I have FlashPaper 2 Installed in C:\Program Files\Macromedia\FlashPaper 2\FlashPrinter.exe
It is version 2.01.2283.0
Licencing 4.0.0.38

Maybe I've got a dud Flashpaper that does not respond to command line?

Mark Lynch 3/6/07 4:18 PM

Another possible problem I thought of - what directory are you running it from.

Make sure that the directory name does not have any spaces in it - I haven't done any escaping for spaces in the directory name.

I typically run it from c:\pdf2flash\ . Let me know how you go.

Cheers,
Mark

Matt 3/6/07 4:39 PM

I tried it with the same settings you show in your example.

flashPrinter= """C:\Program Files\Macromedia\FlashPaper 2\FlashPrinter.exe"""
inPath = "in\"
outPath = "out\"
delayMsec = 10000 'wait to let flashPrinter complete

But no luck :( ... I tried re-installing flashpaper and now I get an error/warning on install, something to do with registry keys! I re-installed, so I could select all users instead of just this user - I thought that might be the problem, but no.

Flashpaper still works even with the warning on installation. I can run it manually. The strange thing is that in trial mode the vb script opens the flashpaper registration window, I press ok , but still no output. In registered mode nothing opens at all.

Basically it looks like my flashpaper installation takes no notice of the command line.

M.

Carlos 3/8/07 8:11 AM

Hello, I'm having the same issue as Matt. I first tried the ANT way and also found it hard to set up (tools.jar?) So I was excited to see Mark's use of VB. My paths are:

inPath = "C:\PDF\"
outPath = "C:\SWF\"

As with Matt, I got messages such as...
Processing: Book PDF's for Web\bk1933.pdf --> Book PDF's for Web\bk1933.swf

but after the processing was complete, there were no SWF files.

Any ideas?

Thanks, Carlos

Mark Lynch 3/8/07 8:28 AM

Hi Carlos,

What directory are you in when you run the script? Where is the script in location to the in and out folders?

Did you change inPath = "in\" to inPath = "C:\PDF"? I'm not sure if it will correctly handle the absolute path.

Try adding the following line:
Wscript.Echo command
just above
objShell.Run(command)

That should output the command being run. Then try running it by hand and see if it is giving any errors.

Cheers,
Mark

Lars Nilsson 3/14/07 3:03 AM

Thanks Mark, this was really neat!

As for Matt's and Carlos problems I found similar or same problem, but found out why in my environment.
I tried FlashPaper on a newly installed virtual machine (no Acrobat Reader).

First problem, install program failed to register flash.ocx (Error 1904), but found a solution:
http://www.adobe.com/cfusion/knowledgebase/index.c...

Second problem: Acrobat Reader must be installed (not suprisingly of course..).

Third problem: Well, couldn't get it to dance with Acrobat Reader 8. Installed version 7.0.9 - that solved it.

As Acrobat Reader kicked in when running the script and not exiting I added this code to the script:
----------- Before looping the files:
adobeReader="""C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe"""
set objWshAdobe=CreateObject("WScript.Shell")
' Start the reader
Set objAdobe=objWshAdobe.Exec(adobeReader)
----------- And before exiting the program:
objAdobe.Terminate()

This gets the Reader window disappear after executing the script.

Thanks again Mark,
/Lars

Carlos & Jen 3/30/07 6:18 AM

Worked perfectly!

Thank you!!

ILYA 5/31/07 3:23 AM

If you need to convert large amount of PDFs or other printable documents to flash papers the Print2Flash may be a better choice. Print2Flash has APIs for automated document conversion.

VBScript example:
P2F = CreateObject(“P2F.Server”)
P2F.ConvertDir "C:\docs", "*.pdf", "C:\inetpub\www.mysite.com\swf"

Command line example:
p2fserver.exe C:\ Docs\*.pdf C:\inetpub\www.mysite.com\swf

In the examples all PDFs in the "C:\docs" folder are converted to Flash. The output files are written to the "C:\inetpub\www.mysite.com\swf" folder.

Print2Flash OLE Automation API objects can run using rights of a user different from the user which creates and uses these objects. This allows converting documents from server-side scripts like ASP or PHP.

Print2Flash batch processing also allows you to fine-tune document options like paper size, page orientation, printing resolution, etc.

Print2Flash official website:
http://print2flash.com

See help topics at
http://print2flash.com/help/BatchProcessing.php http://print2flash.com/help/EnhancedBatchProcessing.php" target="_blank">http://print2flash.com/help/EnhancedBatchProcessin... http://print2flash.com/help/AutomationAPIReference.php" target="_blank">http://print2flash.com/help/AutomationAPIReference...

Matt 6/14/07 5:08 AM

Came back to this one and finally got it working!

Problem now is that it is doing a useless job a compressing. A 216kb PDF at input is coming out as a 2MB swf and as a 2MB+ PDF !?

Memory of using flashpaper was that it done a great job at compression but now its performing like balls!

The input PDF properties states: WebFast= Yes , Created by Adobe..

The output PDF says WebFast=no and Created by PDFLib/C++

Im not sure why Im getting crap results now maybe its to do with Adobe 8? I'll try version 7 - if anyone knows how to get the best compression out of flashpaper please share.

M.

aenis 11/24/07 1:33 AM

i am having the same problem
the PDF files are larger then SWF
what can i do?

Carlos 1/16/09 2:47 PM

I recently noticed that if I convert pdf to swf with this script, the converted SWF have a large white border around the page. If I convert by hand with Flashpaper2, the converted swf do not have this white margin. I thought at first my pdf files had a white border and were not cropped to the edge, but they were. What would cause this script to add the extra white border? Anyone else have this issue?

Wayne Sudol 1/16/09 8:55 PM

Which script are you referring? The print2flash posted by ILYA or the original one posted by My. Lynch?

Page Turning Software 4/2/09 11:09 AM

If you circulate a publication then you want to know what your readers think and how they interact with your printed <a href=http://www.pageturnpro.com>Digital publication</a>. Unfortunately, print surveys for these publications are costly, time consuming and very rarely are they a 100% sampling of your audience.