Friday, January 11, 2008

Share a PDF Network Printer with Samba

Share a PDF printer with your entire network using Ghostscript, Samba, and Linux.

Ghostscript lets you freely print to PDF. However, maintaining Ghostscript on every client in your enterprise can be a nuisance. Consider installing it on a single Linux server instead. Then, use Samba to share it as a PDF printer to your entire network.

Before creating a PDF printer server, install a local PDF printer to test Ghostscript and make sure it fits your requirements. Note that some Linux distributions provide GNU Ghostscript (Version 7) instead of the more recent AFPL Ghostscript (Version 8). Factor this into your testing. You will probably want to compile AFPL Ghostscript for your Linux server, later.

The Server
Every Linux distribution should have Samba and Ghostscript packages that you can install painlessly. Use them. Later, consider downloading and compiling the latest AFPL Ghostscript.

Samba is powerful, so its configuration requires some skill and patience. Consult man smb.conf and edit smb.conf to suit your network. Exercise your favorite Internet search engine, and drop by http://us3.samba.org/samba/docs/using_samba/toc.html. When things aren't working, consult the log files (e.g., /var/log/samba). Don't forget to restart the samba service (e.g., /etc/init.d/samba restart) after changing smb.conf.

Create the directory /home/pdf_printer/output, and chmod it to 777. This is where new PDFs will be delivered. Share this directory with your network by adding this section to smb.conf and restarting Samba:

[pdf_output]

comment = Shared PDF Printer Output

path = /home/pdf_printer/output

; this next line is necessary only when security = share

guest ok = yes

browseable = yes

writeable = yes

In Windows, this share should be visible from the Network Neighborhood or My Network Places. If not, try digging into Entire Network Microsoft Windows Network. Also try the Search for Computers or Find Computer features. Sometimes, new resources aren't visible immediately. Sometimes, client configurations must be reviewed and changed, too.

Now, let's add a PDF Printer to Samba. Once you get it working, adapt the settings to your requirements. Maybe these settings are all you will need.

Download samba-print-pdf from http://ranger.dnsalias.com/mandrake/samba/, copy it into your server's /usr/local/bin directory, and chmod it to 755. Open this script in an editor to see what it does, and possibly change things, such as its Ghostscript OPTIONS.

Add the following section to smb.conf. It should work with Samba's share security model (security = share) or user security model (security = user). The user security model requires that a user provide a name and password before accessing the printer.

[pdf_printer]

comment = Shared PDF Printer

path = /tmp

; this next line is necessary only when security = share

guest ok = yes

printable = yes

use client driver = yes

print command = /usr/local/bin/samba-print-pdf %s \

/home/pdf_printer/output //%L/pdf_output %m %I "%J" &

lpq command =

lprm command =

Restart Samba and then try accessing the file share pdf_output from a client machine. If that works, you are ready to install the client printer.

The Windows Client
Install the Virtual Printer Kit (VPK). Right-click our network printer, pdf_printer, under My Network Places in the File Explorer. Select Connect . . . , and click OK. The Add Printer Wizard will open and ask which printer driver to install. Click Have Disk, browse over to the VPK printer driver that suits your client platform, and click OK. Select the Virtual PostScript Printer driver and click OK. Your new PDF network printer will appear in the computer's Printers folder. Print a test page to make sure it works properly.

Later, copy these Virtual PostScript Printer files to the pdf_output share so that you can access them easily across your network.

How to print PDF over internet?

Printing over the Internet brings the way people like to read and write to the way we plumb information in the 21st century. The idea is to enable authors to create documents using their favorite editor and then print it to a web site. Once on the web server, the PostScript print stream can be converted to PDF and posted online for reading or downloading. In this scenario, the author controls the source document and is responsible for maintenance.

This tips uses HTTP file submission to transfer PostScript to a web server. A more formal solution would use CUPS (http://www.cups.org). For a CUPS-based PDF creation server, try Alambic (http://alambic.iroise.net). Alambic supports HTTP and SMTP interfaces.

This tips demonstrates how to "print" a PostScript print stream to a web server. In our examples, we won't be printing to an elaborate document hosting service. Instead, we will print to the simple http://www.ps2pdf.com web site.

Currently, http://www.ps2pdf.com uses an old version of Ghostscript, so printing to your own, local version of Ghostscript will yield a better PDF.

Download and Install
Visit http://www.pdfhacks.com/submit_file/ and download submit_file-1.0.zip. Unzip this archive, and then copy SubmitFile.exe to a convenient location. This is a simple program that uses the Windows WinInet API to submit a local file to a web server. It then opens the default web browser to view the server's response. The source code is available and you should consult it for HTTP submission details.

Install a ps2pdf.com Printer
The procedure for creating an Internet printer is the same as the procedure for creating the PDF printer in [Hack #39], except you don't need to install Ghostscript. The configuration is also a little different.

Follow the Print to PDF instructions, except:

  1. You don't need to install Ghostscript.
  2. Name the new printer ps2pdf.com Printer instead of GS Pdf Printer.
  3. Name the new Redirected Port RPTWEB: instead of RPTPDF:.
  4. When configuring this new Redirected Port, use the settings in Table below
  5. RedMon port properties

    Field

    Value

    Redirect this port to the program:



    C:\redmon17\


    RedRun.exe

    Arguments for this program are:



    C:\pdfhacks\


    SubmitFile.exe/convert/convert.cgiwww.ps2pdf.cominputfile%1

    Output:

    Program Handles Output

    Run:

    Minimized


  6. Name the Redirected Port log file C:\pdfhacks\web_printer.log instead of C:\gs\pdf_printer.log
  7. Click OK to accept the new port settings.
  8. Click OK to accept the new printer settings and close the dialog.
The RedRun program takes the PostScript print stream and creates a temp file for it. RedRun then runs the program SubmitFile, replacing the %1 with the temp filename. Note that you should not put quotes around this %1, because RedRun seems to pad the temp filename with whitespace that disrupts the SubmitFile arguments.



Test Your ps2pdf.com Printer
Open the ps2pdf.com Printer properties dialog, click the General tab, and click Print Test Page. When your PDF is ready for download from http://www.ps2pdf.com, a browser will open with a hyperlink to follow.

If an error occurs, check the log file for feedback from RedRun or SubmitFile.

Note that the previous configuration is tailored to the current state of http://www.ps2pdf.com. The site administrators might choose to alter it at any time, requiring you to change this printer's configuration.

Sunday, January 6, 2008

How to Print to Image and Other Rasterizing Options

Thumbnail the cover or rasterize the entire document.
You might sometimes need to convert PDF to other graphics formats. You can easily add a "Print to Image" printer by following [Hack #39] and changing a few ingredients. Alternatively, rasterize your PDF documents using Adobe Acrobat or Photoshop. Because Photoshop gives you the most power, you might prefer to "Print to PDF" and then open these pages in Photoshop.

Install a PNG (or JPEG or TIFF) Printer
The procedure for creating a bitmap (e.g., TIFF, JPEG, PNG) printer is the same as the procedure for creating the PDF printer. The configuration is just a little different. In this example, we'll configure a PNG printer, but you just as easily can create a JPEG or TIFF printer. The DEVICE option determines what gets created. We discuss alternative devices a little later.

Follow the PDF Printer instructions, except:

Name the new printer GS png16m Printer instead of GS Pdf Printer.

Name the new Redirected Port RPTPNG16M: instead of RPTPDF:.

When configuring this new Redirected Port, name the options file C:\gs\png16m_printer.cfg instead of C:\gs\pdf_printer.cfg.

When configuring this new Redirected Port, name the log file C:\gs\png16m_printer.log instead of C:\gs\pdf_printer.log.

Create the file png16m_printer.cfg, referenced earlier. It is a text file of additional arguments passed to Ghostscript. An example is included with our Virtual Printer Kit. Change the paths to suit your Ghostscript and system setup.

-dSAFER

-dBATCH

-dNOPAUSE

-Ic:\gs\gs8.14\Resource

-Ic:\gs\fonts

-Ic:\gs\gs8.14\lib

-sFONTPATH=c:\WINDOWS\FONTS

-sDEVICE=png16m

-r72

-dTextAlphaBits=4

-dGraphicsAlphaBits=4

-dAlignToPixels=0

Using this procedure, you can create one printer for each image file format you commonly use.

"Print to Image" devices and options
The documentation that comes with Ghostscript (C:\gs\gs8.14\doc\index.htm) explains the available output devices (Devices.htm) and general options (Use.htm) that you can use in the configuration file.

Image output filenames
When printing a multipage document to one of these bitmap printers, the output filename must include the %d page number variable so that each page gets a unique filename. To pad this variable with three leading zeros, use %03d. On the Windows command line, the % must be represented by %%.

Acrobat: Save As Image
Beginning with Acrobat 5, you can open a PDF and then Save As . . . to JPEG, PNG, or TIFF image files. From the Save As . . . dialog, click the Settings . . . button to configure image options. You can set the image resolution, color space, and compression, among other things.

Photoshop: Open PDF
Photoshop is an ideal place to manipulate bitmaps, so it makes sense to open your PDF right in Photoshop. If your original document isn't a PDF, print one using Acrobat Distiller or our GS Pdf Printer. Open it in Photoshop, then Save As . . . to whatever format you want.

Mac OS X: Preview
Preview application that comes with Mac OS X lets you open PDF files and save them in a variety of graphics formats.

Unlock the secret powers of Distiller and Ghostscript.

Acrobat Distiller creates PDF based on its current profile setting. On Windows, choose a profile when you print by changing the Print >Properties >Adobe PDF Settings tab >Default Settings drop-down box. On a Macintosh, choose PDF Options from the drop-down box that starts out saying Copies & Pages instead of selecting the Adobe PDF Settings tab. When using Ghostscript, you can reference a joboptions file in pdf_printer.cfg.

Whenever you print to an Acrobat PDF printer, you can select a profile that creates the best PDF for your purpose. You can view and edit these profiles using the graphical Distiller application. The surprise is that these profiles, or joboptions files, are plain-text PostScript snippets that give you more control over Distiller than the GUI does. They are also compatible with Ghostscript, although Ghostscript does not implement all the possible settings. Indeed, the joboptions file (and its specification) is a good place to get the straight dope on what Distiller and Ghostscript can really do.

Acrobat Distiller Parameters Tell the Full Story
To fully understand Distiller and Ghostscript features, you must read the Acrobat Distiller Parameters document from Adobe. It is also the definitive guide to joboptions file parameters.

If you have Acrobat on your computer, open Distiller and select Help Distiller Parameters Guide, or search your disk for distparm.pdf. On the Macintosh, this file is in the Extras folder on the installer CD. The Acrobat 6 version of distparm.pdf is not available online except to paying Adobe ASN Developer Program members. The next best thing is the Acrobat 5 version, which is bundled with the freely downloadable Acrobat 5 SDK:

http://partners.adobe.com/asn/acrobat/download.jsp
Ghostscript users should also read C:\gs\gs8.14\doc\Ps2pdf.htm or, online:

http://www.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm
If you plan to deliver PDF to a service bureau, find out if they have a joboptions file you should use when creating your PDF.

Distiller joboptions Profiles
Acrobat Distiller's joboptions files are easy to view and modify using the Distiller GUI. Launch the Distiller application, and set Default Settings (Acrobat 6) or Job Options (Acrobat 5) to the profile you want to view or edit. Then, select Settings Edit Adobe PDF Settings (Acrobat 6) or Settings Job Options (Acrobat 5).

As noted earlier, this graphical interface does not give you access to all the settings documented in Acrobat Distiller Parameters. Because joboptions files are plain text, you can also view or edit them using a text editor.

Ghostscript joboptions Profiles
joboptions files are written in PostScript, so you can pass them to Ghostscript just before your input file using the -f option. Add a joboptions file to your GS Pdf Printer by appending it to the end of the pdf_printer.cfg file you created, like so:

-dSAFER

-dBATCH

-dNOPAUSE

-Ic:\gs\gs8.14\Resource

-Ic:\gs\fonts

-Ic:\gs\gs8.14\lib

-sFONTPATH=c:\WINDOWS\FONTS

-sDEVICE=pdfwrite

-r1200

-c save pop

-f c:\gs\pdfhacks.gs.joboptions


The file pdfhacks.gs.joboptions comes with our Virtual Printer Kit . It is organized and commented to make parameters easy to read and understand. Open it in your text editor and take a look. Edit it to suit your needs. Parameters not supported by Ghostscript are commented out.

If you need to manage a collection of these profiles, consider creating one GS Pdf Printer for each profile. Each printer would have its own Redirected Port, each port using its own cfg file, each cfg file referencing its own joboptions file.

Thursday, January 3, 2008

How to Maximize PDF Portability?

PDF version differences can affect you and your readers.
To best serve your readers, you should ensure that your PDF is compatible with their viewers. What PDF viewers are they running? Assume that they have at least upgraded to the previous version of Acrobat/Reader (or another, compatible viewer). PDFs created with the newest Acrobat might be incompatible with previous versions.

PDF Versions Overview
With each new version of Acrobat, Adobe introduces an updated version of the PDF specification. They go together,
In many cases, an older viewer still can read a newer-version PDF (although the viewer will complain). Its behavior depends on which new features the PDF uses. Which viewers implement newer features? Here are some highlights, selected for their bearing on mass distribution. For complete details, consult the PDF Reference, Versions 1.3, 1.4, and 1.5.

PDF 1.3 (Acrobat 4) introduced:
  • Digital signatures
  • File attachments
  • JavaScript support
  • Logical page numbering

PDF 1.4 (Acrobat 5) introduced:
  • Additional 128-bit encryption option
  • Additional JavaScript trigger events (document close, will save, did save, will print, did print)
  • Enhanced interactive forms

PDF 1.5 (Acrobat 6) introduced:
  • Additional file compression options
  • Additional encryption options

An older viewer can simply ignore many of the things it doesn't understand. The showstoppers are the compression or encryption features, because the viewer can't show the document if it can't read the streams.

If your PDF relies on newer JavaScript or forms features to work properly, prevent older viewers from opening your PDF. Determine the minimum PDF version your document requires and then apply the corresponding encryption using an empty password. Older viewers simply won't be able to read it.

Create Compatible PDFs
Out of the box, Distiller or PDFMaker yields PDFs that are compatible with the previous version of Acrobat. No problem.

When you open a PDF in Acrobat, modify it, and then save it, your PDF's version is upgraded silently to match Acrobat's. It is no longer compatible with the previous versions of Acrobat/Reader. This happens regardless of whether your PDF uses any of the new features.

Install older versions of Acrobat Reader and test your PDFs, if you are worried about how they'll look or function. Download old installers from http://www.adobe.com/products/acrobat/reader_archive.html or http://www.oldversion.com/program.php?n=acrobat.

One solution is to use the Reduce File Size feature in Acrobat 6 (File Reduce File Size . . . Compatible with: Acrobat 5.0 and later), which enables you to also set the compatibility level of the resulting PDF. Another solution is to use the PDF Optimizer feature (Advanced PDF Optimizer . . . ) and set the "Compatible with" field to "Acrobat 5.0 and later." A third option is to refry your PDF.

Tuesday, January 1, 2008

How to Create PDFs quickly and easily from any Macintosh OS X program?

Apple built a "Save As PDF" capability right into the Macintosh OS X Print dialog box. Any time you go to print a document, you can choose Save As PDF . . . from the bottom of the Print dialog box. Unfortunately, this approach provides no options and tends to produce large files, but at least it is a quick solution to producing PDFs. This option is available at the bottom left of any Print dialog box.

If you click the Save As PDF . . . button, a file dialog box will ask you where to put the resulting PDF file. Select a location, click OK, and the Mac will print to a PDF file.

There aren't any obvious configuration options for Save as PDF . . . , but if you have Mac OS X 10.3 or later, you can choose settings through the Filters tab of the ColorSync utility's Preferences window. (The ColorSync utility is in MacintoshHD:Applications:Utilities.) If you check PDF Workflow in the Domains tab, you'll be able to change your PDF options from the Print dialog box as well.

Optimization for Acrobat Distiller Profile

Select the best Distiller profile for your purpose.
When you use Acrobat's "Print to PDF" or use the PDFMaker macro for Word, Adobe's Distiller is the engine that creates your PDF. What kind of PDF do you need? You can configure Distiller to create the best PDF for your purpose. The choice is usually between document fidelity and file size. File size becomes an issue only when distributing a PDF electronically. When in doubt, choose fidelity.

Changing the Distiller Profile
Acrobat Distiller comes with a few preconfigured profiles. They are also called Settings or joboptions files. When printing to PDF, change the profile by clicking the Print dialog's Properties button (Windows), or by selecting PDF Options from the drop-down box that starts out saying Copies & Pages (Mac). Select the Adobe PDF Settings tab and select a Distiller profile from the Default Settings: (Acrobat 6) or Conversion Settings: (Acrobat 5) drop-down box. This choice is not permanent. To change the default profile, consult the Adobe PDF (Acrobat 6) or Acrobat Distiller (Acrobat 5) printer properties.

When using PDFMaker on Windows, change its profile inside Word by selecting Adobe PDF Change Conversion Settings . . . (Acrobat 6) or Acrobat Change Conversion Settings . . . (Acrobat 5). This choice, shown in Figure 4-6, becomes the default.

When creating a PDF for a print shop or service bureau, ask them for a joboptions file to use. On Windows, move it to Distiller's Settings folder, which is located somewhere such as C:\Program Files\Adobe\Acrobat 5.0\Distillr\Settings\. On the Macintosh, open Distiller and use the Settings Add Adobe PDF Settings . . . menu option to add it to the list. Then, select the print shop or service bureau's profile when creating your PDF, as described earlier.