-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathChromeSavePDF.ahk
45 lines (41 loc) · 1.07 KB
/
ChromeSavePDF.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
; Title:
; Link: https://www.autohotkey.com/boards/viewtopic.php?p=335405#p335405
; Author:
; Date:
; for: AHK_L
/*
*/
ChromeSavePDF(ProfileFolder,Link,FileName,Open:=False)
{
; huge thanks to GeekDude! (https://www.autohotkey.com/boards/memberlist.php?mode=viewprofile&u=161)
; https://github.com/G33kDude/Chrome.ahk
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=42890
; function by JoeW based on GeekDude's example: ExportPDF.ahk
RetCode:=0
ChromeInst:=new Chrome(ProfileFolder,Link,"--headless")
If !(PageInst:=ChromeInst.GetPage())
{
ChromeInst.Kill()
Return 1
}
Else
{
PageInst.WaitForLoad()
Base64PDF:=PageInst.Call("Page.printToPDF").data
Size:=Base64_Decode(BinaryPDF, Base64PDF)
FileOpen(FileName,"w").RawWrite(BinaryPDF,Size)
If (Open)
{
Try Run,%FileName%
Catch
RetCode:=2
}
Try PageInst.Call("Browser.close") ; Fails when running headless
Catch
ChromeInst.Kill()
PageInst.Disconnect()
}
Return RetCode
}
#Include Chrome.ahk
#Include Base64EncodeDecode.ahk