0

Notepad.exe で開く必要があるテキスト ファイルがあり、ユーザーに入力を追加してもらいます。次に、ユーザーがファイルを終了したときにファイルを Adob​​ePDF に印刷したいと思います。

ここに私がファイルを開く必要があるものがあります

Start-Process notepad.exe C:\path\to\text\file\MyTextFile.txt -NoNewWindow -Wait

終了時に PDF を印刷する方法がわかりません。AdobePDF はインストール済みのプリンターですが、デフォルトのプリンターではありません。ヘルプやヒントをいただければ幸いです。

4

1 に答える 1

0

このようなものを試すことができます。

$TxtFilePath = "C:\folder\txtfile.txt"
Start-Process notepad.exe $TxtFilePath -NoNewWindow -Wait #Assuming user save the file
Get-Content -Path $TxtFilePath| Out-Printer PDFCreator #PDFCreator is the printer name for PDF 

- 編集 -

ファイル名を保持するための直接的な方法を見つけることができませんでした.ms wordでハックを書いたようなものです.

Function Save-TxtAsPDF
{
    Param([string] $FilePath, [string] $OutFolder)

    # Required Word Variables
    $ExportASPDFConstant = 17
    $DoNotSaveConstant = 0

    # Create a hidden Word window
    $word = New-Object -ComObject word.application
    $word.visible = $false

    # Add a Word document
    $doc = $word.documents.add()

    # Put the text into the Word document
    $txt = Get-Content $FilePath
    $selection = $word.selection
    $selection.typeText($txt)

    # Set the page orientation to landscape
    $doc.PageSetup.Orientation = 1

    $FileName = (Split-Path -Path $FilePath -Leaf).Replace(".txt",".pdf")  


    $DestinationPath = Join-Path $OutFolder $FileName

    # Export the PDF file and close without saving a Word document
    $doc.ExportAsFixedFormat($DestinationPath,$ExportASPDFConstant)
    $doc.close([ref]$DoNotSaveConstant)
    $word.Quit()
}


$TxtFilePath = "C:\folder\tt.txt"
$OutFolder = "C:\Outputfolder"

Start-Process notepad.exe $TxtFilePath -NoNewWindow -Wait #Assuming user save the file

Save-TxtAsPDF -FilePath $TxtFilePath -OutFolder $OutFolder

それが役立つかどうかを確認してください!

于 2017-01-09T13:38:45.860 に答える