批量把 word 转换成图片格式 pdf - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zdl0929
5.32D
0.12D
V2EX    问与答

批量把 word 转换成图片格式 pdf

  •  
  •   zdl0929 2024 年 8 月 14 日 2202 次点击
    这是一个创建于 554 天前的主题,其中的信息可能已经有所发展或是发生改变。
    有类似软件可以达到这个目的吗?

    在线网站也可以,我找到一个 maipdf 可以将文字版的 pdf 转换为图片版的 pdf ( turn PDF into images PDF ,https://maipdf.com/est/maiconvert.html ),但只能单个单个来,我这 word 批量转成 pdf ,再到这网站上也不好操作。

    有没有一步到位的,可以直接批量 word 转换为图片格式的 pdf (也就是每页都是图片)。
    没有一步到位的,有标准 pdf 转图标格式 pdf 的也可以。

    或者考虑直接写一个类似程序?有什么思路吗
    9 条回复    2024-08-14 15:46:42 +08:00
    Apol1oBelvedere
        1
    Apol1oBelvedere  
       2024 年 8 月 14 日
    试了一下 GPT 很容易写出这样的程序,对于把各个开源文件转换模块用胶水粘合成一段代码的需求,GPT 能实现。
    jpyl0423
        2
    jpyl0423  
       2024 年 8 月 14 日
    原来用 vbs 转过,网上搜的脚本,随便搜就能搜到
    zhidazhai
        3
    zhidazhai  
       2024 年 8 月 14 日
    是我没明白内容吗? WORD 可以直接转成 PDF ,PDF 可以导出或另存为 JPG ,都是批量自动化操作
    xHliu
        4
    xHliu  
       2024 年 8 月 14 日 via Android
    word to pdf ,pdf to jpg ,jpg to pdf

    要是急着用,就多转换一圈,
    pililink
        5
    pililink  
       2024 年 8 月 14 日
    可以去看看 wps 有没有这个功能
    wu529778790
        6
    wu529778790  
       2024 年 8 月 14 日
    https://github.com/Stirling-Tools/Stirling-PDF
    这个开源的,有你要的这个功能
    zdl0929
        7
    zdl0929  
    OP
       2024 年 8 月 14 日
    @Apol1oBelvedere #1 雀氏,在 gpt 帮助下,很快完成了
    kinkin666
        8
    kinkin666  
       2024 年 8 月 14 日
    com.luhuiguo:aspose-words:23.1
    这个用来把 word 转 pdf

    org.apache.pdfbox:pdfbox-app:2.0.13
    这个用来把 pdf 转图片
    zdl0929
        9
    zdl0929  
    OP
       2024 年 8 月 14 日
    找了半天没合适的,然后 gpt 半小时搞定
    ------
    # 读取文件夹中的所有 word 文件,把每一个转换为图像文件,再将图像文件合并到一个同名的 pdf 文件中
    import os
    from docx2pdf import convert
    from pdf2image import convert_from_path
    import img2pdf
    import shutil

    def word_to_pdf(word_file, pdf_file):
    convert(word_file, pdf_file)

    def pdf_to_images(pdf_file, image_prefix):
    images = convert_from_path(pdf_file)
    # 如果 image_prefix 文件夹不存在创建文件夹
    os.makedirs(os.path.join("imagetmp", image_prefix), exist_ok=True)
    image_paths = []
    for i, image in enumerate(images):
    image_path = os.path.join("imagetmp/"+ image_prefix, f'page_{i + 1}.png')
    image.save(image_path, 'PNG')
    image_paths.append(image_path)
    return image_paths
    def images_to_pdf(images, pdf_file):
    with open(pdf_file, "wb") as f:
    f.write(img2pdf.convert([i for i in images if i.endswith(".png")]))

    def convert_word_files_to_pdf(source_directory, target_directory):
    for root, dirs, files in os.walk(source_directory):
    for file in files:
    if file.endswith(".docx"):
    source_file = os.path.join(root, file)
    pdf_file = os.path.join(root, file.replace(".docx", ".pdf"))
    image_pdf_file = os.path.join(root, file.replace(".docx", ".pdf"))
    word_to_pdf(source_file, pdf_file)
    images = pdf_to_images(pdf_file, file.replace(".docx", ""))
    images_to_pdf(images, image_pdf_file)
    # os.remove(pdf_file)
    target_dir = root.replace(source_directory, target_directory)
    os.makedirs(target_dir, exist_ok=True)
    shutil.move(image_pdf_file, target_dir)

    convert_word_files_to_pdf(source_dir, dist_dir)
    div style="box-sizing: border-box">
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1887 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 03:44 PVG 11:44 LAX 19:44 JFK 22:44
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86