Created
June 26, 2017 13:10
-
-
Save anonymous/59f7055339f45c0522f306c3e367764f 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 response = new HttpClient().GetAsync(url); | |
string html = new WebClient().DownloadString(url); | |
// 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