blob: 37236434d01645a69a3d30ad45da0ff73dbf3f57 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta property="og:image" content="http://www.apache.org/images/asf_logo.gif" />
<!--
<link rel="stylesheet" type="text/css" media="screen" href="http://www.apache.org/css/style.css">
-->
<link rel="stylesheet" type="text/css" media="screen" href="https://www.apache.org/css/code.css">
<link href="/css/profile.css" rel="stylesheet" type="text/css" />
<link href="/css/xmlgraphics.css" rel="stylesheet" type="text/css" />
<link href="/css/print.css" rel="stylesheet" type="text/css" media="print" />
<script src="https://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.stoc.js"></script>
<script>
$(document).ready(function(){
$('ul#navigation a').each(function() {
if (this.href === window.location.href)
{ $(this). attr('id', 'forefront');}
});
$('ul#navigation a#forefront').each(function() {
});
})
$(function(){
$("#items").stoc({ search: "#content", stocTitle: "<h3>Page Contents</h3>" });
});
</script>
<style>
.highlight {color: red;}
</style>
</head>
<body>
<div id="banner">&nbsp;
</div>
<div id="navigation">
<style type="text/css">
/* The following code is added by mdx_elementid.py
It was originally lifted from http://subversion.apache.org/style/site.css */
/*
* Hide class="elementid-permalink", except when an enclosing heading
* has the :hover property.
*/
.headerlink, .elementid-permalink {
visibility: hidden;
}
h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
<p><a href="/"><img alt="Apache XML Graphics Project Logo" src="/images/apache-xml-graphics.gif" title="Apache XML Graphics Project" /></a></p>
<h1 id="xml-graphics-commons">XML Graphics Commons<a class="headerlink" href="#xml-graphics-commons" title="Permanent link">&para;</a></h1>
<ul>
<li><a href="/commons/">Overview</a></li>
<li><a href="/commons/download.html">Download</a></li>
<li>
<h2 id="documentation">Documentation<a class="headerlink" href="#documentation" title="Permanent link">&para;</a></h2>
<ul>
<li><a href="/commons/postscript.html">Tools for Adobe PostScript</a></li>
<li><a href="/commons/image-loader.html">Image Loader Framework</a></li>
<li><a href="https://cwiki.apache.org/confluence/display/XMLGRAPHICS/XmlGraphicsCommonComponents">XML Graphics Commons Components Wiki</a></li>
</ul>
</li>
<li>
<h2 id="information">Information<a class="headerlink" href="#information" title="Permanent link">&para;</a></h2>
<ul>
<li><a href="/commons/bugs.html">Bugs</a></li>
<li><a href="/commons/changes.html">Changes</a></li>
<li><a href="/repo.html">Code Repositories</a></li>
<li><a href="/mail.html">Mailing Lists</a></li>
</ul>
</li>
</ul>
<h1 id="apache-xml-graphics">Apache&trade; XML Graphics<a class="headerlink" href="#apache-xml-graphics" title="Permanent link">&para;</a></h1>
<ul>
<li>
<h3 id="project-overview">Project Overview<a class="headerlink" href="#project-overview" title="Permanent link">&para;</a></h3>
<ul>
<li><a href="/team.html">Who We Are</a></li>
<li><a href="/legal.html">Legal Stuff</a></li>
<li><a href="/charter.html">Project Charter</a></li>
<li><a href="/mail.html">Mailing Lists</a></li>
<li><a href="/repo.html">Code Repositories</a></li>
<li><a href="https://www.apache.org/foundation/sponsorship.html">ASF Sponsorship Program</a></li>
<li><a href="https://www.apache.org/foundation/thanks.html">ASF Thanks</a></li>
<li><a href="https://www.apache.org/licenses/">Licenses</a></li>
<li><a href="/security.html">Apache XML Graphics Security</a></li>
<li><a href="https://www.apache.org/security/">ASF Security</a></li>
</ul>
</li>
</ul>
<h1 id="sub-projects">Sub Projects<a class="headerlink" href="#sub-projects" title="Permanent link">&para;</a></h1>
<ul>
<li><a href="/batik/">Apache Batik</a></li>
<li><a href="/fop/">Apache FOP</a></li>
<li><a href="/commons/">Apache XML Graphics Commons</a></li>
</ul>
<h2 id="search-apache-xml-graphics">Search Apache XML Graphics<a class="headerlink" href="#search-apache-xml-graphics" title="Permanent link">&para;</a></h2>
<form name="search" id="search" action="https://www.google.com/search" method="get">
<input value="xmlgraphics.apache.org" name="sitesearch" type="hidden"/>
<input type="text" name="q" id="query" />
<input type="submit" id="submit" value="Search" />
</form>
<h3 id="apachecon-n-america">ApacheCon N. America<a class="headerlink" href="#apachecon-n-america" title="Permanent link">&para;</a></h3>
<p><a title="ApacheCon North America" href="https://www.apachecon.com"><img class="apachecon_logo" alt="ApacheCon North America" src="https://www.apachecon.com/images/landingpage/apachecon-logo.png" width="200" /></a><br /><br /></p>
<ul>
<li><strong><a href="https://www.apachecon.com/">ApacheCon NA</a></strong></li>
</ul>
<p>Hope to see you there!</p>
<h3 id="apachecon-europe">ApacheCon Europe<a class="headerlink" href="#apachecon-europe" title="Permanent link">&para;</a></h3>
<p><a title="ApacheCon Europe" href="https://www.apachecon.com"><img class="apachecon_logo" alt="ApacheCon Europe" src="https://www.apachecon.com/images/landingpage/apachecon-logo.png" width="200" /></a><br /><br /></p>
<ul>
<li><strong><a href="https://www.apachecon.com/">ApacheCon Europe</a></strong></li>
</ul>
<p>Hope to see you there!</p>
<a title="Apache Software Foundation" href="https://www.apache.org"><img id="asf_logo_url" alt="Apache Software Foundation " src="/images/asf_logo_url.png" width="200" /></a><br /><br />
<a title="Support the Apache Software Foundation" href="https://donate.apache.org/"><img id="asf_support_url" alt="Support the Apache Software Foundation " src="https://blogs.apache.org/foundation/mediaresource/d67ca611-a57c-462d-ac23-95063f81d175" width="200" /></a>
<script>
$(document).ready(function () {
    $('#navigation :header').click(function () {
        var text = $(this).siblings('ul');
        if (text.is(':hidden')) {
            text.slideDown('200');
        } else {
            text.slideUp('200');
        }
    });
    if ($('#navigation :header').siblings('ul')) {
$('#navigation :header').append(' &raquo;');
    }
$('#navigation > ul > li ul').hide();
var str=location.href.toLowerCase();
$("#navigation li a").each(function() {
if (str.indexOf(this.href.toLowerCase()) > -1) {
$(this).parents().slideDown('200');
$("li.highlight").removeClass("highlight");
$(this).parent().addClass("highlight");
}
});
})
</script> </div>
<div id="bannertext" style="border-bottom: 2px dashed #666666; height: 60px;">
<a href="/"><img src="/images/apache-xml-graphics.gif" alt="The Apache FOP Project" width="226" height="51" style="float:left; margin-right: 15px;" /></a>
<h2>The Apache&trade; XML Graphics Project</h2>
</div>
<div id="content" class="grid_16">
<div id="items">
</div>
<div class="section-content"><style type="text/css">
/* The following code is added by mdx_elementid.py
It was originally lifted from http://subversion.apache.org/style/site.css */
/*
* Hide class="elementid-permalink", except when an enclosing heading
* has the :hover property.
*/
.headerlink, .elementid-permalink {
visibility: hidden;
}
h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style>
<h1>Tools for Adobe PostScript</h1>
<h1>Tools for Adobe PostScript</h1>
<h2 id="overview">Overview</h2>
<p>Apache&trade; XML Graphics Commons contains various tools for writing and processing Adobe PostScript files. This includes:</p>
<ul>
<li>
<p>A PostScript generator class which helps writing PostScript files from scratch.</p>
</li>
<li>
<p>Two Graphics2D implementations, one for plain PostScript and one for writing Encapsulated PostScript (EPS).</p>
</li>
<li>
<p>A DSC-parser/processor: Parse, post-process and change DSC-compliant PostScript files.</p>
</li>
</ul>
<blockquote>
<p><strong>NOTE:</strong></p>
<p>We don't currently include a PostScript interpreter though we would love to have one. A Java-based PostScript interpreter to keep an eye on is the one from the <a href="http://foray.sourceforge.net">FOray project</a>.</p>
</blockquote>
<h1 id="generator">The PostScript generator</h1>
<p>The "PSGenerator" class can help writing PostScript files. It deals with things like escaping, saving/tracking/restoring graphics state, writing DSC comments and tracking of DSC resources.</p>
<p>You will rarely interact with the PS generator itself, as it is probably more interesting to generate a PostScript file using Java2D which is described in the following section.</p>
<h2 id="java2d">Java2D: Graphics2D implementation for generating PostScript and EPS</h2>
<p>We provide two classes (PSDocumentGraphics2D and EPSDocumentGraphics2D) which you can use to generate complete PostScript files using normal Java2D means. The difference between the two classes is that the EPS variant creates a fully compliant Encapsulated PostScript file while the PS variant simply creates a normal DSC-compliant level 2 PostScript file. It depends on your requirement which variant you choose. The PS variant is mostly for printing purposes while the EPS variant is better suited for inclusion in other documents.</p>
<h3 id="creating-eps">Creating an EPS file</h3>
<p>Creating an EPS file using the Graphics2D implementation is easy. Instantiate EPSDocumentGraphics2D, set a GraphicContext and set up the output document. Here's an example:</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D</span><span class="o">;</span>
<span class="o">[..]</span>
<span class="n">EPSDocumentGraphics2D</span> <span class="n">g2d</span> <span class="o">=</span> <span class="k">new</span> <span class="n">EPSDocumentGraphics2D</span><span class="o">(</span><span class="kc">false</span><span class="o">);</span>
<span class="n">g2d</span><span class="o">.</span><span class="na">setGraphicContext</span><span class="o">(</span><span class="k">new</span> <span class="n">org</span><span class="o">.</span><span class="na">apache</span><span class="o">.</span><span class="na">xmlgraphics</span><span class="o">.</span><span class="na">java2d</span><span class="o">.</span><span class="na">GraphicContext</span><span class="o">());</span>
<span class="c1">//Set up the document size</span>
<span class="n">g2d</span><span class="o">.</span><span class="na">setupDocument</span><span class="o">(</span><span class="n">out</span><span class="o">,</span> <span class="mi">400</span><span class="o">,</span> <span class="mi">200</span><span class="o">);</span> <span class="c1">//400pt x 200pt</span>
<span class="c1">//out is the OutputStream to write the EPS to</span>
<span class="n">g2d</span><span class="o">.</span><span class="na">drawRect</span><span class="o">(</span><span class="mi">10</span><span class="o">,</span> <span class="mi">10</span><span class="o">,</span> <span class="mi">50</span><span class="o">,</span> <span class="mi">50</span><span class="o">);</span> <span class="c1">//paint a rectangle using normal Java2D calls</span>
<span class="n">g2d</span><span class="o">.</span><span class="na">finish</span><span class="o">();</span> <span class="c1">//Wrap up and finalize the EPS file</span>
</pre></div>
<p>A complete example for generating an EPS files can be found in the <a href="http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/examples/java/java2d/ps/">"examples" directory</a> in the distribution.</p>
<h2 id="dsc">DSC parser/processor</h2>
<p>Many PostScript files use special comments to structure a document. This allows manipulation of PostScript files without interpreting them. These special comments are defined in the <a href="http://partners.adobe.com/public/developer/en/ps/5001.DSC_Spec.pdf">Document Structuring Conventions</a>. The code in Commons is designed to work with DSC 3.0. For details on how DSC is used, please take a look at the DSC specification.</p>
<p>The DSC support in Commons was primarily developed to implement resource optimization features in <a href="http://xmlgraphics.apache.org/fop/">Apache FOP</a> 's PostScript output support. Resources like images which are used repeatedly in a document should not be written to the PostScript file each time it is used. Instead it is written once at the beginning of the file as a PostScript form. The form is then called whenever the image needs painting.</p>
<p>But the DSC parser could potentially be used for other purposes. The most obvious is extracting a subset of pages from a DSC-compliant file. Assume you want to print only page 45 to 57 of a particular document. There's an example that demonstrates exactly this. Check out the "examples" directory in the distribution. Other potential use cases for the DSC parser are:</p>
<ul>
<li>
<p>Patching PostScript files, for example, adding OMR marks for automatic packaging</p>
</li>
<li>
<p><a href="http://en.wikipedia.org/wiki/Imposition">Imposition</a> (2-up, n-up, rotation, etc.)</p>
</li>
<li>
<p>EPS graphic extraction</p>
</li>
<li>
<p>Inspecting the page count</p>
</li>
<li>
<p>etc. etc.</p>
</li>
</ul>
<p>The DSC parser (DSCParser) was designed as a pull parser, i.e. you fetch new events from the parser inspecting them and acting on them as they are found. If you prefer to work with a push parser, you can pass the DSCParser a DSCHandler implementation and the parser will send you all the events.</p>
<p>The best example to understand how to use the DSC parser is the PageExtractor class that implements the page extraction functionality mentioned above.</p>
<blockquote>
<p><strong>NOTE:</strong></p>
<p>The DSC parser is not considered feature-complete. The basic infrastructure is there but, for example, not all DSC comments are available as concrete Java classes. If you need to extend the DSC parser for your own use cases, please send us your patches.</p>
</blockquote>
</div>
</div>
<div class="clear"></div>
<div id="footer">
<div class="copyright">
<div style="float:left; padding: 7px;">
<a title="Apache Software Foundation" href="http://www.apache.org"><img id="asf-feather-logo" alt="Apache Software Foundation" src="/images/asf_logo_url.png" width="200" /></a>
</div>
<p>
Copyright &copy; 2016 The Apache Software Foundation, Licensed under
the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
<br />
Apache, Apache XML Graphics, Apache FOP, Apache Batik, the Apache feather logo, and the
Apache XML Graphics logos are trademarks of <a href="http://www.apache.org">The Apache
Software Foundation</a>. All other marks mentioned may be trademarks or registered
trademarks of their respective owners.
<br />
</p>
</div>
</div>
</body>
</html>