Search This Blog

Showing posts with label pdf. Show all posts
Showing posts with label pdf. Show all posts

Sunday, 25 October 2015

WatchDirectory 4.9.2 released - free update

We just released version 4.9.2 of our File Monitoring Program WatchDirectory.

New / Changed in this release

A new plugin has been added so WatchDirectory can now print PDF files directly without need for Acrobat or Foxit Reader. This works more reliable, faster and is easier to setup.

If you use WxRemote's "Last Message" option, WatchDirectory used a very inefficient method to write those LastMessage files. This has been fixed.

The Email Task can now request a read receipt. Note that this depends on the receiver's email client if those receipts will be sent.

When a task starts and it finds that its history database is corrupt, it will automatically repair this database.

Download / Install

Download the current release here. Stop all your tasks and install this new release "on top" of your current installed version so it will keep all your settings and tasks.

Monday, 12 October 2015

WatchDirectory v4.9.2 beta - Print PDF Files

You can now download a new beta version of WatchDirectory.

New in this beta version

This new beta includes a native plugin to print PDF files. Previously WD printed PDF files by calling Acrobat Reader of Foxit Reader to do the actual printing. This new plugin should be more reliable and work faster.

This release also checks to see if the history database is corrupt. The typical reason why it becomes corrupt is a power failure or a forced Windows shutdown. When a task is starting and it finds a corrupt database it will auto-repair it.

Download / Install

See this forum post for download and install information.

Friday, 17 August 2012

Print downloaded PDF files automatically with WatchFTP

Q&A

A customer asked how he can automatically print PDF files downloaded by WatchFTP.

WatchFTP can start a batch file after downloading so we use a script to run Foxit Reader to print the file. One extra feature was needed: he wants to print invoices on one printer and tickets on another.

Here is an example bat file you can use for this:

SET FOXCMD=C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe
rem the printer for INV- files (printer names exactly as on your "Printers" control panel applet)
SET PRINTER1=Local Printer1
rem the printer for TIC- files
SET PRINTER2=\\Server\ServerPrinter 1
rem the printer for everything else
SET PRINTERDEFAULT=Local Printer2
rem a log file (taskname_yyyymmdd.log)
SET LOG=C:\Logs\%WF_CONFIG%_%WF_DATE%.log

rem check for valid file type, only PDFs are supported
IF "%WF_FILE_E%" NEQ "PDF" GOTO :Eof

rem get the first 4 positions of the filename
SET P4=%WF_FILE_N:~0,4%

SET PRINTER=%PRINTERDEFAULT%
IF /I "%P4%" EQU "INV-" (
   SET PRINTER=%PRINTER1%
)
IF /I "%P4%" EQU "TIC-" (
   SET PRINTER=%PRINTER2%
)
echo [%time%] printing %WF_FILE% to printer %PRINTER% >> "%LOG%"
"%FOXCMD%" /t "%WF_FILE%" "%PRINTER%"
IF %errorlevel% GEQ 1 GOTO :PrintFails
echo [%time%] printed >> "%LOG%"
GOTO :EOF

:PrintFails
echo [%time%] ERROR - FILE WAS NOT PRINTED >> "%LOG%"
GOTO :EOF

Thursday, 20 October 2011

After printing the PDF, I want to...

Some of the WatchDirectory plugins are actually small batch file scripts (.bat or .cmd). Those scripts are typically called by WatchDirectory when new files are detected.

For example, the "Print PDF using FoxIt Reader" plugin is a .bat script that calls Foxit to print the pdf.

Some customers want to have a bit of extra functionality after printing the PDF, for example Delete, Copy or Move the pdf. Here is how you do it, should be easy enough if you know a little bit of batch scripting.

Locate the batch Script to change

In this blogpost I will assume your WatchDirectory task is called PrintPDF, change the directory name below accordingly.

  • Make sure the task (PrintPDF) is not running while you make changes to its script
  • Inside the WatchDirectory Control Center select the menu "Tools -> Explore Task Directory"
    (this opens Windows Explorer inside the directory where WatchDirectory stores all its settings)
  • Navigate one directory "deeper" into the subdirectory with the name of your task (PrintPDF)
  • Inside this directory you will find a file called wd.bat, this is the script started by WatchDirectory

Make the changes

Open the file wd.bat in a text editor (notepad) and scroll to the bottom where you will find the following 2 lines

"%FOXCMD%" %OPTIONS% "%WD_FILE%" "%PRINTER%"
%ANNOTATE% Info done

Any changes you want to make after the file has printed should be just before the "%ANNOTATE%" line.

Delete the PDF after printing

Insert the following line

DEL "%WD_FILE%"

Move the PDF after printing

Insert the following line

MOVE "%WD_FILE%" "C:\Some Other Directory"

Print the PDF twice

Just repeat the FOXCMD line, like this

"%FOXCMD%" %OPTIONS% "%WD_FILE%" "%PRINTER%"
"%FOXCMD%" %OPTIONS% "%WD_FILE%" "%PRINTER%"
%ANNOTATE% Info done

Saturday, 27 February 2010

Print PDF files Automatically - with Foxit Reader

Please note: the new task mentioned in this blog is now part of the just released version 4.6.2 of WatchDirectory.

WatchDirectory already has a task called Automatically Print PDF files. That task uses Acrobat Reader in the background to print the PDF.

We found a way to use the fantastic free Foxit Reader to print PDF's. Foxit Reader proves to be much faster and, more important, more reliable than Acrobat Reader.

This new "Print PDF" plugin will be included in the next release of WatchDirectory.

When you use this new task, you must tell it where Foxit Reader is installed and on which printer it should print the PDF's. This is the printer name as it shows on the Windows Control Panel printers applet. No typo's allowed.

Printing from a Windows Service

Please note that Windows maintains the list of printers separately for each login account. When you configure a "Print PDF" task to run as a Windows Service (on the How to Run panel), the task will run as user "LocalSystem". LocalSystem most likely doesn't have your printers installed so you must tell Windows to run this Service as another user (as "You").

  • Inside the WatchDirectory Control Center select the menu
    "Tools -> Windows Services"
  • Locate the WatchDirectory Service for your task. If you called the task "PrintMyPdf", the Windows Service is called "watchDirectory:PrintMyPdf"
  • Open its settings (right-click -> Properties) and change the account information so it uses another user and password.

Saturday, 11 April 2009

Convert TIFF to PDF

A request we often get is a way to convert TIFF files to PDF with WatchDirectory.

While WD does not have a native way to do this, you should be aware that WD's "Automatically Run a Batch File" plugin can do almost anything. If there is a command line tool available, WatchDirectory can "run it".

Anyway, we have found 2 ways to convert TIFF to PDF using command line tools. The batch scripts below should be started by WD's "run a batch file" plugin. It is also a good idea to create a filter so WD will only start the script for TIF and TIFF files.

ImageMagick and Ghostscript

ImageMagick is one of my favorite tools for image manipulation. If a format is not "natively" supported by ImageMagick, it can delegate to other tools. ImageMagick needs Ghostscript for PDF support.

Downloads needed:
ImageMagick, I currently use v6.5.1, available here: http://www.imagemagick.org/script/binary-releases.php#windows.
Ghostscript, I currently use v8.6.3, available here: http://mirror.switch.ch/ftp/mirror/ghost/GPL/gs863/.

The ImageMagick/Ghostscript script. Note you don't see any reference to Ghostscript, but it must be installed otherwise the script won't work.

@echo off
IF "%WD_FILE_E%" NEQ "TIF" (
   IF "%WD_FILE_E%" NEQ "TIFF" GOTO :EOF
)
rem where is ImageMagick installed???
SET IMADIR=C:\Program Files\ImageMagick-6.5.1-Q16

"%IMADIR%\convert.exe" "%WD_FILE%" "%WD_FILE_D%\%WD_FILE_B%.pdf"
IF %ERRORLEVEL% NEQ 0 GOTO :EOF

rem if you want to remove the tiff after it has been converted
rem uncomment (remove the "rem") the next line
rem DEL "%WD_FILE%"

Irfanview

Another great tool, I didn't even know it supported command line conversions until Dirk (German language support) told me. You can download Irfanview here.

The Irfanview script:

@echo off
IF "%WD_FILE_E%" NEQ "TIF" (
   IF "%WD_FILE_E%" NEQ "TIFF" GOTO :EOF
)
rem where is Irfanview installed???
SET IMADIR=C:\Program Files\irfanview

"%IMADIR%\i_view32.exe" "%WD_FILE%" /convert="%WD_FILE_D%\%WD_FILE_B%.pdf"
IF %ERRORLEVEL% NEQ 0 GOTO :EOF

rem if you want to remove the tiff after it has been converted
rem uncomment (remove the "rem") the next line
rem DEL "%WD_FILE%"

IrfanView settings

Current releases of IrfanView will prompt you with a little popup window (to preview the PDF). Obviously, you don't want that when you are automating the creation of PDF files.

Just start IrfanView, open a TIFF file and save it as PDF. Next to the "Save As" window, where you enter the pdf filename, is a little window where you should select the "not needed" option. From now on, the script above will not cause those prompts.

Friday, 31 October 2008

Automatically split PDF into separate pages

Split PDF into separate pages

In a previous post I showed how to add a header page to a PDF using Pdftk. This example uses the same program to split a PDF into separate pages. See the previous post for Pdftk download info.

The previous post only mentioned WatchDirectory, but you can obviously also use WatchFTP's Batch File Action to do the same thing.

The Batch Script

Use the following batch script to let Pdftk automatically split the newly detected PDF.

If you want to use this script with WatchFTP, to automatically split downloaded PDF's into separate pages, you need to change some variable names in the script.
All variables that start with WD_ must be changed to WF_, for example %WD_REASON% in the script below must be changed to %WF_REASON%.

(The script does not show properly in some blog-readers, please copy it from the original post)

Make sure to properly configure the script in the first few lines (the variables PD and OUTDIR). You probably want to make sure the OUTDIR variable is not set to the directory your WatchDirectory task is monitoring. If it *is* set to that directory, WatchDirectory will call your script again (and again) for the split pages.

Friday, 5 September 2008

Automatically add a header page to new PDF documents

The example batch script below will combine 2 PDFs using the pdftk program (Auf Deutsch).
One of the PDF files is a "static" page that will be used as the "header" for the output PDF. The other PDF file is the file detected by WatchDirectory.

Download pdftk

You can download the Windows version of pdftk here:
http://www.accesspdf.com/article.php/20041130153545577

WatchDirectory task

Create a new task and select the run a batch file plugin. Select the sample batch script below (make sure you changed its settings the way you need). Make sure you only select the "FILENEW" option on the Events page.

The example batch script

Below is the example script. Please make sure to change the 3 settings starting on line 5 to the correct location of pdftk, the header.pdf you want to use and the output directory.
(The script does not show properly in some blog-readers, please copy it from the original post)

If you want the script to automatically delete the original PDF, remove the REM on the last line.

A small variation

If you want to add the static page as the last page of the new PDF, change line 15 from (original):

"%PD%" "%HDP%" "%WD_FILE%" cat output "%OUTDIR%\%WD_FILE_N%"

to (new):

"%PD%" "%WD_FILE%" "%HDP%" cat output "%OUTDIR%\%WD_FILE_N%"

Wednesday, 23 July 2008

Print PDF to any printer - Without Acrobat

The previous post showed how you can print to any printer with some "secret switches" passed to Acrobat Reader®. Here is another way to print PDFs without using Acrobat at all. This is a far more efficient way of printing as it doesn't need to load Acrobat.

For this to work, your printer must support direct printing of PDF/Postscript (nearly all Postscript Level 3 printers support this).

Create a file called AutoPrintPdf.bat using a plain text editor (notepad, do not use editors like MS Word!), and enter the following inside the file:

rem ignore files that do not have a PDF extension
IF "%WD_FILE_E%" NEQ "PDF" GOTO :EOF
rem ignore all events, except FILENEW (a new file is created)
IF "%WD_REASON%" NEQ "FILENEW" GOTO :EOF
rem send it to printerport "raw" on server "server"
LPR -S server -P raw "%WD_FILE%"

Replace server with the name or ip address of the server to which the printer is connected.
Replace raw with the name of the printer. If this name contains spaces, surround the name with "quotes".

Create a new watchDirectory task, select the Run an existing .bat file plugin.
Click the "EXBAT" variable, and browse/select the AutoPrintPdf.bat you have just created.
On the Filter Events page create a filter so this task will only process files with a PDF extension.
On the Events page, only select the FILENEW option.

Or just use Foxit Reader

The current WatchDirectory release has a new task that uses Foxit Reader to print PDF's. Please see this blogpost.

Monday, 21 July 2008

Print PDF to any printer

The current implementation of WatchDirectory's Print PDF plugin always prints to the default printer. Here is a small tip if you want to print to another printer.

This is what Adobe has to say on this subject:

The DDE command line parameters for Acrobat and Reader are as follows. These are unsupported but have worked for some developers.

AcroRd32.exe /p filename
- executes the Reader and prints a file
AcroRd32.exe /t path printername drivername portname
- Initiates Acrobat Reader, prints a file while suppressing the Acrobat print dialog box, then terminates Reader.

The four parameters of the /t option evaluate to path,printername, drivername, and portname (all strings).
printername - The name of your printer.
drivername - Your printer driver’s name. Whatever appears in the Driver Used box when you view your printer’s properties.
portname - The printer's port. portname cannot contain any "/" characters; if it does, output is routed to the default port for that printer.

Note: If using Acrobat, substitute Acrobat.exe in place of AcroRd32.exe in the command lines.

The current implementation of WatchDirectory's "Print PDF" plugin passes 2 parameters to Acrobat:
/p - like above: print the pdf
/h - undocumented - do not show Acrobat's window while printing

If you want to print to another printer than the default, you need to use the "Run Any Bat File" plugin (you will find it on "New Task -> Scripting") and use the following batch file to do the printing:

rem you may need to change this, where is acrobat reader?
SET ACRO=C:\Program Files\Acrobat\Reader\AcroRd32.exe
SET TIMEOUT=60
rem if the printername doesn't contain spaces, remove the "quotes"!
SET PRINTER="My Printer"
SET GDPU=%WD_INSTDIR%\GdPUtil.exe



rem check for valid file type
IF "%WD_FILE_E%" NEQ "PDF" (
   %ANNOTATE% Warn "File not printed, only PDF files are supported"
   GOTO :Eof
)

"%GDPU%" -runkill %TIMEOUT% "%ACRO%" /t "%WD_FILE%" %PRINTER%
%ANNOTATE% Info done

Please change the script as needed (printername, location of Acrobat Reader).

Adobe® and Acrobat® are registered trademarks of Adobe.