2017-01-09 17 views
0

Notepad.exe에서 열어야하는 텍스트 파일이 있으며 사용자가 입력을 추가해야합니다. 그런 다음 사용자가 파일을 끝내면 AdobePDF로 파일을 인쇄하고 싶습니다. 여기 Powershell 텍스트 파일을 열어 종료시 출력하십시오.

내가 파일

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

출구에서 PDF를 인쇄하는 방법을 확실하지를 열 필요가 것입니다. AdobePDF는 설치된 프린터이지만 기본 프린터가 아닙니다. 어떤 도움이나 조언도 크게 감사 할 것입니다. 내가 파일 이름을 유지하기 위해 직접 접근 방법을 알아낼 수

$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 

--EDIT--

답변

0

당신이 뭔가를 시도 할 수는 종류의 MS와 해킹을 썼다 단어,

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 

도움이되는지 확인하십시오.

+0

위대한 작품. 그러나 PDF 파일을 저장할 때 원본 텍스트 파일 이름을 유지할 수있는 방법이 있는지 궁금합니다. – Eric

+0

대답을 업데이트했습니다. 직접 접근 할 수 없습니다! 도움이되는지 확인하십시오! –