Skip to main content
Skip table of contents

Extracting PostScript comment information

📌 Overview

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 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 this metadata, even when the namespace for it is not known.

The new IPSCommentMonitor interface enables users to detect comments within PostScript jobs.

Although the requirement was for detecting DSC comments, in this case looking for a %%BeginFeature comment to detect a toner save option, IDistiller is also able to detect single percent comments, so we also support this.

📗 Instructions

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 allows the user to detect any comments.  

🪜 Steps

The interface defines two abstract functions for this:

  1. 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".

  2. 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.

⌨️ Sample Code

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".

☑️ Conclusion

The introduction of the IPSCommentMonitor interface in Mako 7.0.0 provides a powerful tool for extracting and monitoring PostScript comments, including those defined by the Document Structuring Conventions (DSC). By leveraging the setCommentMonitor() function in IDistiller, users can efficiently detect and act upon specific comments within PostScript jobs. This capability enhances the flexibility and control over PostScript processing, making it easier to manage metadata and job control information.

📚 Additional Resources

If you need additional help, see our API documentation for detailed information on class/method usage, or raise a support ticket via our customer portal.




JavaScript errors detected

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

If this problem persists, please contact our support.