Created
July 28, 2014 13:50
-
-
Save joelbyler/d0453ffefbd85b58ef9a to your computer and use it in GitHub Desktop.
Simple html to pdf example using TuesPechkin
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using TuesPechkin; | |
namespace SimpleHtmlToPdfConsole | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// create a new document with your desired configuration | |
var document = new HtmlToPdfDocument | |
{ | |
GlobalSettings = | |
{ | |
ProduceOutline = true, | |
DocumentTitle = "Pretty Websites", | |
//PaperSize = PaperKind.A4, | |
Margins = | |
{ | |
All = 1.375, | |
Unit = Unit.Centimeters | |
} | |
}, | |
Objects = { | |
new ObjectSettings { HtmlText = "<h1>Pretty Websites</h1><p>This might take a bit to convert!</p>" }, | |
new ObjectSettings { PageUrl = "www.google.com" }, | |
new ObjectSettings { PageUrl = "www.microsoft.com" }, | |
new ObjectSettings { PageUrl = "www.github.com" } | |
} | |
}; | |
IPechkin converter = Factory.Create(); | |
// subscribe to events | |
/* converter.Begin += OnBegin; | |
converter.Error += OnError; | |
converter.Warning += OnWarning; | |
converter.PhaseChanged += OnPhase; | |
converter.ProgressChanged += OnProgress; | |
converter.Finished += OnFinished;*/ | |
// convert document | |
byte[] result = converter.Convert(document); | |
ByteArrayToFile(result, "C:/temp/exmple.pdf"); | |
} | |
public static bool ByteArrayToFile(byte[] _ByteArray, string _FileName) | |
{ | |
try | |
{ | |
System.IO.FileStream _FileStream = new System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write); | |
_FileStream.Write(_ByteArray, 0, _ByteArray.Length); | |
_FileStream.Close(); | |
return true; | |
} | |
catch (Exception _Exception) | |
{ | |
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString()); | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not recognize that :
" IPechkin converter = Factory.Create(); " What is it ?