tiff2pdf 彩色

tiff2pdf 彩色

我将一些扫描.tif文件转换为.pdf使用tiff2pdf(libtiff 版本 4.0.3 )和 JPEG 压缩。查看它们evince会显示彩色(粉红色)背景。

我最初的想法是我的扫描仪坏了,但是文件.tif正常,.pdf如果我不使用 JPEG 压缩,文件也正常(但文件会变得非常大)。

如何 .pdf使用命令行工具获得未着色的压缩 JPEG?

答案1

这是一个似乎一直存在的问题2007年左右报道并重新出现(或者我使用了很长一段时间的旧版本的库,没有这个问题)。

您可以做的就是对输出文件进行后处理(假设您sed-i选项):

 tiff2pdf -j input.tif -o out.pdf
 sed -i 's|/DecodeParms << /ColorTransform 0 >>||' out.pdf

-o由于某种原因,如果您省略选项tiff2pdf并将输出直接通过管道传输到sed(如果您这样做,则不会收到tiff2pdf -j input.tif > out.pdf),您会收到错误消息和损坏的 PDF 文件


如果您愿意修补 tiff 4.0.4beta 源代码,您可以注释掉其中的第 5160–5163 行tools/tiff2pdf.c(其中写了这些ColorTransform内容):

    /*
    if(t2p->tiff_photometric != PHOTOMETRIC_YCBCR) {
        written += t2pWriteFile(output, (tdata_t) "/DecodeParms ", 13);
        written += t2pWriteFile(output, (tdata_t) "<< /ColorTransform 0 >>\n", 24);
     }
     */

或将t2pseekproc函数更改为:

static uint64
t2p_seekproc(thandle_t handle, uint64 offset, int whence)
{
    T2P *t2p = (T2P*) handle;
    int res;
    if (t2p->outputdisable <= 0 && t2p->outputfile) {
        res = fseek(t2p->outputfile, (long) offset, whence);
        if (res == -1 && offset == 0 && whence == SEEK_END)
            return 0;
        return res;
    }
    return offset;
}

fseek这样,如果您从末尾以偏移量 0执行 an 操作,它就不再失败(IMO 仅fseek当前面有一个具有非零值的不同的 且失败时才有意义)。

通过这两个更改,所有测试仍然通过(但它们显然没有涵盖所有功能)。通过第二个更改,您可以执行以下操作:

 tiff2pdf -j | input.tif | sed -i 's|/DecodeParms << /ColorTransform 0 >>||' out.pdf

IMO 不太可能破坏其他tiff2pdf未经过源代码中的测试套件测试的东西。

相关内容