我正在尝试批量标记许多 pdf 文件,我在 github 上发现了一些非常相似的东西,但是您必须在脚本中命名每个文件以与实际的 pdf 文件匹配才能正常工作。
https://github.com/iprapas/pythonpdf
def stamp_pdf(input_path, stamp_path, output_path, add_frame=False):
output = PdfFileWriter()
create_pdf_stamp(stamp_path, add_frame=add_frame)
pdf_in = PdfFileReader(open(input_path, 'rb'))
pdf_stamp = PdfFileReader(open(stamp_path, 'rb'))
stamp = pdf_stamp.getPage(0)
for i in xrange(pdf_in.getNumPages()):
page = pdf_in.getPage(i)
page.mergePage(stamp)
output.addPage(page)
with open(output_path, 'wb') as f:
output.write(f)
def main():
stamp_pdf('../input/input1.pdf', '../temp/tmp_stamp.pdf', '../output/stamped1.pdf')
stamp_pdf('../input/input1.pdf', '../temp/tmp_stamp.pdf', '../output/stamped1_with_frame.pdf', add_frame=True)
stamp_pdf('../input/input2.pdf', '../temp/tmp_stamp.pdf', '../output/stamped2.pdf')
stamp_pdf('../input/input2.pdf', '../temp/tmp_stamp.pdf', '../output/stamped2_with_frame.pdf', add_frame=True)
if __name__ == "__main__":
main()
我确信有一种方法可以替换单个文件链接,以便它直接指向目录并保留文件名。任何让我开始的指针将不胜感激,因为我一直在尝试各种代码,但运气不佳。