-
Notifications
You must be signed in to change notification settings - Fork 0
/
strip_page_group.py
36 lines (32 loc) · 994 Bytes
/
strip_page_group.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# from Rufflewind
# https://tex.stackexchange.com/questions/76273/multiple-pdfs-with-page-group-included-in-a-single-page-warning
#
# Removes the pdf groups from the pdf.
# Usage of the whole toolchain:
# qpdf --qdf input.pdf - | python strip_page_group.py | fix-qdf >output.pdf
import re, sys
stdin = getattr(sys.stdin, "buffer", sys.stdin)
stdout = getattr(sys.stdout, "buffer", sys.stdout)
stderr = getattr(sys.stderr, "buffer", sys.stderr)
page_group = None
for line in stdin:
if page_group is None:
if line.rstrip() == b" /Group <<":
page_group = [line]
else:
stdout.write(line)
else:
page_group.append(line)
if line.rstrip() == b" >>":
break
else:
if page_group:
stdout.write(b"".join(page_group))
page_group = None
for line in stdin:
stdout.write(line)
stdout.flush()
if page_group:
stderr.write(b"".join(page_group))
else:
stderr.write(b"note: did not find page group\n")