ImageMagick or GhostScript: convert a multi-page TIFF to a multi-page PDF

20,614

Solution 1

Use a tool called tiff2ps from the tool set provided by libtiff:

http://www.libtiff.org/tools.html

Once you have the tiff in ps format, you can call ps2pdf to convert to pdf, which is part of the ghostscript package in most linux distributions.

Solution 2

convert multipage.tiff -density 300x300 -compress jpeg multipage.pdf

This should work, though there can be some issues.

Solution 3

Use following code to generate multi page pdf from multi page tiff file:

<?php

$images = new Imagick($pathToYourFile);

foreach($images as $i=>$image) {
    $image->setImageFormat("pdf"); 
    $images->addImage( $image );
}

$images->writeImages($yourFileName.'.pdf', true);

?>
Share:
20,614
StackOverflowNewbie
Author by

StackOverflowNewbie

Updated on July 09, 2022

Comments

  • StackOverflowNewbie
    StackOverflowNewbie almost 2 years

    I need to convert a multi-page TIFF to a multi-page PDF. I have access to ImageMagick and GhostScript (in *nix environment). How do I do this? Thanks.

    UPDATE:

    It turns out that my test file was wrong (it didn't have multiple pages), which made me think my command was wrong. This seems to work for me: convert input.tif output.pdf

  • StackOverflowNewbie
    StackOverflowNewbie over 13 years
    won't this result in a 1 page PDF?
  • StackOverflowNewbie
    StackOverflowNewbie over 13 years
    is there a way to do this with just IM and/or GS?
  • Orbling
    Orbling over 13 years
    @StackOverflowNewbie: When I tried it, it resulted in a multipage PDF on my version. Seems to work the same as listing the files separately.
  • Orbling
    Orbling over 13 years
    @StackOverflowNewbie: Personally, I find IM can make a right hash of PDFs, so would probably split the TIFF using IM to single page PDFs, and use pdftk to combine them.
  • Missaka Wijekoon
    Missaka Wijekoon over 13 years
    Try 'convert original.tif output%d.tif' and see if it splits it into multiple files. Then in a script convert each to a postscript using Imagemagick. Then use ghostscript to print each ps file to the pdf device.
  • StackOverflowNewbie
    StackOverflowNewbie over 13 years
    what is the point of the intermediary step of converting TIFF to PS? If I can combine multiple TIFFs into a PDF directly, should I use that approach?
  • Missaka Wijekoon
    Missaka Wijekoon over 13 years
    Sure. It has been some time since I used ImageMagick, so the intermediate step was once necessary. If you can go straight in one step, as another poster has commented, do so. Otherwise if you do encounter problems, try my suggestion.
  • Kurt Pfeifle
    Kurt Pfeifle almost 13 years
    Your answer will basically work correctly. But you missed the option to use tiff2pdf directly (if you have a not-too-old libtiff). Please update your answer accordingly.
  • j0k
    j0k over 11 years
    Thanks for posting an answer! While a code snippet could answer the question it's still great to add some addition information around, like explain, etc ..
  • Dmitry
    Dmitry over 6 years
    The question does not ask for PHP solution.