Skip to content

Instantly share code, notes, and snippets.

Created June 26, 2017 13:38
Show Gist options
  • Save anonymous/7e755c689b52099d94c61d65977475f3 to your computer and use it in GitHub Desktop.
Save anonymous/7e755c689b52099d94c61d65977475f3 to your computer and use it in GitHub Desktop.
public static void ConvertToPDF()
{
Byte[] bytes;
using (var ms = new MemoryStream())
{
using (var doc = new Document())
{
using (var writer = PdfWriter.GetInstance(doc, ms))
{
doc.Open();
var web = new HtmlWeb();
var html = web.Load(url).ToString();
// Convert
using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(doc))
{
using (var sr = new StringReader(html))
{
htmlWorker.Parse(sr);
}
}
doc.Close();
}
}
bytes = ms.ToArray();
}
var file = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TestOutput.pdf");
System.IO.File.WriteAllBytes(file, bytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment