Skip to content

Instantly share code, notes, and snippets.

@Romern
Created January 1, 2024 22:30
Show Gist options
  • Save Romern/02ee6dc9230893d79fbb90959bd56fa1 to your computer and use it in GitHub Desktop.
Save Romern/02ee6dc9230893d79fbb90959bd56fa1 to your computer and use it in GitHub Desktop.
%!PS-Adobe-3.0 EPSF-3.0
%%Pages: 1
%%BoundingBox: 36 36 576 756
%%LanguageLevel: 1
%%EndComments
%%BeginProlog
%%EndProlog
% (a) (b) -> (ab)
% https://stackoverflow.com/questions/12378904/postscript-concatenate-two-strings
/concat { exch dup length
2 index length add string
dup dup 4 2 roll copy length
4 -1 roll putinterval
} bind def
/copyfile {
/outfilename exch def
/infilename exch def
/infile infilename (r) file def
/outfile outfilename (w) file def
{
% read chars from file to the buffer
infile read {
outfile exch write
} {
infile closefile
outfile closefile
exit
} ifelse
} loop
} def
/i 2 def
/processedfiles i dict def
{
{
(/tmp/input*.pdf) { %filenameforall
/filename exch def
/filenamebak filename (_bak) concat def
% check if file was already processed
processedfiles filename known not {
% put file into dictionay
processedfiles filename true put
% create copy for access after the file has been removed
filename filenamebak copyfile
% read first few bytes of file and check if we would be including ourselfves, which would be bad (magic bytes)
/fileobj filenamebak (r) file def
/header 15 string def
fileobj header readstring
pop pop
fileobj closefile
(%PDF-1.3\n%INDIC) header eq not {
header print
(\n) print
filenamebak print
filenamebak run
/i i 1 sub def
} if
} if
} 4096 string filenameforall
} stopped {} { } ifelse % error catching frame
i 1 lt {
exit
} if
} loop
showpage
0 quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment