Created
June 26, 2017 13:38
-
-
Save anonymous/7e755c689b52099d94c61d65977475f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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