From 6c89d4b35bda528813b7ae9a39a1819af16a1fd0 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 21 Jun 2018 20:16:05 -0400 Subject: When splitting files, remove unreferenced objects (fixes #203) --- include/qpdf/QPDFPageDocumentHelper.hh | 6 ++++++ include/qpdf/QPDFPageObjectHelper.hh | 13 +++++++++++++ 2 files changed, 19 insertions(+) (limited to 'include') diff --git a/include/qpdf/QPDFPageDocumentHelper.hh b/include/qpdf/QPDFPageDocumentHelper.hh index d7d4a026..5847e078 100644 --- a/include/qpdf/QPDFPageDocumentHelper.hh +++ b/include/qpdf/QPDFPageDocumentHelper.hh @@ -52,6 +52,12 @@ class QPDFPageDocumentHelper: public QPDFDocumentHelper QPDF_DLL void pushInheritedAttributesToPage(); + // This calls QPDFPageObjectHelper::removeUnreferencedResources + // for every page in the document. See comments in + // QPDFPageObjectHelper.hh for details. + QPDF_DLL + void removeUnreferencedResources(); + // Add new page at the beginning or the end of the current pdf. // The newpage parameter may be either a direct object, an // indirect object from this QPDF, or an indirect object from diff --git a/include/qpdf/QPDFPageObjectHelper.hh b/include/qpdf/QPDFPageObjectHelper.hh index 9226a748..570e81b4 100644 --- a/include/qpdf/QPDFPageObjectHelper.hh +++ b/include/qpdf/QPDFPageObjectHelper.hh @@ -122,6 +122,19 @@ class QPDFPageObjectHelper: public QPDFObjectHelper void addContentTokenFilter( PointerHolder token_filter); + // A page's resources dictionary maps names to objects elsewhere + // in the file. This method walks through a page's contents and + // keeps tracks of which resources are referenced somewhere in the + // contents. Then it removes from the resources dictionary any + // object that is not referenced in the contents. This operation + // is most useful after calling + // QPDFPageDocumentHelper::pushInheritedAttributesToPage(). This + // method is used by page splitting code to avoid copying unused + // objects in files that used shared resource dictionaries across + // multiple pages. + QPDF_DLL + void removeUnreferencedResources(); + private: class Members { -- cgit v1.2.3-54-g00ecf