IAP GITLAB
Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
R
RemovePDFPageGroups
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ralf Ulrich
RemovePDFPageGroups
Commits
d70acd3f
Commit
d70acd3f
authored
May 11, 2020
by
Ralf M Ulrich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aaded script
parent
f26f1b8d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
strip_pdf.py
strip_pdf.py
+62
-0
No files found.
strip_pdf.py
0 → 100755
View file @
d70acd3f
#!/usr/bin/python3
import
re
,
sys
,
os
import
subprocess
def
is_tool
(
name
):
from
shutil
import
which
return
which
(
name
)
is
not
None
if
not
is_tool
(
'qpdf'
)
or
not
is_tool
(
'fix-qdf'
):
print
(
'This tool depends on the
\"
qpdf
\"
and
\"
fix-qdf
\"
tools. Please install first!'
)
sys
.
exit
(
1
)
if
(
len
(
sys
.
argv
)
!=
2
):
print
(
'Please pass name of pdf file to remove page groups from.'
)
sys
.
exit
(
1
)
print
(
sys
.
argv
)
filename
=
sys
.
argv
[
1
]
filename_name
,
filename_extension
=
os
.
path
.
splitext
(
filename
)
if
filename_extension
!=
".pdf"
:
print
(
"Can only handle pdf input files."
)
sys
.
exit
(
1
)
outfilename
=
filename_name
+
'.strip.pdf'
outfile
=
open
(
outfilename
,
'xb'
)
qpdf
=
subprocess
.
Popen
([
'qpdf'
,
'--qdf'
,
filename
,
'-'
],
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
text
=
True
)
fixpdf
=
subprocess
.
Popen
(
'fix-qdf'
,
stdin
=
subprocess
.
PIPE
,
stdout
=
outfile
,
stderr
=
subprocess
.
PIPE
)
output
,
err
=
qpdf
.
communicate
()
page_group
=
None
for
line
in
output
:
print
(
type
(
line
),
line
)
if
page_group
is
None
:
if
line
.
rstrip
()
==
b" /Group <<"
:
page_group
=
[
line
]
else
:
fixpdf
.
stdin
.
write
(
line
)
else
:
page_group
.
append
(
line
)
if
line
.
rstrip
()
==
b" >>"
:
break
else
:
if
page_group
:
fixpdf
.
stdin
.
write
(
b""
.
join
(
page_group
))
page_group
=
None
for
line
in
output
:
fixpdf
.
stdin
.
write
(
line
)
fixpdf
.
stdin
.
flush
()
fixout
,
fixerr
=
fixpdf
.
communicate
()
print
(
fixout
,
fixerr
)
if
page_group
:
stderr
.
write
(
b""
.
join
(
page_group
))
else
:
stderr
.
write
(
b"note: did not find page group
\n
"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment