Skip to main content
Skip table of contents

Extracting PostScript comment information



Introduction

A common practice in PostScript is the use of PostScript comments (which start with a % character) to store metadata, often job control information that a PostScript consumer can act upon, usually a RIP inside a printer or a DFE driving a printing press.

This approach is even formalized in the Document Structuring Conventions, or DSC, a set of standards for PostScript which primarily specifies a way to structure a PostScript file and a way to expose that structure in a machine-readable way.

Mako 7.0.0 introduces a new mechanism in IDistiller (the Mako class for parsing PostScript into PDF) to capture his metadata, even when the namespace for it is not known.

The new IPSCommentMonitor interface enables users to detect comments within PostScript jobs. The original request was for detecting DSC comments, in this case looking for a %%BeginFeature comment to detect a toner save option, but IDistiller is also able to detect single percent comments, so we also support this.

How to use the new interface

A new API function has been added to IDistiller, setCommentMonitor() which allows a class derived from IPSCommentMonitor to be set, and this class will be used to define any comments the user is interested in and will allow the user to detect any comments.  The interface defines two abstract functions for this:

getComments() returns a list of comment keys that will be used to notify Jaws that the user is interested in any comment beginning with this key.  For example, a key of %%BeginFeature would notify that the user is interested in any comments beginning with "%%BeginFeature", such as "%%BeginFeature: documentsize a4", or "%%BeginFeature: tonersaving on".
comments() is a function that is invoked whenever Mako encounters a comment the user is interested in. The supplied RawString argument will contain the entire comment.

As a very simple example, a user could define a class as follows:

CPP
class CMyCommentMonitor : public IPSCommentMonitor
{
  public:
    CMyCommentMonitor()
    {
        // Set the comments we are interested in.
        m_comments.append("%%BeginFeature");
        m_comments.append("%%BoundingBox");
    }

    // Get the comments we've set.
    virtual const CRawStringVect &getComments() const
    {
        return m_comments;
    }

    // Called when a comment we are interested in was found.
    virtual void comment(const RawString &comment)
    {
        printf ("Found: %s\n", comment.c_str());
    }

  private:
    CRawStringVect m_comments;
};

And then set this using IDistiller::setCommentMonitor() to detect any comments beginning with "%%BeginFeature" or "%%BoundingBox".




JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.