I am making use of a tool called GemBoxDocument which can be used to convert html files into a pdf file.
The sample code on their website shows how this can be done converting an actual file that exists on a server (source):
using System;
using System.Linq;
using System.Text;
using GemBox.Document;
using GemBox.Document.Tables;
class Sample
{
[STAThread]
static void Main(string[] args)
{
// If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
DocumentModel document = DocumentModel.Load("Reading.html");
document.Save("Convert.pdf");
}
}
However, in my case, i want to be able to convert a page that had been loaded in a browser and has potentially been edited.
So far i have thought of sending the HTML content through an ajax call as follows:
$.ajax({
url: 'convertToPDF',
type: 'POST',
data: {
html: $("#page").html()
},
success: function (data) {
}
});
"#page"
is a html wrapper for the whole entire page including loaded CSS scripts and images.
My initial thinking is that i will send the html code through to the server, create a temporary file and then pass that through as an argument to the .Load()
function.
However i dont think im doing this correctly. #page has externally referenced CSS and images that i dont think will be passed to the server. So my question is, how can i get ALL the content of a loaded page into a single variable in javascript and send it to the sever?