2011-01-17 35 views

Respuesta

1

utilizar una herramienta llamada tiff2ps del conjunto de herramienta proporcionada por libtiff:

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

vez que tenga el TIFF en formato PS, puede llamar ps2pdf para convertir a pdf, que es parte del paquete ghostscript en la mayoría de las distribuciones de Linux.

+0

hay una manera de hacer esto con sólo IM y/o GS? – StackOverflowNewbie

+0

Pruebe 'convertir original.tif output% d.tif' y vea si lo divide en varios archivos. Luego, en un script, conviértalos a una posdata usando Imagemagick. Luego use ghostscript para imprimir cada archivo ps en el dispositivo pdf. –

+0

¿Cuál es el punto del paso intermedio de convertir TIFF a PS? Si puedo combinar múltiples TIFF en un PDF directamente, ¿debería usar ese enfoque? – StackOverflowNewbie

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

Esto debería funcionar, aunque puede haber algunos problemas.

+0

¿no dará como resultado un PDF de 1 página? – StackOverflowNewbie

+1

@StackOverflowNewbie: cuando lo probé, resultó en un PDF de varias páginas en mi versión. Parece que funciona igual que enumerar los archivos por separado. – Orbling

+0

@StackOverflowNewbie: Personalmente, me parece que IM puede hacer un hash correcto de archivos PDF, por lo que probablemente dividiría el TIFF utilizando archivos PDF de una sola página y usaría pdftk para combinarlos. – Orbling

0

Tuve una situación similar de convertir un archivo TIFF multipágina. pero en mi caso, la extensión resultante fue una miniatura JPG. Sin embargo, creo que este código siguiente se ejecutará para convertir TIFF a PDF. http://sourcecodemania.com/how-to-convert-text-to-speech-with-php/

<?php 
try 
{ 
// Saving every page of a TIFF separately as a JPG thumbnail 
$images = new Imagick("testing.tif"); 
foreach($images as $i=>$image) { 
    // Providing 0 forces thumbnail Image to maintain aspect ratio 
    $image->thumbnailImage(768,0); 
    $image->writeImage("page".$i.".jpg"); 
    echo "<img src='page$i.jpg' alt='images' ></img>"; 
} 
$images->clear(); 
} 
catch(Exception $e) 
{ 
     echo $e->getMessage(); 
} 
?> 

Los comentarios son bienvenidos http://www.sourcecodemania.com

0
#!/bin/bash 
# scanadf frontend 
# kdialog info at http://techbase.kde.org/Development/Tutorials/Shell_Scripting_with_KDE_Dialogs#Menu_and_Selection_Dialogs 
# i/o redirection at http://tldp.org/LDP/abs/html/io-redirection.html 
# variable to file i/o at http://www.linuxquestions.org/questions/programming-9/bash-script-%96-reading-and-writing variables-to-a-separate-file-365158/ 
# 
#rev. 1.2 03.02.12 
# 
#NOTE: TO RUN THIS SCRIPT YOU WILL NEED TO CREATE THE DIRECTORIES REFERRED TO IN THE SCRIPT. 
#THE ANSWER TO THE QUESTION IS THE TWO-PASS COMMANDS BELOW "convert" and "gs" 
#THE CONVERT COMMAND COMBINES ALL THE TIFFS IN THE DIRECTORY INTO A SINGLE PDF 
#THE GS (GHOSTSCRIPT) COMMAND RESIZES TO 8.5X11 AND COMPRESSES 
# 
# 
#THIS IS A KDIALOG SCRIPT AND WILL ONLY RUN IN KDE. KDIALOG COMMANDS COULD BE REPLACED BY DIALOG COMMANDS 
#ALTERNATIVELY, THE KDIALOG COMMANDS COULD BE REPLACED BY COMMAND LINE COMMANDS AND RUN IN A TERMINAL. 
# 

yn1=1 
cd ~/.getscan/ 
. config 
while [ $yn1 = 1 ]; 
do 
    cd ~/.getscan/tmp/ 
    kdialog --title "scanner activated" --passivepopup "scanner warming up" 
    if [ $scnr = 2 ];then 
     scanadf --mode $clr --resolution $res -y 279 --source 'Automatic Document Feeder(left aligned,Duplex)' 2>test.txt 
    else 
     scanadf --mode $clr --resolution $res -y 279 2>test.txt 
    fi 
    err1=$(cat test.txt) 
    rm test.txt 
# 
#scanner error trap 
# 
    if [ $? = 1 ];then 
    kdialog --title "scanner error" --msgbox "$err1" 
    else 
# 
#don't want to accidentally create in tmp folder. 
#"label" kdialog option didn't work 
# 
    kdialog --title "scanner info" --passivepopup "$err1" 5 
    cd ~/downloads/transfer 
    name=`kdialog --getsavefilename :newscan.pdf "*.pdf"` 
    cd ~/.getscan/tmp/ 
# convert * $name 
    convert * tmp/temp.pdf 
    gs -o $name -sDEVICE=pdfwrite -dPDFFitPage -r300x300 -g2550x3300 tmp/temp.pdf 
    rm * 
    rm tmp/* 
    okular $name 
fi 
    yn1=`kdialog --title "continue?" --radiolist "Select:" 1 "scan another document?" on 2 "stop" off 3 "change settings" off --geometry 150x100+300+300 ` 
if [ $yn1 = 2 ];then 
    yn1="y" 
fi 
if [ $yn1 = 3 ];then 
    cd ~/.getscan/ 
    . config 
    if [ $scnr = 2 ];then 
     scnr="ADF-Duplex" 
    fi 
    res1=`kdialog --title "scanner resolution" --radiolist "Select Resolution:" 1 "100" off 2 "200" off 3 "300" on 4 "400" off 5 "500" off 6 "600"` 
    if [ $res1 = 3 ];then 
     res1=300 
    fi 
    echo res=$res1 > config 
    clr1=`kdialog --title "color" --radiolist "Select Resolution:" 1 "black & white" on 2 "24bit color" off` 
    if [ $clr1 = 1 ];then 
     clr1=black 
    fi 
    if [ $clr1 = 2 ];then 
     clr1="'24bit color'" 
    fi 
    echo clr=$clr1 >> config 
    scnr1=`kdialog --title "mode" --radiolist "Select Resolution:" 1 "ADF" on 2 "ADF duplex" off` 
    if [ $scnr1 = 1 ];then 
     scnr1="1" 
    fi 
    if [ $scnr1 = 2 ];then 
     scnr1="2" 
    fi 
    echo scnr=$scnr1 >> config 
    . config 
    yn1=1 
    fi 
done 
exit 0 
+0

¡Gracias por publicar una respuesta! Si bien un fragmento de código podría responder a la pregunta, sigue siendo genial agregar información adicional, como explicar, etc. – j0k

1

Utilice el código siguiente para generar PDF de varias páginas a partir de varios archivos TIFF:

<?php 

$images = new Imagick($pathToYourFile); 

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

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

?> 
+1

La pregunta no requiere una solución PHP. – Dmitry

Cuestiones relacionadas