- Build the WSP file
- Deploy the WSP
Open in browser: http://sharepoint.url/sites/site/_layouts/15/nova.sp.pdf.helper/GeneratePdf.ashx?url=http%3A%2F%2Fgoogle.com%2F%3Fq%3Dnova
- the request type must be "GET"
- the url query string parameter is mandatory
- the url value should be encoded using JavaScript encodeURIComponent or .net Uri.EscapeDataString
The PhantomJs is used to render the URL from the query string. The executable is included in the project in the manifest and is installed into web application (IIS) bin folder. The standard PhantomJs rasterize.js script is used to render the page. The script and config file for PhantomJs are included in project as embedded resources.
The executable is called with "elevated privileges", so App Pool of the Web Application is used to run Phantom and for authentication to destination site.
The page is implemented as HTTP handler. It returns the rendered PDF or error info as HTML.
The project was created for SP2013 using VS2015, but it can be "downgraded" to SharePoint 2010. Some code changes are required, as it uses few of new .net 4.0 features, i.e.: template strings.