1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.
  2. Better Analytics for WordPress Get It Free

Image DPI in a PDF

Discussion in 'PHP' started by TwistMyArm, Jun 12, 2008.

  1. #1
    Hi all,

    I have a collection of PDFs that I will be printing at varying dimensions. Does anyone know how I could go about analysing the images embedded in the PDF to determine the 'DPI' of each image in the actual printout?

    In reality, I can work out everything I need, so long as I can work out the dimensions of the 'element' that the images are in in the PDF.

    Hopefully that makes sense to somebody: if not, feel free to say! I'm looking to do it with PHP in a Linux environment. I have tried with pCOS but apparently it's not possible, though I'm happy to be corrected.

    If I need to pay for a library, I'm happy to do so, so long as the price, support and reliability are right.

    Thanks...
     
    TwistMyArm, Jun 12, 2008 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Man I hate bumpers, but I need all the help I can get right now :)

    If anyone can recommend any libraries for accessing image data (and the data of the element containing that image, specifically) in PDFs, I'd be more than appreciative!
     
    TwistMyArm, Jun 23, 2008 IP
  3. dev_SeeInside

    dev_SeeInside Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    do you have ImageMagick installed on your server? This makes it very easy to do what you're looking for (as easy as loading the image, and calling getImageResolution() function) and it works great with PHP.

    It's been a while since I've played with it, but I know it supports PDFs and it can do everything you need (I have worked with PDF files in the past, so I know it works!). Check out the Imagick extension, there's not very good documentation, but it's easy to figure out!

    Start here: ca3.php.net/imagick

    EDIT: Check out the developer's blog here: valokuva.org/?cat=1 (sorry, I can't post links yet)
    He's got some really interesting code samples there if you want to learn more..

    EDIT 2: Oh yeah, best of all, it's all FREE! :)
     
    dev_SeeInside, Jun 24, 2008 IP
  4. dev_SeeInside

    dev_SeeInside Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry, I misread your original post, i'm not sure about getting the dpi of each image within the PDF.. I know it works for getting/setting DPI on the file as a whole, even 1 page of a PDF at a time. As for individual page elements.. Sorry, I have no idea :S
     
    dev_SeeInside, Jun 24, 2008 IP
  5. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #5
    That is not a question that is asked frequently which is why you aren't getting any responses. I honestly see 2 major hurdles to overcome with this.

    1. getting the pictures out of the PDF. I'm sure you can go PDF -> JPG or PNG somehow but figuring out where the picture begins and ends is a different story. I assume the pics are of different size since you are trying to get the resolution from it so setting a cropping area will be a nightmare.

    2. If you "flatten" the pdf to a picture how does PHP (gd/ImageMagick/whatever) determine what 100% is? it's all just little RGB dots to a program and can't really tell when a picture gets blurry or pixelated.

    Frankly, I just don't think PHP and PDF play this well together and this is coming from someone who runs a site creating business forms to PDF files online. php -> pdf is much easier than pdf -> php.

    Pulling out embedded pictures or fonts as a separate object .. I don't think so. Open to being wrong though.
     
    ErectADirectory, Jun 24, 2008 IP