Coder Social home page Coder Social logo

Comments (3)

dwarring avatar dwarring commented on September 26, 2024

This PDF has image resources, rather than inline images. If every page has an image resource named FFX1, then to get at the raw image data:

use PDF::API6;
use PDF::XObject::Image;

my PDF::API6 $pdf .= open: "test.pdf";

my $n := $pdf.page-count;
my PDF::XObject::Image @images = (1 .. $n).map: -> $page-num {
    $pdf.page($page-num)<Resources><XObject><FXX1>;
}

with @images.head -> $img {
    my blob8 $raw-compressed = $img.encoded.encode('latin-1');
    my blob8 $raw-uncompressed = $img.decoded;
    # partially implemented. probably returns Nil
    note (try $img.to-png1).WHAT.raku;
}

However, a PDF may contain several image formats, and the to-png is only partially implemented for some image formats. It will most likely return Nil rather than an object of PDF::Content::Image::PNG. It could be that image magick, or other image manipulation libraries can load the raw compressed or uncompressed data.

Reading of images from PDF files could, in general, do with a lot more work. I'd been thing of trying to integrate MagicWand, or something similar, but would need to investigate further.

from pdf-api6.

vrurg avatar vrurg commented on September 26, 2024

Thank you! I expected the format to be anything but hoped that perhaps PDF::To::Cairo can manage it. But with the current state of affairs it looks like using something like pdftoppm would be preferable.

BTW, unrelated. A while ago I desperately wanted to intercept PDF rendering to pull out data from it. No idea how I managed to overlook PDF::API6 being capable of this, but at the moment I'm biting own elbows seeing the possibilities I would have!

from pdf-api6.

dwarring avatar dwarring commented on September 26, 2024

pdftoppm Sound reasonable.

Yeah PDF::To::Cairo is just an advanced application of rendering also available in PDF::API6. PDF::Tags::Reader is another example that renders to extract structure and text from a tagged PDF file.

from pdf-api6.

Related Issues (16)

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.