{
  "id": 6374667,
  "title": "A PDF Exporter With No PDF Library",
  "url": "https://urgent.news/2026/09/09/a-pdf-exporter-with-no-pdf-library",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-09T03:00:00.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/megapixel99/a-pdf-exporter-with-no-pdf-library-2hb9"
  },
  "original_language": "en",
  "account": "Longshot, a Firefox screenshot extension designed by me, exports screenshots as PDF files. Strikingly, the exporter is only 336 lines of code and relies on no external libraries. This is not due to a lack of relying on libraries to write everything, but rather because the PDF library would have performed two functions: handling image data and compressing data. In this case, these functions are already taken care of by the browser itself. The /DCTDecode filter indicates that the PDF stores image data as a JPEG bitstream, and the /FlateDecode filter indicates that the stream is zlib-wrapped deflate. Both of these filters can be handled natively by the browser through canvas.toBlob and CompressionStream. Consequently, the code for this exporter is considerably shorter than that of a general PDF library, which would need to handle typography, fonts, vector graphics, encryption, forms, and incremental updates among other features.\n\nOne potential pitfall with PDF files is the cross-reference table, which provides a byte offset for each object in the file. A single incorrect offset can render the entire document unreadable. Unlike higher-level components, this issue cannot be caught by the exporting process and will not be noticed until the file is opened later. To avoid this, the test suite checks the existence and correctness of the cross-reference table by seeking to the specified offsets and verifying the objects they point to.\n\nThe design of Longshot's exporter is such that it does not use any canvas APIs, thanks to a separate bridge component. This design decision allows the byte-level testing to occur in Node, without the need for a browser environment. The exporter also includes features such as splitting the document at page height for readability, using an invisible OCR layer with selectable and searchable text, and discarding low-confidence OCR recognitions. These choices help ensure that the searchable layer is both accurate and useful for users.",
  "summary": "Longshot, a Firefox screenshot extension I have been building, exports to PDF. The exporter is 336 lines and pulls in nothing. That is not a boast about writing things from scratch, which is usually a bad reason to do anything; it is that the two jobs a PDF library would do here are both already done by the browser, and once you notice that, the remaining work is smaller than the dependency would…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}