# Introduction, Context

If PDF files are edited with inkscape, or generated with matplotlib, it is a 
typical scenario that PageGroups are part of those files. If multiple such 
PDFs are included, e.g. in latex. Only one of those PageGroups is used (there 
can only be one at least per page). It is not very clear to me if this is a misbehaviour 
of inkscape, latex or just a general problem in working with both of them. 

However, latex will produce warnings/errors in such cases pointing to the PageGroups.

With this script here, PDF files can be edited automatically to remove 
PageGroups. The internal structure of the PDFs is kept consistent, if needed
the xref tables are updated and fixed. The quality of the PDF is not affected. 
Also the size of the files is not affected (they become a few bytes shorter). 

This tool helped me to write and review papers for the CMS Collaboration 
where no errors on latex are allowed in the final step. 

# Warning  
**Use this tool with great care, do not trust its output blindly**. 
Make sure image-by-image that the
generated files are completely OK for the purpose they are indended for! Make
your own backup before starting to modify plots! I take no responsibility for
any damages or losses. You may use this script only on your own risk. 

I tested this on files editor with inkscape and generated by matplotlib with 
excellent results. Thus a workflow for files, where the normal application of
the script does not result in good results, it is worth trying to first import
in inkscape, re-export as pdf, the apply this script, check output. 

Note, this only works on single-page PDFs! It is only intended for individual
plots/images. 

# Usage

`./strip_pdf.py <file.pdf>`

The script will check if file.pdf has any PageGroups and only if one is found
it will create a security copy `file.save.pdf` and modify the original file
to remove the PageGroup. 


Ralf Ulrich
May 2020

# References

The starting point to this project were:

https://tex.stackexchange.com/questions/76273/multiple-pdfs-with-page-group-included-in-a-single-page-warning

https://www.mrunix.de/forums/showthread.php?73546-pdfTeX-warning-pdflatex-exe-PDF-inclusion-multiple-pdfs-with-page-group-included-in

There are actually options to edit PDF files based on "qdf" that will be more general -- which I did not need. Also QDF will change the files
in a much more invasive way also yieldig significantly larger files in the end.