如何使用 PDFTK(或其他命令行应用程序)查找和替换现有 PDF 文件中的文本 [英] How to find and replace text in a existing PDF file with PDFTK (or other command line application)

查看:26
本文介绍了如何使用 PDFTK(或其他命令行应用程序)查找和替换现有 PDF 文件中的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 PDF 文档的每一页上都有一行包含此字符串:

I have on each page of my PDF document a line with this string:

%REPLACE%

我想查找并替换为另一个字符串.

Which I'd like to find and replace with another string.

有谁知道如何使用某些命令行应用程序(例如 PDFTK)执行此操作?

Does anyone know how to do this with some command line application such as PDFTK?

这个人们给了我是一个重要的线索,但我想要更直接的东西.

This folk gave me an important clue however I'd like something more direct.

谢谢.

推荐答案

您可以尝试如下修改您的PDF内容

You can try to modify content of your PDF as follows

  1. 解压PDF文本流

  1. Uncompress the text streams of PDF

pdftk file.pdf output uncompressed.pdf uncompress

  • 使用 sed 将您的文本替换为另一个

  • Use sed to replace your text with another

    sed -e "s/ORIGINALSTRING/NEWSTRING/g" <uncompressed.pdf >modified.pdf
    

  • 如果此尝试成功,请使用 pdftk

    pdftk modified.pdf output recompressed.pdf compress
    

  • 注意:这种方式不是每次都成功,主要是字体子集

    Note: This way is not successful every time, mainly due to font subsetting

    这篇关于如何使用 PDFTK(或其他命令行应用程序)查找和替换现有 PDF 文件中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆