Skip to content

Instantly share code, notes, and snippets.

@dougluce
Last active January 8, 2023 20:44
Show Gist options
  • Save dougluce/0c0de73f16563e592f5c11c1cb1dd449 to your computer and use it in GitHub Desktop.
Save dougluce/0c0de73f16563e592f5c11c1cb1dd449 to your computer and use it in GitHub Desktop.
Tiny hand-composed PDF for unit tests.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
%PDF-1.7
1 0 obj % The list of pages.
<<
/Type /Pages % Define the pages in the file.
/Count 1 % There's just the one.
/Kids [2 0 R] % It's defined in object 2.
>>
endobj
2 0 obj % Definition of our single, simple page
<<
/Type /Page
/Parent 1 0 R
/Resources <<
/Font <<
/F0 <<
/Type /Font
/BaseFont /Times-Italic
/Subtype /Type1
>>
>>
>>
/MediaBox [0 0 600 850]
/Contents 3 0 R
>>
3 0 obj % Contents of the page
<< /Length 314 >>
stream
BT % Begin text object
/F0 180 Tf % Use super-tall 180-point Times-Italic
30 Tz 40 Tc % Smush it narrow and space it out a bit
60 400 Td % Stick the text about in the middle
(Page Number 1) Tj % It'll be the page number
ET % End text object
endstream
endobj
4 0 obj % The page catalog
<<
/Type /Catalog
/Pages 1 0 R
>>
endobj
xref
0 0
trailer
<<
/Root 4 0 R
>>
startxref
984
%%EOF
@amcgregor
Copy link

🎤🔻

 %!PS
 showpage

And that's all you need to ship. To PDF-ize it (if you really need a PDF), run this source through ps2pdf, which also lets you pick a specific PDF version to target. (By way of ps2pdf12 tagged commands or -dCompatibilityLevel switch.) It can also be a one-liner in a Makefile or something:

sample.pdf: sample.ps
	echo -e " %!PS\n showpage" | ps2pdf - - > sample.pdf

(Mine has some software-generated commentary and extraneous metadata, but essentially not worth the effort to try to remove from a one-liner.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment