static async Task Main(string[] args) { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. using (var converter = await HtmlConverter.CreateAsync()) { var html = "<html><head><style>body { background-color: coral; margin-top: 100px;}</style></head>" + "<body><h1>Did you notice the margins and the scale?</h1></body></html>"; var options = new HtmlConversionOptions(); options.Page.MarginLeft = 10; options.Page.MarginTop = 20; options.Page.MarginRight = 30; options.Page.MarginBottom = 40; options.Page.Scale = 1.5; using (var pdf = await converter.CreatePdfFromStringAsync(html, options)) pdf.Save("ConvertWithMarginsAndScale.pdf"); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public static void Convert() { HtmlConversionOptions options = new HtmlConversionOptions(false); HtmlConverter htmlConverter = new HtmlConverter(new Uri(@"https://en.wikipedia.org"), options); htmlConverter.Convert("converter-output.pdf"); }
static async Task Main(string[] args) { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. // It is possible to use the same converter for multiple conversions. // When reusing the converter you save on converter instantiation time. using (var converter = await HtmlConverter.CreateAsync()) { // Convert some HTML code in a string var html = "<body><br/><br/><br/><h1>Hello, World<h1></body>"; using (var pdf = await converter.CreatePdfFromStringAsync(html)) pdf.Save("ConvertLocalHtmlString.pdf"); // Convert a local HTML file using (var pdf = await converter.CreatePdfAsync(@"..\Sample Data\sample.html")) pdf.Save("ConvertLocalHtmlFile.pdf"); // Convert some HTML specifying a base URL var incompleteHtml = "<img src=\"/images/team.svg\"></img>"; var options = new HtmlConversionOptions(); options.Load.BaseUri = new Uri("https://bitmiracle.com/"); using (var pdf = await converter.CreatePdfFromStringAsync(incompleteHtml, options)) pdf.Save("ConvertHtmlWithBaseUrl.pdf"); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public static void Convert(string URL) { HtmlConversionOptions options = new HtmlConversionOptions(false); HtmlConverter htmlConverter = new HtmlConverter(new Uri(URL), options); htmlConverter.Convert("converter-output.pdf"); }
public async Task <IActionResult> SaveDocument(int id) { HtmlConversionOptions options = new HtmlConversionOptions(false); options.Title = "Contrato " + id + " - LocalizaCS"; HtmlConverter htmlConverter = new HtmlConverter(new Uri("http://localhost:8680/TbLocacoes/Contrato/" + id), options); htmlConverter.Convert("C:/Users/talita.salles/source/repos/LocalizaCS/wwwroot/Contratos/Contrato_" + id + ".pdf"); return(Redirect("http://localhost:8680/Contratos/Contrato_2.pdf")); }
static async Task Main(string[] args) { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. var url = new Uri("https://plugins.yithemes.com/yith-infinite-scrolling"); using (var converter = await HtmlConverter.CreateAsync()) { // The page at the url loads additional contents when scroll position changes. // Let's run a script before the conversion. The script scrolls the page until // there is no more new content. This way all the page contents will be converted. var options = new HtmlConversionOptions(); var js = @" async function scrollDownUntilYouCantAnyMore() { await new Promise((resolve, reject) => { var totalHeight = 0; var distance = 100; var timer = setInterval(() => { var scrollHeight = document.body.scrollHeight; window.scrollBy(0, distance); totalHeight += distance; if(totalHeight >= scrollHeight){ clearInterval(timer); resolve(); } }, 400); }); } scrollDownUntilYouCantAnyMore(); "; options.Start.SetStartAfterScriptRun(js); using (var pdf = await converter.CreatePdfAsync(url, options)) pdf.Save("ConvertAfterScriptRun.pdf"); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
static async Task Main(string[] args) { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. // Wait for 10 seconds before starting the conversion. // This should be enough for the test to complete. var options = new HtmlConversionOptions(); options.Start.SetStartAfterDelay(10 * 1000); using (var converter = await HtmlConverter.CreateAsync()) { using (var pdf = await converter.CreatePdfAsync(new Uri("https://html5test.com/"), options)) pdf.Save("ConvertWithDelay.pdf"); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
static async Task Main(string[] args) { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. using (var converter = await HtmlConverter.CreateAsync()) { // It is important to specify page size and turn on transparent background. // Usually, the size should be equal to the size of the page you want to overlay. var options = new HtmlConversionOptions(); options.Page.TransparentBackground = true; options.Page.SetSizeInches(4.13, 5.83); string htmlCode = "<div style=\"position: absolute; top: 270px; right: 100px;\">" + "I would like to put this here</div>"; using (var htmlPdf = await converter.CreatePdfFromStringAsync(htmlCode, options)) { var pdfPath = @"..\Sample Data\simple-graphics.pdf"; using (var pdf = new PdfDocument(pdfPath)) { // Create an XObject from a page in the document generated from HTML. // Please note that the code uses different document instances to call the // method and access the collection of the pages. var xObj = pdf.CreateXObject(htmlPdf.Pages[0]); // Draw the XObject on a page from the existing PDF. pdf.Pages[0].Canvas.DrawXObject(xObj, 0, 0); pdf.Save("PutHtmlOverPdf.pdf"); } } } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
static async Task Main(string[] args) { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. using (var converter = await HtmlConverter.CreateAsync()) { var url = new Uri("http://httpbin.org/basic-auth/foo/bar"); var options = new HtmlConversionOptions(); options.Authentication.SetCredentials("foo", "bar"); // The following two lines are here just to make the output easier to read. options.Page.MarginTop = 100; options.Page.Scale = 2; using (var pdf = await converter.CreatePdfAsync(url, options)) pdf.Save("ConvertPasswordProtected.pdf"); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
static async Task Main(string[] args) { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. using (var converter = await HtmlConverter.CreateAsync()) { var options = new HtmlConversionOptions(); options.Page.HeaderTemplate = File.ReadAllText(@"..\Sample Data\header-template.html"); options.Page.MarginTop = 110; options.Page.FooterTemplate = File.ReadAllText(@"..\Sample Data\footer-template.html"); options.Page.MarginBottom = 50; var url = new Uri("https://www.iana.org/glossary"); using (var pdf = await converter.CreatePdfAsync(url, options)) pdf.Save("ConvertWithHeaderAndFooter.pdf"); } Console.WriteLine($"The output is located in {Environment.CurrentDirectory}"); }
public PedamorfResponse ConvertUrl(string url, HtmlConversionOptions options) { return(GetResponse(x => x.ConvertUrl(url, options))); }