Coder Social home page Coder Social logo

setapdf-imageextractor's Introduction

SetaPDF-ImageExtractor

This package is a proof of concept to extract images from PDFs in pure PHP with the SetaPDF-Core component and an image render module. Currently, not all kinds of images are supported. This is also very dependent on your used image renderer library. GD and Imagick are currently implemented. We recommend you to use Imagick as it's more feature complete as GD but may be a little harder to install.

Requirements

This package is developed and tested on PHP >= 7.4.

You'll need an active license of the SetaPDF-Core component.

Requirements of the SetaPDF-Core component can be found here.

Usage

This example here extracts all images from the first page of the pdf:

$document = SetaPDF_Core_Document::loadByFilename('your-pdf-file.pdf');
$images = \setasign\SetaPDF\ImageExtractor\ImageExtractor::getImagesByPageNo($document, 1);
foreach ($images as $imageData) {
    // if you're using imagick
    $imagick = \setasign\SetaPDF\ImageExtractor\ImageExtractor::toImage($imageData, ImageExtractor::IMAGE_RENDERER_IMAGICK);
    $imagick->setImageFormat('png');
    $image = $imagick->getImageBlob();
    $imagick->destroy();
    echo '<img src="data:image/png;base64,' . base64_encode($image) . '"/>';

    // if you're using gd use this code instead
    $gd = ImageExtractor::toImage($imageData, ImageExtractor::IMAGE_RENDERER_GD);
    ob_start();
    imagepng($gd);
    $image = ob_get_clean();
    imagedestroy($gd);
    echo '<img src="data:image/png;base64,' . base64_encode($image) . '"/>';
}

License

This package is open-sourced software licensed under the MIT license.

setapdf-imageextractor's People

Contributors

janslabon avatar maximiliankresse avatar

Watchers

 avatar  avatar

setapdf-imageextractor's Issues

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.