Giter VIP home page Giter VIP logo

Comments (2)

m-holger avatar m-holger commented on July 2, 2024 1

Not the way the function cpp_pdf_split used by qpdf::pdf_subset is written. cpp_pdf_split copies the pages requested to a new empty pdf file, which looses all bookmarks, links, etc. To preserve bookmarks, cpp_pdf_split would need to remove any pages not requested from the input file. This would be a relatively trivial to implement.

from qpdf.

m-holger avatar m-holger commented on July 2, 2024 1

Sample implementation:

Rcpp::CharacterVector cpp_pdf_select(char const* infile, char const* outfile,
                                     Rcpp::IntegerVector which, char const* password){
  QPDF inpdf;
  read_pdf_with_password(infile, password, &inpdf);
  QPDFPageDocumentHelper in_pdh(inpdf);
  std::vector<QPDFPageObjectHelper> pages =  in_pdh.getAllPages();
  for (auto const& page :pages) {
    in_pdh.removePage(page);
  }
  for (int i = 0; i < which.size(); i++) {
    int index = which.at(i) -1; //zero index
    in_pdh.addPage(pages.at(index), false);
  }
  QPDFWriter outpdfw(inpdf, outfile);
  outpdfw.setStaticID(true); // for testing only
  outpdfw.setStreamDataMode(qpdf_s_preserve);
  outpdfw.write();
  return outfile;
}

from qpdf.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.