我怀疑我缺少一些简单的东西,但是我已经花了几个小时了,所以去吧。
我需要获取一个使用JSPDF在Intranet站点上动态生成的PDF,并将其保存到某个位置。该代码成功触发了动态HTML的构建,以创建PDF。
如何运行它并获取PDF而不是HTML?
VBA:
Sub DownloadMap(WO As String, Mch As String)
Dim myurl As String
myurl = "http://intranetsite/page?workOrderString=" & WO & "&mchString=" & Mch
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myurl, False
WinHttpReq.send
myurl = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set ostream = CreateObject("ADODB.Stream")
ostream.Open
ostream.Type = 1
ostream.Write WinHttpReq.responseBody
ostream.SaveToFile "C:\build\file.html", 2
ostream.Close
End If
End Sub
已精简生成的html版本,并将其保存到“ c:\ build \ file.html”。手动打开此HTML文件会立即生成正确的PDF下载。
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
</head>
<Body>
<script>
var pdf = new jsPDF('l');
//bunch of script to generate the PDF
pdf.save('625419' + ' - ' + 'T02' + '.pdf')
</script>
</body>
</html>
如何让VBA执行生成的HTML并获取pdf,而不是获取生成的HTML?