{"route":"/en-US-v0.14.1/reference/png/","title":"PNG","description":"Documentation for functions related to PNG in Typst.","part":null,"outline":[{"id":"summary","name":"Summary","children":[]},{"id":"exporting-as-png","name":"Exporting as PNG","children":[{"id":"command-line","name":"Command Line","children":[]},{"id":"web-app","name":"Web App","children":[]}]}],"body":{"kind":"category","content":{"name":"png","title":"PNG","details":"<p>Instead of creating a PDF, Typst can also directly render pages to PNG raster\ngraphics. PNGs are losslessly compressed images that can contain one page at a\ntime. When exporting a multi-page document, Typst will emit multiple PNGs. PNGs\nare a good choice when you want to use Typst's output in an image editing\nsoftware or when you can use none of Typst's other export formats.</p>\n<p>In contrast to Typst's other export formats, PNGs are bound to a specific\nresolution. When exporting to PNG, you can configure the resolution as pixels\nper inch (PPI). If the medium you view the PNG on has a finer resolution than\nthe PNG you exported, you will notice a loss of quality. Typst calculates the\nresolution of your PNGs based on each page's physical dimensions and the PPI. If\nyou need guidance for choosing a PPI value, consider the following:</p>\n<ul>\n<li>A value of 300 or 600 is typical for desktop printing.</li>\n<li>Professional prints of detailed graphics can go up to 1200 PPI.</li>\n<li>If your document is only viewed at a distance, e.g. a poster, you may choose a\nsmaller value than 300.</li>\n<li>If your document is viewed on screens, a typical PPI value for a smartphone is\n400-500.</li>\n</ul>\n<p>Because PNGs only contain a pixel raster, the text within cannot be extracted\nautomatically (without OCR), for example by copy/paste or a screen reader. If\nyou need the text to be accessible, export a PDF or HTML file instead.</p>\n<p>PNGs can have transparent backgrounds. By default, Typst will output a PNG with\nan opaque white background. You can make the background transparent using\n<code><span class=\"typ-key\">#</span><span class=\"typ-key\">set</span> <span class=\"typ-func\">page</span><span class=\"typ-punct\">(</span>fill<span class=\"typ-punct\">:</span> <span class=\"typ-key\">none</span><span class=\"typ-punct\">)</span></code>. Learn more on the\n<a href=\"/en-US-v0.14.1/reference/layout/page/#parameters-fill\"><code>page</code> function's reference page</a>.</p>\n<h2 id=\"exporting-as-png\">Exporting as PNG</h2>\n<h3 id=\"command-line\">Command Line</h3>\n<p>Pass <code>--format png</code> to the <code>compile</code> or <code>watch</code> subcommand or provide an output\nfile name that ends with <code>.png</code>.</p>\n<p>If your document has more than one page, Typst will create multiple image files.\nThe output file name must then be a template string containing at least one of</p>\n<ul>\n<li><code>{p}</code>, which will be replaced by the page number</li>\n<li><code>{0p}</code>, which will be replaced by the zero-padded page number (so that all\nnumbers have the same length)</li>\n<li><code>{t}</code>, which will be replaced by the total number of pages</li>\n</ul>\n<p>When exporting to PNG, you have the following configuration options:</p>\n<ul>\n<li>\n<p>Which resolution to render at by specifying <code>--ppi</code> followed by a number of\npixels per inch. The default is <code>144</code>.</p>\n</li>\n<li>\n<p>Which pages to export by specifying <code>--pages</code> followed by a comma-separated\nlist of numbers or dash-separated number ranges. Ranges can be half-open.\nExample: <code>2,3,7-9,11-</code>.</p>\n</li>\n</ul>\n<h3 id=\"web-app\">Web App</h3>\n<p>Click &quot;File&quot; &gt; &quot;Export as&quot; &gt; &quot;PNG&quot; or click the downwards-facing arrow next to\nthe quick download button and select &quot;Export as PNG&quot;. When exporting to PNG, you\nhave the following configuration options:</p>\n<ul>\n<li>\n<p>The resolution at which the pages should be rendered, as a number of pixels\nper inch. The default is <code>144</code>.</p>\n</li>\n<li>\n<p>Which pages to export. Valid options are &quot;All pages&quot;, &quot;Current page&quot;, and\n&quot;Custom ranges&quot;. Custom ranges are a comma-separated list of numbers or\ndash-separated number ranges. Ranges can be half-open. Example: <code>2,3,7-9,11-</code>.</p>\n</li>\n</ul>","items":[],"shorthands":null}}}