Giter VIP home page Giter VIP logo

Comments (3)

JorjMcKie avatar JorjMcKie commented on July 22, 2024 1

You only rarely ever need to do PDF-to-PDF conversion at all. Previously, a valid motivation was to convert annotations and fields to become permanent parts of the pages. This is now gone since we have Document.bake().

For just getting a bytes object from the reduced PDF (some pages omitted) simply use Document.tobytes(...) - which is nothing else but a save() to memory instead of disk.

from pymupdf.

JorjMcKie avatar JorjMcKie commented on July 22, 2024
  1. We can only accept bug posts that can be reproduced. Your post has no reproducible data like a reproducing file.

  2. For building / copying page range subsets of a given PDF, you are using an inadequate method! What you are doing instead is a PDF-to-PDF conversion. As documented, this will work only if the source PDF contains no errors. Obviously this is not the case for your file - of course I am forced to guess here, given the circumstances.

I suggest you use one of the following approaches:

  • Directly create a subset of page numbers you are interested in. This happens by specifying a list of relevant 0-based page numbers. For example: doc.select([0, 2, 4, 8, 4711]). This will strip down the PDF accordingly - keeping intact things like the (relevant part of) the Table of Contents and more. As a side note: the page numbers must be in valid range, but they may contain duplicates and they need not be ascending.
  • Make a new (target) PDF and execute one or multiple target.insert_pdf() methods, specifing desired page ranges. This will lead to a target PDF without Table of Contents or other document-wide source PDF properties.

When done, don't forget to save the resulting PDF with maximum compression, i.e. execute method ez_save(...).

from pymupdf.

spreeni avatar spreeni commented on July 22, 2024

Thanks for the detailed reply @JorjMcKie!

I tried it with a couple other PDFs now and it works with them, so it seems to be an issue with the PDFs I have here. They are PDFs of concatenated scans in varying orientations. Sorry for not being able to provide them here for reproducability.

I am however getting the same error with target.insert_pdf() for these files. And as I was interested in getting a Python bytes object of the page in question (for DB storage and upload to an API), I still feel that doc.convert_to_pdf() seems to be a fitting option for this use case, or am I missing something?

But as it seems that this is an error in the PDF, this issue can be closed I suppose.

from pymupdf.

Related Issues (20)

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.