第一次发帖 - 但我认为这是一个很好的帖子,因为我花了 2 天时间进行研究,与当地专家交谈,但仍然没有完成。
必须在大量文件(.txt 文件)上定期启动单个打印作业,并且必须通过打印作业将其转换为本地文件(即通过 PDF 打印机),该文件保留每个文件的原始基本名称。此外,脚本必须是高度可移植的。
如果文件只是被转换(而不是打印),原始基本文件名没有保留,或者打印过程需要在每次打印时手动交互,则无法实现目标。
经过我的研究,这是目前 PowerShell 中的内容:
问题:此脚本执行所有操作,但实际上打印文件的内容。它遍历文件,并在保留原始文件名基础的同时“打印”一个 .pdf;但 .pdf 是空的。
我知道我错过了一些关键的东西(即可能是流使用?);但经过搜索和搜索一直无法找到它。任何帮助是极大的赞赏。
正如代码中提到的,打印功能的核心是从这篇文章中收集的:
# The heart of this script (ConvertTo-PDF) is largley taken and slightly modified from https://social.technet.microsoft.com/Forums/ie/en-US/04ddfe8c-a07f-4d9b-afd6-04b147f59e28/automating-printing-to-pdf?forum=winserverpowershell
# The $OutputFolder variable can be disregarded at the moment. It is an added bonus, and a work in progress, but not cirital to the objective.
function ConvertTo-PDF {
param(
$TextDocumentPath, $OutputFolder
)
Write-Host "TextDocumentPath = $TextDocumentPath"
Write-Host "OutputFolder = $OutputFolder"
Add-Type -AssemblyName …Run Code Online (Sandbox Code Playgroud)