Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kinuasa/99214396ec8a55b63b44e107a24ddb2c to your computer and use it in GitHub Desktop.
Save kinuasa/99214396ec8a55b63b44e107a24ddb2c to your computer and use it in GitHub Desktop.
Microsoft Print to PDFプリンター経由でテキストファイルをPDFファイルに変換するPower Automate for desktopフロー(動作確認:バージョン 2.47 ) 関連Webサイト:https://rpacommunity.connpass.com/event/329227/
/# <セレクター例>
・印刷結果を名前を付けて保存ダイアログ(メモ帳)
:desktop > window > window[Class="#32770"] > window[Name*="名前を付けて保存"][Class="#32770"]
・名前を付けて保存ダイアログ(その他)
:desktop > window > window[Name*="名前を付けて保存"][Class="#32770"]
・ファイル名入力欄
> pane[Class="DUIViewWndClassName"] > combobox[Id="FileNameControlHost"] > edit[Class="Edit"]
・保存ボタン
> button[Class="Button"][AccessKey="Alt+s"]
> button[Class="Button"][Name="保存(S)"]#/
SET TargetFilePath TO $'''C:\\Test\\Text\\Test.txt'''
SET SaveFilePath TO $'''C:\\Test\\Text\\Microsoft Print to PDFで変換.pdf'''
/# ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
ファイルがすでに存在している場合の警告を抑えるため事前に削除
★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#/
IF (File.IfFile.Exists File: SaveFilePath) THEN
File.Delete Files: SaveFilePath
END
Workstation.GetDefaultPrinter PrinterName=> DefaultPrinterName
Workstation.SetDefaultPrinter PrinterName: $'''Microsoft Print to PDF'''
Workstation.PrintDocument DocumentPath: TargetFilePath
UIAutomation.PopulateTextField.PopulateTextField TextField: appmask['WinSavePrintOutputAs']['EdtFileName'] Text: SaveFilePath Mode: UIAutomation.PopulateTextMode.Replace ClickType: UIAutomation.PopulateMouseClickType.SingleClick
UIAutomation.PressButton Button: appmask['WinSavePrintOutputAs']['BtnSave'] Simulate: False
Workstation.SetDefaultPrinter PrinterName: DefaultPrinterName
# [ControlRepository][PowerAutomateDesktop]
{
"ControlRepositorySymbols": [
{
"IgnoreImagesOnSerialization": false,
"Repository": "{\r\n\"Screens\":[\r\n{\r\n\"Controls\":[\r\n{\r\n\"AutomationProtocol\":\"uia3\",\r\n\"ScreenShot\":null,\r\n\"ElementTypeName\":\"Edit\",\r\n\"InstanceId\":null,\r\n\"Name\":\"EdtFileName\",\r\n\"SelectorCount\":1,\r\n\"Selectors\":[\r\n{\r\n\"CustomSelector\":\">pane[Class=\\\"DUIViewWndClassName\\\"] > combobox[Id=\\\"FileNameControlHost\\\"] > edit[Class=\\\"Edit\\\"]\",\r\n\"Elements\":[],\r\n\"Ignore\":false,\r\n\"ImageSelector\":null,\r\n\"IsCustom\":true,\r\n\"IsImageBased\":false,\r\n\"IsWindowsInstance\":false,\r\n\"Name\":\"DefaultSelector\",\r\n\"Properties\":[]\r\n}\r\n],\r\n\"Tag\":\"edit\",\r\n\"ScreenshotPath\":null\r\n},\r\n{\r\n\"AutomationProtocol\":\"uia3\",\r\n\"ScreenShot\":null,\r\n\"ElementTypeName\":\"Button\",\r\n\"InstanceId\":null,\r\n\"Name\":\"BtnSave\",\r\n\"SelectorCount\":1,\r\n\"Selectors\":[\r\n{\r\n\"CustomSelector\":\">button[Class=\\\"Button\\\"][AccessKey=\\\"Alt+s\\\"]\",\r\n\"Elements\":[],\r\n\"Ignore\":false,\r\n\"ImageSelector\":null,\r\n\"IsCustom\":true,\r\n\"IsImageBased\":false,\r\n\"IsWindowsInstance\":false,\r\n\"Name\":\"DefaultSelector\",\r\n\"Properties\":[]\r\n}\r\n],\r\n\"Tag\":\"button\",\r\n\"ScreenshotPath\":null\r\n}\r\n],\r\n\"Handle\":{\r\n\"value\":0\r\n},\r\n\"ProcessName\":null,\r\n\"ScreenShot\":null,\r\n\"ElementTypeName\":\"Window\",\r\n\"InstanceId\":null,\r\n\"Name\":\"WinSavePrintOutputAs\",\r\n\"SelectorCount\":1,\r\n\"Selectors\":[\r\n{\r\n\"CustomSelector\":\":desktop > window > window[Class=\\\"#32770\\\"] > window[Name*=\\\"名前を付けて保存\\\"][Class=\\\"#32770\\\"]\",\r\n\"Elements\":[],\r\n\"Ignore\":false,\r\n\"ImageSelector\":null,\r\n\"IsCustom\":true,\r\n\"IsImageBased\":false,\r\n\"IsWindowsInstance\":false,\r\n\"Name\":\"DefaultSelector\",\r\n\"Properties\":[]\r\n}\r\n],\r\n\"Tag\":\"window\",\r\n\"ScreenshotPath\":null\r\n}\r\n],\r\n\"Version\":1\r\n}",
"ImportMetadata": {
"DisplayName": "Computer",
"ConnectionString": "",
"Type": "Local",
"DesktopType": "local"
},
"Name": "appmask"
}
],
"ImageRepositorySymbol": {
"Repository": "{\r\n \"Folders\": [],\r\n \"Images\": [],\r\n \"Version\": 1\r\n}",
"ImportMetadata": {},
"Name": "imgrepo"
},
"ConnectionReferences": []
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment