Skip to content

Instantly share code, notes, and snippets.

@manuelnelson
Created October 2, 2012 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelnelson/3820718 to your computer and use it in GitHub Desktop.
Save manuelnelson/3820718 to your computer and use it in GitHub Desktop.
Pechkin PDF Print form
public JsonResult PrintForm(string html)
{
try
{
var contentPath = Server.MapPath("~/Content/");
var css = System.IO.File.ReadAllText(Path.Combine(contentPath + "bootstrap.css"));
var fullHtml = string.Format(@"<!DOCTYPE html> <html> <head><style type='text/css'> {0} </style></head><body> {1} </body></html>",css, html);
var config = new ObjectConfig();
config.SetAllowLocalContent(true);
//config.SetUserStylesheetUri("bootstrap.css");
var pdfBuf = _synchronizedPechkin.Convert(config, fullHtml);
contentPath = Path.Combine(contentPath, "Pdfs/newPdf.pdf");
System.IO.File.WriteAllBytes(contentPath, pdfBuf);
return Json("success");
}
catch (Exception ex)
{
return Json("unable to make pdf");
}
}
@serenians
Copy link

do you know by any chance how to include images??
I have used both Url.Content and Server.MapPath, both doesnt work .. how do i reference path..?

@emiliepoccioli
Copy link

Hi, Di you manage to add your CSS? I have the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment