Jump to content

FM printing to PDF FREE! Solution for PC's


onefish

This topic is 6827 days old. Please don't post here. Open a new topic instead.

Recommended Posts

After working on this for a while I have finally sorted out a free solution to print to PDF from FM. This solution has many other benefits as well such as:

The free PDF distiller can be set up and used for any PC printing requirements;

The solution effectively works around the limitations of FM changing printers without a plugin;

In my current solution, all printed layouts are printed to PDF and the document opened in front of the database in the centre 1/2 of the screen and full screen height. This is a very effective print preview with the option to save as, print, or just close. The temp PDF directory is cleared by a script run upon exiting FM.

To make this solution work for you, you will need to download the following software which is under GPL (you can still sell your solutions).

PDFCreator you will want the GPL version if you intend to sell your solution. Note, the attached scripts were developed to work with the GPL version and I have not tested them with the APL version of PDFCreator.

AutoIT you may also wish to download SciTe throught the link at AutoIT. It is not necessary but makes writing and testing AutoIT scripts much easier.

Just do a normal install of PDFCreator, you probably don't want the tray and desktop shortcuts though.

Now to bypass the change printer bug in FM all we have to do is change the default windows printer in the registry as the first step of the FM print script and then change it back after the print is complete. In this case we want to change it to the PDFCreator. PDFCreator has some settings that we also want to change in the registry for each print. These settings are:

AutoSaveDirectory

AutoSaveFileName

AutoSaveFormat

NoConfirmMessageSwitchingDefaultprinter

RunProgramAfterSaving

RunProgramAfterSavingProgramname

StartStandardProgram

UseAutoSave

UseAutoSaveDirectory

Some of these settings are hidden and can only be changed in the registry, the rest can be changed and personalised by the user. Information about these settings can be found in the PDFCreator help file. As with changing the Windows default printer, we only want to change the settings for the desired print and then change them back. This enables PDFCreator to be setup and used by the user to create PDF documents from other applications.

We use two scripts to do this, 1 initiated by Filemaker through sendevent "open" and the other run by PDFCreator after the PDF doc has been saved.

The attached AutoIT scrip "PDFsetup" is the first. This script cache the users settings for PDFCreator and the default Windows printer to registry directory "HKEY_CURRENT_USERSoftwareICHMSSetup". ICHMS is the name of my current project and you can change it if you like. This script also saves a timestamp used by the second script to rename the PDF file. This script then sets PDFCreator to the default Windows printer and changes the PDFCreator settings to auto save and run the second script when the PDF is saved.

Carry on with your print script in filemaker and print to PDFCreator. This should be scripted without user intervention to stop confusion. That's all from FM, just the one send event at the begining of the print script.

When the PDF document is saved PDFCreator will run the attached script "OpenPDF". This script initiates a loop checking if the PDF document exists and exits when it does or alternatively and after about a minute of the file not existing, shows a message box and restores the registry values that were changed in the first script with those stored in "HKEY_CURRENT_USERSoftwareICHMSSetup", then halts the script. This is required as large reports may take a few seconds to be processed. When the PDF file exists the script pauses for 1/2 second then renames the file with the timestamp stored in the registry by the first script then begins another loop checking if the file with the new name exists. Again if there are any errors the loop times out after about 1 minute and shows the user a message box and restores the registry values that were changed in the first script with those stored in "HKEY_CURRENT_USERSoftwareICHMSSetup" and halts the script. When the renamed file exists the script again pauses 1/2 second then opens it with the users default PDF viewer and snaps the document to the screen height and the middle 1/2 of the users screen. Now since the script did not encounter any errors it restores the registry values that were changed in the first script with those stored in "HKEY_CURRENT_USERSoftwareICHMSSetup".

This system generates a unique name using the timestamp for each file so it is possible to have more than one PDF document produced through the script open at one time. The down side of this is that there is the potential to store up a lot of unwanted PDF documents over time. To stop this happening create a FM script that runs upon closing the file and have it sendevent to an AutoIT script that deletes all *.PDF documents in the temp directory the files are automatically saved to. The attached script "DeletePDF" does exactly that.

In this example I am using the PDF document as a print preview that can be previewed, printed, "Save As" or directly emailed if required. I have not tried but the technique of changing the default windows printer in the registry may also work for printing to different printers within the same file or script.

In order for the attached AutoIT scripts to work properly they will have to be compiled into executable files. I have left them as text documents so you can change directories and things as necessary for your application. If you cannot open them, you did not install SciTe. Just change the file extension to .txt and use notepad.

The directories required for the attached scripts to function are:

c:Program FilesICHMSScripts (place all executable scripts in here)

c:ICHMStemp (the temporary drictory that the PDF docs are saved in)

You can change these but you must also change all references in the scripts. Good luck and I hope this is useful for someone else. It has replaced a need for two very expensive plugins for me.

Au3_Scripts.zip

Link to comment
Share on other sites

  • 2 weeks later...

Wow, I wish I had known about those free PDF exporters earlier.

But just so you know, I also recently encountered a free "Print to PDF" program called CutePDF. While its name may not sound too professional, I've been using it successfully for the past few weeks. And while it may lack some of the features found in others programs, it will get the job done too.

Link to comment
Share on other sites

This topic is 6827 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.