
JoliPrint.com has an API for converting URLs to PDFs. It works great for websites, but we can use it very easily in VBA as well.
The API uses a URL shortener to return the PDF location, and requires urlencoding. I use the URLEncode function found at Free VB Code.
First we'll declare the base URL to be used for all API requests:
Public Const BASE_URL As String = "http://api.joliprint.com/api/rest/url/text?"
The function itself is very short. All we do is pass the urlencoded URL to the API. The response is the shortened URL.
Function GetPDFURL(url As String) As String
Dim xml As Object ' MSXML2.XMLHTTP
Dim result As String
Set xml = GetMSXML
With xml
.Open "GET", BASE_URL & "url=" & URLEncode(url), False
.send
End With
result = xml.responseText
GetPDFURL = result
End Function
The GetMSXML function may be found on the MSXML Object Library page.
Sample Usage
Sub CreatePDF()
Dim printUrl As String
printUrl = GetPDFURL("http://joliprint.com/api/")
End Sub