public void ConvertUrlToPdfWithSuccess() { byte[] resultBuffer = null; string url = "http://writelinez.com"; UriSourceConverterSettings settings = new UriSourceConverterSettings(); settings.GlobalSettings = new PdfConverterGlobalSettings(); settings.GlobalSettings.Copies = 1; settings.GlobalSettings.DocumentTitle = "YaYa!!!"; settings.GlobalSettings.Orientation = Orientation.Portrait; settings.WebSettings = new PdfWebSettings(); settings.WebSettings.LoadImages = true; settings.WebSettings.Background = true; DotNetCorePdf pdf = DotNetCorePdf.Create(); using (UriSourcePdfConverter converter = pdf.CreateUriSourcePdfConverter()) { resultBuffer = converter.Convert(settings, url); } using (FileStream fs = new FileStream(@"c:\temp\writelinez.pdf", FileMode.Create)) { fs.Write(resultBuffer, 0, resultBuffer.Length); } }
public void ConvertFilePathToPdfWithSuccess() { byte[] resultBuffer = null; string path = @"c:\temp\testFile.html"; if (!File.Exists(path)) { string html = "<html><head><title>Test Page</title></head><body><b>I am the one and only PDF.</b><p>You know you like it!!!</p></body></html>"; byte[] htmlBytes = Encoding.UTF8.GetBytes(html); using (FileStream fs = new FileStream(path, FileMode.Create)) { fs.Write(htmlBytes, 0, htmlBytes.Length); } } UriSourceConverterSettings settings = new UriSourceConverterSettings(); settings.GlobalSettings = new PdfConverterGlobalSettings(); settings.GlobalSettings.Copies = 1; settings.GlobalSettings.DocumentTitle = "YaYa!!!"; settings.GlobalSettings.Orientation = Orientation.Portrait; settings.WebSettings = new PdfWebSettings(); settings.WebSettings.LoadImages = true; settings.WebSettings.Background = true; DotNetCorePdf pdf = DotNetCorePdf.Create(); using (UriSourcePdfConverter converter = pdf.CreateUriSourcePdfConverter()) { resultBuffer = converter.Convert(settings, path); } using (FileStream fs = new FileStream(@"c:\temp\testFile.pdf", FileMode.Create)) { fs.Write(resultBuffer, 0, resultBuffer.Length); } }