首页 > 系统相关 >PowerShell-将word另存为pdf

PowerShell-将word另存为pdf

时间:2023-05-18 15:11:06浏览次数:40  
标签:Exception word 另存为 wordObject Write file pdf PowerShell

$folderPath = "D:\工作\temp\2023年4月19日"
$folderPathOut = "D:\工作\temp\2023年4月19日"
$wordFiles = Get-ChildItem -Path $folderPath -Filter "*.docx"
try{
    Get-Process -Name "*word*" |Stop-Process         #避免之前运行失败的word程序影响
    $wordObject = new-object -ComObject "Word.Application"
}
catch {
    Write-Host "Exception Caught: " $_.Exception -ForegroundColor Red
    exit
}
foreach ($file in $wordFiles){
    $pdfPath = Join-Path -Path $folderPathOut -ChildPath ($file.BaseName + ".pdf")
    try{
        $document = $wordObject.Documents.Open($file.FullName)
    }
    catch {
        Write-Host "打开word文件: " $_.Exception -ForegroundColor Red
        continue
    }
    try{
        $document.SaveAs($pdfPath, 17)
    }
    catch {
        Write-Host "另存为: " $_.Exception -ForegroundColor Red
    }
    finally{
        $document.Close()
    }
}
$wordObject.Quit()
Remove-Variable wordObject

 

标签:Exception,word,另存为,wordObject,Write,file,pdf,PowerShell
From: https://www.cnblogs.com/love-DanDan/p/17412021.html

相关文章

  • Navicat连接本地mysql报错-caching_sha2_password
     查询用户加密方式:selectuser,pluginfromuserwhereuser='root';修改用户加密方式改为mysql_native_password。alteruser'root'@'localhost'identifiedwithmysql_native_passwordby'123123';执行命令flushprivileges使权限配置项立即生效flushp......
  • 打印word材料的心酸日记
    为什么写打印word踩坑呢,挺离谱的【......
  • 支持复制粘贴word图片的百度编辑器
    ​ 当前功能基于PHP,其它语言流程大致相同 1.新增上传wordjson配置在ueditor\php\config.json中新增如下配置:     /* 上传word配置 */    "wordActionName":"wordupload",/* 执行上传视频的action名称 */    "wordFieldName":"upfile",/* 提交的......
  • 支持复制粘贴word图片的百度Web编辑器
    ​ 百度ueditor新增的将word内容导入到富文本编辑框的功能怎么没有啊,...ueditor实现word文档的导入和下载功能的方法:1、UEditor没有提供word的导入功能,只能说是粘贴复制。2、方案:用poi来提供word导入,思路是将word转换为html输出,再用UEditor提供的setContent()方法将html的内容......
  • 支持复制粘贴word图片的百度HTML编辑器
    ​图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码目前限chrome浏览器使用首先以um-editor的二进制流保存为例:打开umeditor.js,找到UM.plugins['autoupload'],然后找到autoUploadHandler方法,注释掉其中的代码。加入下面的代码://判断剪贴......
  • 支持复制粘贴word图片的CKEditor编辑器
    ​ 这种方法是servlet,编写好在web.xml里配置servlet-class和servlet-mapping即可使用后台(服务端)java服务代码:(上传至ROOT/lqxcPics文件夹下)<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@     page contentType="text/html;cha......
  • PowerShell里cd文件夹报错,是因为文件名称中包含空格
    PowerShell里cd文件夹报错,是因为文件名称中包含空格。需要将文件包在引号中。 cd"C:\ProgramFiles"  ......
  • PageOffice在线打开 word 文件,并且禁止复制
    在线打开word禁用拷贝的三种方式:1使用AllowCopy属性,效果:所有的word进程都不能进行拷贝操作2禁止word选择功能,效果:因为无法选择,所以无法拷贝3使用DisableCopyOnly属性,效果:禁止拷贝文档内容到外部,但内部是可以拷贝的,也可以从外部拷贝到word文档内部具体实现过......
  • 支持复制粘贴word图片的wangEditor编辑器
    ​如何做到ueditor批量上传word图片?1、前端引用代码<!DOCTYPE html PUBLIC "-//W3C//DTDXHTML1.0Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>......
  • python:ERROR: Could not build wheels for wordcloud, which is required to install
    pycharm里无法下载,在下面下载出现问题 需要下载error里的文件https://www.lfd.uci.edu/~gohlke/pythonlibs/#wordcloud这个网站找。输入Python,看自己电脑是怎样的 下载文件后,放到对应位置,下载成功 ......