PhantomJS wrapper for .NET (C#) Run javascript from .NET code
features
- Execute javascript, load & render HTML pages with PhantomJS tool (headless browser) from .NET application. Useful for executing javascript code on server-side in real web context.
-
Wrapper provides .NET API for:
- running PhantomJS process (from a file or just javascript code string)
- setting input data through stdin with .NET Stream
- reading result (text or binary) from stdout into .NET Stream
- events for handling console log and js errors
- Easy to use: just install NReco.PhantomJS nuget package
-
Usage examples (C#):
- ReadConsoleLog:
- how to pass arguments from C# code (and get them in javascript code)
- how to read console.log in C# code (produced by javascript code)
- StdinStdout:
- how to provide input from C# Stream into javascript code
- how to read stdout into C# Stream from javascript code
- execute rasterize.js from C# code
-
SvgBatch (commercial package only):
- how to convert several SVG (or HTML) files to image (PNG,JPG,PDF) with one PhantomJS call
- how to convert a lot of SVG files with several PhantomJS processes with 100% CPU utilization
-
RenderPdf (commercial package only):
- implements sample HTML-to-PDF converter that uses PhantomJS for rendering web page to PDF file
- supports various PDF generation options: page size, orientation, margin, header/footer with page numbering
- ReadConsoleLog:
- Looking for specialized HTML to PDF converter? Try NReco.PdfGenerator
download and pricing
PhantomJS .NET Wrapper FREE pack
Wrapper DLL, ReadConsoleLog and StdinStdout Examples, NO support, .NET 4.x only |
Download for Free |
PhantomJS .NET Wrapper enterprise source code pack
Includes: component source code + commercial license for multiple deployments/SaaS usage, a license key, a 1-year of email support. |
$99 - Order Now |
quick purchase process
- 1 Choose a package
- 2 Pay online
- 3 Download the package
PhantomJS can be used for web scraping, rendering web page with SVG/Canvas to image (get web page thumbnail) or PDF
and other server-side page automation.
Don't spend your time and money on PhantomJS integration: it's already done!
Don't spend your time and money on PhantomJS integration: it's already done!
how to use
- Install NReco.PhantomJS nuget package
- Execute javascript with one line of C# code:
var phantomJS = new PhantomJS(); phantomJS.OutputReceived += (sender, e) => { Console.WriteLine("PhantomJS output: {0}", e.Data); }; phantomJS.RunScript("for (var i=0; i<10; i++) console.log('hello from js '+i); phantom.exit();", null);
- That's all! Next steps:
- Explore online API documentation
- Download usage examples
online PhantomJS demo
var system = require('system'); var page = require('webpage').create(); page.open(system.args[1], function(status) { var divCount = page.evaluate(function() { return document.getElementsByTagName('DIV').length; }); console.log(divCount); phantom.exit(); });Execute Javascript on Server
frequently asked questions
NReco.PhantomJS wrapper can be used for FREE in single-deployment projects (websites, intranet/extranet) or applications for company's internal business purposes (redistributed only internally inside the company).
Commercial license is required for:
Commercial license is required for:
- Applications for external redistribution (ISV)
- SaaS deployments
- .NET Core build (requires commercial license key)
Component cannot be used (does not work) in the following cases:
NReco.PhantomJS nuget package has dependency on PhantomJS package that copies phantomjs.exe to project output directory (and PhantomJS wrapper uses it from that location by default). You you decided to use different location for phantomjs.exe you may specify it with ToolPath property.
Wrapper can be used from .NET Core applications: portable build that targets .NET Standards 1.5 is included into commercial package.
- partial-trust environments where starting new processes is prohibited (shared ASP.NET hostings)
- special Windows Server configurations with restricted access to GDI API. Azure Apps (former WebSites) are NOT supported!
- .NET platforms where System.Diagnostics.Process API is not available (UWP/Univeral Apps)
NReco.PhantomJS nuget package has dependency on PhantomJS package that copies phantomjs.exe to project output directory (and PhantomJS wrapper uses it from that location by default). You you decided to use different location for phantomjs.exe you may specify it with ToolPath property.
Wrapper can be used from .NET Core applications: portable build that targets .NET Standards 1.5 is included into commercial package.
PhantomJS can render web pages to PDF (including SVG and canvas! Most of js charts may be rendered correctly)
but result is highly depends on the HTML layout. There are number of known issues with page breaks and links; also
PDF can look a bit different in comparing to the browser view.
If you're looking for the component that can convert almost any existing web page to the nice-looking PDF
consider using NReco PdfGenerator: this is .NET wrapper for wkhtmltopdf tool
which provides much better PDF results.
RenderPdf example (included into commercial package) implements simple Html-to-PDF converter class that uses PhantomJS and supports the following PDF export options:
- page size, orientation and margins
- header/footer (defined with HTML templates) with page numbering
- extra options like zoom factor or javascript delay
what's new
2023 May 05 |
v.1.1.0 changes:
|
2017 Jun 02 |
v.1.0.4 changes:
|
2016 Feb 24 |
v.1.0.3 changes:
|
2015 Aug 03 |
v.1.0.2 changes:
|
2015 Apr 05 |
v.1.0.1 changes:
|
2015 Apr 3 | v.1.0: Initial NReco.PhantomJS release (uses PhantomJS 2.0) |
more components
-
HTML-to-PDF Generator
.NET wrapper for WkHtmlToPdf utility that generates PDF reports by HTML template.
-
Image Generator
.NET wrapper WkHtmlToImage utility that generate pretty-looking images by HTML layout.
-
PivotData Toolkit for .NET
.NET components for manipulating multidimensional dataset (in-memory data cube) without OLAP server, aggregating huge datasets, calculating data for pivot tables / charts, web pivot table control for ASP.NET MVC/Blazor.
-
VideoConverter
.NET wrapper for FFMpeg utility for converting media files (video, audio). Can be used for video thumbnail extraction, live media stream transcoding etc.