解密许多pdf在一个去使用pdftk



我有10个pdf文件需要用户密码才能打开。我知道那个密码。我想以解密的形式保存它们。它们的文件名如下所示:static_part.dynamic_part_like_date.pdf

我想转换所有的10个文件。我可以在静态部分之后给出一个*,并对所有这些部分进行处理,但我还需要相应的输出文件名。因此,必须有一种方法来捕获文件名的动态部分,然后在输出文件名中使用它。

对一个文件执行此操作的正常方法是:

pdftk secure .pdf input_pw foopass output unsecured.pdf

我想这样做:

pdftk var=secured*.pdf input_pw foopass输出unsecured+var.pdf

谢谢。

你的请求有点模棱两可,但这里有一些想法可能会对你有所帮助。

假设你的10个文件中有1个是

  # static_part.dynamic_part_like_date.pdf
  # SalesReport.20110416.pdf  (YYYYMMDD)

如果您只希望将SalesReport.pdf转换为不安全的,您可以使用shell脚本来实现您的要求:

# make a file with the following contents, 
# then make it executable with `chmod 755 pdfFixer.sh`
# the .../bin/bash has to be the first line the file.
$ cat pdfFixer.sh
#!/bin/bash
# call the script like $ pdfFixer.sh staticPart.*.pdf  
# ( not '$' char in your command, that is the cmd-line prompt in this example,
#   yours may look different )
# use a variable to hold the password you want to use
pw=foopass
for file in ${@} ; do
    # %%.* strips off everything after the first '.' char
    unsecuredName=${file%%.*}.pdf
    #your example : pdftk secured.pdf input_pw foopass output unsecured.pdf
    #converts to
    pdftk ${file} input_pw ${foopass} output ${unsecuredName}.pdf
done

您可能会发现需要将%.*修改为

  • 从end开始少取,(使用%.*)只取最后一个'。'和后面的所有字符(从右边开始)。
  • 从from(使用#*.)剥离到静态部分,留下动态部分OR
  • 从前面剥离(使用##*.),直到最后一个'。"char。

在命令行中找出你需要的东西真的会容易得多。设置一个变量,包含1个示例fileName

myTestFileName=staticPart.dynamicPart.pdf

,然后使用echo结合变量修饰符来查看结果。

echo ${myTestFileName##*.}
echo ${myTestFileName#*.}
echo ${myTestFileName##.*}
echo ${myTestFileName#.*}
echo ${myTestFileName%%.*}

等。

还请注意我如何将修改后的变量值与普通字符串(.pdf)组合在一起,在unsecuredName=${file%%.*}.pdf

IHTH

最新更新