ImageMagick 或 GhostScript:将多页 TIFF 转换为多页 PDF

发布于 2024-10-12 15:21:12 字数 208 浏览 11 评论 0原文

我需要将多页 TIFF 转换为多页 PDF。我可以访问 ImageMagick 和 GhostScript(在 *nix 环境中)。我该怎么做?谢谢。

更新:

事实证明我的测试文件是错误的(它没有多个页面),这让我认为我的命令是错误的。这似乎对我有用:convert input.tif output.pdf

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

等风也等你 2024-10-19 15:21:12
convert multipage.tiff -density 300x300 -compress jpeg multipage.pdf

这应该可行,尽管可能存在一些问题。

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

This should work, though there can be some issues.

染柒℉ 2024-10-19 15:21:12

使用 libtiff 提供的工具集中名为 tiff2ps 的工具:

http://www.libtiff.org/tools。 一旦你有了ps

格式的 tiff,你就可以调用 ps2pdf 来转换为 pdf,它是大多数 Linux 发行版中 Ghostscript 包的一部分。

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.

凶凌 2024-10-19 15:21:12

使用以下代码从多页 tiff 文件生成多页 pdf:

<?php

$images = new Imagick($pathToYourFile);

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

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

?>

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);

?>
咋地 2024-10-19 15:21:12
#!/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
#!/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
一刻暧昧 2024-10-19 15:21:12

我在转换多页 TIFF 文件时也遇到过类似的情况。但就我而言,生成的扩展名是 JPG 缩略图。但是,我相信以下代码将运行以将 TIFF 转换为 PDF。 https://web.archive.org/web/20170211082909/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();
}
?>

I had a similar situation of converting a multipage TIFF file. but in my case the resulting extension was JPG thumbnail. However, I believe that this following code will run for converting TIFF to PDF. https://web.archive.org/web/20170211082909/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();
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文