使用 pdftk 一次性解密多个 PDF

发布于 2024-11-01 07:25:09 字数 393 浏览 5 评论 0原文

我有 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 output unsecured+var.pdf

谢谢。

I have 10 PDFs that ask for a user password to open. I know that password. I want to keep them in a decrypted format. Their filenames follow the form:
static_part.dynamic_part_like_date.pdf

I want to convert all the 10 files. I can give a * after the static part and work on all of them, but I also want the corresponding output filenames. So there has to be a way to capture the dynamic part of the filename and then use it in the output filename.

The normal way of doing this for one file is:

pdftk secured.pdf input_pw foopass output unsecured.pdf

I want to do something like:

pdftk var=secured*.pdf input_pw foopass output unsecured+var.pdf

Thanks.

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

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

发布评论

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

评论(1

余罪 2024-11-08 07:25:09

您的要求有点含糊,但这里有一些可能对您有帮助的想法。

假设您的 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 '

您可能会发现您需要修改 %.* 内容要从

  • 末尾删除更少的内容,(使用 %.*)仅删除最后一个 '.'以及之后的所有字符(从右侧剥离)。
  • 从前面剥离(使用#*。)仅保留静态部分,保留动态部分或
  • 从前面剥离(使用##*。)以剥离所有内容,直到最后一个“。”字符。

对于您来说,在命令行上弄清楚您需要什么确实会容易得多。
使用 1 个示例文件名设置一个变量

myTestFileName=staticPart.dynamicPart.pdf

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

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

等。

另请注意我如何将修改后的变量值与纯字符串 (.pdf) 结合起来,在 unsecuredName=${file%%.*}.pdf

IHTH

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

您可能会发现您需要修改 %.* 内容要从

  • 末尾删除更少的内容,(使用 %.*)仅删除最后一个 '.'以及之后的所有字符(从右侧剥离)。
  • 从前面剥离(使用#*。)仅保留静态部分,保留动态部分或
  • 从前面剥离(使用##*。)以剥离所有内容,直到最后一个“。”字符。

对于您来说,在命令行上弄清楚您需要什么确实会容易得多。
使用 1 个示例文件名设置一个变量

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

等。

另请注意我如何将修改后的变量值与纯字符串 (.pdf) 结合起来,在 unsecuredName=${file%%.*}.pdf

IHTH

Your request is a little ambiguous, but here are some ideas that might help you.

Assuming 1 of your 10 files is

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

And you want only the SalesReport.pdf converted as unsecured, you can use a shell script to achieve your requirement:

# 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 '

You may find that you need to modify the %.* thing to

  • strip less from end, (use %.*) to strip just the last '.' and all chars after (strip from right).
  • strip from the fron (use #*.) to just the static part, leaving the dynamic part OR
  • strip from the front (use ##*.) to strip everything until the last '.' char.

It will really be much easier for you to figure out what you need at the cmd-line.
Set a variable with 1 sample fileName

myTestFileName=staticPart.dynamicPart.pdf

and then use echo combined with the variable modifiers to see the results.

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

etc.

Also notice how I combine a modified variable value with a plain string (.pdf), in unsecuredName=${file%%.*}.pdf

IHTH

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

You may find that you need to modify the %.* thing to

  • strip less from end, (use %.*) to strip just the last '.' and all chars after (strip from right).
  • strip from the fron (use #*.) to just the static part, leaving the dynamic part OR
  • strip from the front (use ##*.) to strip everything until the last '.' char.

It will really be much easier for you to figure out what you need at the cmd-line.
Set a variable with 1 sample fileName

and then use echo combined with the variable modifiers to see the results.

etc.

Also notice how I combine a modified variable value with a plain string (.pdf), in unsecuredName=${file%%.*}.pdf

IHTH

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文