将文件批量打印为PDF的新文件夹

时间:2019-04-23 21:04:52

标签: powershell pdf printing

我有一个2000多个PDF文件的文件夹,我需要使用原始文件名将它们打印并另存为新的PDF文件,并保存在单独的文件夹中。有没有办法在Powershell或使用CMD中执行此操作?

我尝试通过右键单击并选择打印选项来选择文件夹中的多个文件以同时打印。但这卡在了窗口中,要求提供一个新的文件名和一个我无法提供的目标文件夹,因为每个文件都必须具有原始文件名。

 // the directory to store the output.
 string directory = Environment.GetFolderPath  
 (Environment.SpecialFolder.MyDocuments);

 // initialize PrintDocument object
 PrintDocument doc = new PrintDocument() {
     PrinterSettings = new PrinterSettings() {
         // set the printer to 'Microsoft Print to PDF'
         PrinterName = "Microsoft Print to PDF",

         // tell the object this document will print to file
         PrintToFile = true,

         // set the filename to whatever you like (full path)
         PrintFileName = Path.Combine(directory, file + ".pdf"),
     }
    };

 doc.Print();

我希望将新的PDF文件另存为目标目录文件夹中的新PDF文件,其文件名与原始目录相同。

Origin Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\NonRedacted  --> Origin File name "Random_Name.PDF"


Destination Directory and File name:
C:\Users\ts\P***S***\Legal\i3**\Redacted --> Destination File Name "Random_Name.PDF"

0 个答案:

没有答案
相关问题