protected void btnPDF_Click(object sender, EventArgs e) { string url = @"http://localhost/MobileDeviceManagement/Form.aspx?id=" + formId + "&hideBtn=true"; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); //int webPageWidth = 1024; //int webPageHeight = 0; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; //converter.Options.WebPageWidth = webPageWidth; //converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertUrl(url); // save pdf document doc.Save(Response, false, "Form " + formId + ".pdf"); // close pdf document doc.Close(); }
/// <summary> /// Gets the index of the sibling page of the current page. /// A sibling page is the page either before or after the current page. /// Usually it is the previous page (to help avoid spoilers). /// If both adjacent pages are of different orientations, there is no sibling page. /// If the current page is the first page, the sibling will be page 2 if it's the same orientation. /// If only one of the current page's siblings is of the same orientation, that page is the sibling. /// </summary> /// <param name="currentPage">The index of the page to get the sibling page index for.</param> /// <returns>The index of the sibling page, or null if there is no sibling.</returns> private PdfPage GetSiblingPage(PdfPage currentPage) { if (currentPage == null) { throw new ArgumentNullException("currentPage", "The currentPage parameter cannot be null."); } PdfPage previousPage = currentPage.Index > 0 ? pdf.GetPage(currentPage.Index - 1) : null; PdfPage nextPage = currentPage.Index < pdf.PageCount - 1 ? pdf.GetPage(currentPage.Index + 1) : null; if (previousPage == null && nextPage == null) { // One page document. return(null); } PdfPageOrientation currentPageOrientation = GetPageOrientation(currentPage); if (previousPage == null) { return((currentPageOrientation == GetPageOrientation(nextPage)) || GetPageOrientation(nextPage) == PdfPageOrientation.Square ? nextPage : null); } else if ((currentPageOrientation == GetPageOrientation(previousPage)) || GetPageOrientation(previousPage) == PdfPageOrientation.Square) { return(previousPage); } else { return((currentPageOrientation == GetPageOrientation(nextPage)) || GetPageOrientation(nextPage) == PdfPageOrientation.Square ? nextPage : null); } }
protected void btnMakePDF_Click(object sender, EventArgs e) { string url = txtMakePDF.Value; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), "Portrait", true); HtmlToPdf converter = new HtmlToPdf(); converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.MarginBottom = 10; converter.Options.MarginLeft = 10; converter.Options.MarginRight = 10; converter.Options.MarginTop = 10; try { PdfDocument doc = converter.ConvertUrl(url); // if you want to save to file doc.Save(Server.MapPath("/Documents/document3.pdf")); doc.Save(Response, true, "document3.pdf"); doc.Close(); } catch (Exception ex) { // show the error model if (ex.Message != "Thread was being aborted.") { myModal.Style.Add("display", "block"); } } }
public static async Task CreatePdfFrumUrl(string url, string fileName) { PdfPageSize pageSize = PdfPageSize.A4; PdfPageOrientation pdfOrientation = PdfPageOrientation.Portrait; int webPageWidth = 1024; int webPageHeight = 1000; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertUrl(url); // save pdf document doc.Save($@"C:\Temp\{fileName}.pdf"); // close pdf document doc.Close(); }
private byte[] CreatePdf(string result) { string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; int webPageHeight = 0; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; PdfDocument doc = converter.ConvertHtmlString(result); //Conversion failure. Could not find 'Select.Html.dep'. // save pdf document byte[] data = doc.Save(); return(data); }
public Byte[] ExportDrawing(string html) { Byte[] res = null; string htmlString = html; PdfPageSize pageSize = PdfPageSize.A4; PdfPageOrientation pdfOrientation = PdfPageOrientation.Landscape; HtmlToPdf converter = new HtmlToPdf(); converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; PdfDocument doc = converter.ConvertHtmlString(htmlString); using (MemoryStream ms = new MemoryStream()) { doc.Save(ms); res = ms.ToArray(); doc.Close(); } return(res); }
protected void Button_Descargar_Click(object sender, EventArgs e) { UsuarioCompleto UsuarioCompleto = (UsuarioCompleto)Session["UsuarioCompleto"]; DateTime hoy = DateTime.Now; string host = HttpContext.Current.Request.Url.Host; int port = HttpContext.Current.Request.Url.Port; // read parameters from the webpage string url = host + ":" + port + "/Pages/ReportesPDF.aspx?id=" + UsuarioCompleto.Usuario.id_usuario; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { webPageWidth = Convert.ToInt32(1024); } catch { } int webPageHeight = 0; try { webPageHeight = Convert.ToInt32(0); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // esto es re importante // lo que hago es setearle un delay de X segundos // para que se puedan generar los graficos normalmente converter.Options.MinPageLoadTime = 5; // create a new pdf document converting an url PdfDocument doc = converter.ConvertUrl(url); // save pdf document doc.Save(Response, false, "Informe_Nutricloud_" + hoy.ToString("dd-MM-yyyy") + ".pdf"); // close pdf document doc.Close(); }
private byte[] HtmlToPdf(string htmlBody, string htmlFooter) { // get parameters string headerUrl = Startup.ServerPath + @"\wwwroot\templates\header.html"; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // header settings converter.Options.DisplayHeader = true; converter.Header.Height = 20; PdfHtmlSection headerHtml = new PdfHtmlSection(headerUrl) { AutoFitHeight = HtmlToPdfPageFitMode.AutoFit }; converter.Header.Add(headerHtml); // footer settings converter.Options.DisplayFooter = true; converter.Footer.Height = 165; PdfHtmlSection footerHtml = new PdfHtmlSection(htmlFooter, null) { AutoFitHeight = HtmlToPdfPageFitMode.AutoFit, AutoFitWidth = HtmlToPdfPageFitMode.AutoFit, WebPageWidth = 793 }; converter.Footer.Add(footerHtml); // read parameters from the webpage PdfPageSize pageSize = PdfPageSize.A4; PdfPageOrientation pdfOrientation = PdfPageOrientation.Portrait; int webPageWidth = 793; int webPageHeight = 0; // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; converter.Options.MarginLeft = 0; converter.Options.MarginRight = 0; //set document permissions converter.Options.SecurityOptions.CanAssembleDocument = false; converter.Options.SecurityOptions.CanCopyContent = true; converter.Options.SecurityOptions.CanEditAnnotations = false; converter.Options.SecurityOptions.CanEditContent = false; converter.Options.SecurityOptions.CanPrint = true; converter.Options.PdfDocumentInformation.Title = "CPD Activity Accreditation"; converter.Options.PdfDocumentInformation.CreationDate = DateTime.UtcNow; converter.Options.PdfDocumentInformation.Subject = "CPD Activity Accreditation"; converter.Options.PdfDocumentInformation.Keywords = "scfhs.org.sa"; // create a new pdf document converting an url SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlBody); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); // return resulted pdf document return(pdf); }
// need to do some sort of caching by retrievingthe file only if it has been converted before. public string ConvertToPdf(MatchModel match, string url) { try { var fileName = $"{match.TeamA} vs {match.TeamB} - {match.Score}.pdf"; fileName = stripIllegalCharacters(fileName); var filePath = Path.Combine(AppState.ScoresheetRepo, fileName); if (checkIfFileExists(filePath)) { return(File.ReadAllBytes(filePath).ToBase64()); } else { Logger.LogDebug($@"Converting {url} to PDF..."); string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; int webPageHeight = 0; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; PdfDocument doc = null; // create a new pdf document converting an url doc = converter.ConvertUrl(url); Logger.LogDebug($"Saving '{filePath}'..."); // save pdf document doc.Save(filePath); Logger.LogDebug($"'{filePath}' Saved!"); // close pdf document doc.Close(); Logger.LogDebug($"Closing '{filePath}'..."); Logger.LogDebug($"Converting File Bytes to Base64..."); var base64 = File.ReadAllBytes(filePath).ToBase64(); Logger.LogDebug($"Done!"); return(base64); } } catch (Exception ex) { ex.CustomLog(Logger, "Failed to convert HTML to PDF and save the file."); throw; } }
// POST: contents/Delete/5 // select pdf library public FileStreamResult DownloadZip(string id) { MemoryStream workStream = new MemoryStream(); content content = db.contents.Find(id); // read parameters from the webpage string htmlString = content.content_post; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { webPageWidth = 1024; } catch { } int webPageHeight = 0; try { webPageHeight = 0; } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlString); byte[] pdf = doc.Save(); doc.Close(); // put pdf into zip using (var zip = new ZipFile()) { zip.AddEntry(content.content_id + ".pdf", pdf); zip.Save(workStream); } workStream.Position = 0; FileStreamResult fileResult = new FileStreamResult(workStream, System.Net.Mime.MediaTypeNames.Application.Zip); fileResult.FileDownloadName = content.content_id + ".zip"; return(fileResult); }
protected void lnkDownload_Click(object sender, EventArgs e) { LinkButton lnkDownload = (LinkButton)sender; lnkDownload.Enabled = false; DataTable dt = (DataTable)ViewState["TestKey"]; string testkey = dt.Rows[0]["TestKey"].ToString(); string currenturl = HttpContext.Current.Request.Url.AbsoluteUri; currenturl = currenturl.Split('/')[2]; string url = "http://" + currenturl + "/Teacher/" + "Report.aspx?TestAssignedId=" + lnkDownload.CommandArgument.ToString(); string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Landscape"; // string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1120; // int webPageWidth = 1024; try { // webPageWidth = Convert.ToInt32(1024); webPageWidth = Convert.ToInt32(1120); } catch { } int webPageHeight = 0; try { webPageHeight = Convert.ToInt32(0); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url SelectPdf.PdfDocument doc = converter.ConvertUrl(url); // save pdf document doc.Save(Response, false, lnkDownload.CommandName + "_" + testkey + ".pdf"); // close pdf document doc.Close(); lnkDownload.Enabled = true; }
public static Rectangle GetPageOrientation(PdfPageOrientation pageOrientation) { if (pageOrientation == PdfPageOrientation.Retrato) { return(PageSize.A4); } return(PageSize.A4.Rotate()); }
public void pdf() { string htmlString = ""; var file = (System.Web.HttpContext.Current.Server.MapPath("~/") + "practice-hours.html"); var html = "<TR VALIGN=TOP><TD WIDTH=75 STYLE='border-top: 3.00pt solid #6773b6; border-bottom: 3.00pt solid #6773b6; border-left: 3.00pt solid #6773b6; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in'>" + "<P CLASS='western' STYLE='widows: 0; orphans: 0;padding-top:12px;'><FONT COLOR='#5162a5'><FONT FACE='Arial, sans-serif'><FONT SIZE=2><SPAN LANG='en-GB'><B>Dates:</B></SPAN></FONT></FONT></FONT></P></TD>" + "<TD WIDTH=115 STYLE='border-top: 3.00pt solid #6773b6; border-bottom: 3.00pt solid #6773b6; border-left: 3.00pt solid #6773b6; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in'>" + "<P CLASS='western' STYLE='widows: 0; orphans: 0;padding-top:12px;'><FONT COLOR='#5162a5'><FONT FACE='Arial, sans-serif'><FONT SIZE=2><SPAN LANG='en-GB'><B>Name and address of <BR> organisation:</B></SPAN></FONT></FONT></FONT></P></TD>" + "<TD WIDTH=115 STYLE='border-top: 3.00pt solid #6773b6; border-bottom: 3.00pt solid #6773b6; border-left: 3.00pt solid #6773b6; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in'>" + "<P CLASS='western' STYLE='widows: 0; orphans: 0;padding-top:12px;'><FONT COLOR='#5162a5'><FONT FACE='Arial, sans-serif'><FONT SIZE=2><SPAN LANG='en-GB'><B>Name and address of <BR> organisation:</B></SPAN></FONT></FONT></FONT></P></TD>" + "<TD WIDTH=115 STYLE='border-top: 3.00pt solid #6773b6; border-bottom: 3.00pt solid #6773b6; border-left: 3.00pt solid #6773b6; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in'>" + "<P CLASS='western' STYLE='widows: 0; orphans: 0;padding-top:12px;'><FONT COLOR='#5162a5'><FONT FACE='Arial, sans-serif'><FONT SIZE=2><SPAN LANG='en-GB'><B>Name and address of <BR> organisation:</B></SPAN></FONT></FONT></FONT></P></TD>" + "<TD WIDTH=115 STYLE='border-top: 3.00pt solid #6773b6; border-bottom: 3.00pt solid #6773b6; border-left: 3.00pt solid #6773b6; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in'>" + "<P CLASS='western' STYLE='widows: 0; orphans: 0;padding-top:12px;'><FONT COLOR='#5162a5'><FONT FACE='Arial, sans-serif'><FONT SIZE=2><SPAN LANG='en-GB'><B>Name and address of <BR> organisation:</B></SPAN></FONT></FONT></FONT></P></TD>" + "<TD WIDTH=115 STYLE='border-top: 3.00pt solid #6773b6; border-bottom: 3.00pt solid #6773b6; border-left: 3.00pt solid #6773b6; border-right: none; padding-top: 0in; padding-bottom: 0in; padding-left: 0.08in; padding-right: 0in'>" + "<P CLASS='western' STYLE='widows: 0; orphans: 0;padding-top:12px;'><FONT COLOR='#5162a5'><FONT FACE='Arial, sans-serif'><FONT SIZE=2><SPAN LANG='en-GB'><B>Name and address of <BR> organisation:</B></SPAN></FONT></FONT></FONT></P></TD>" + "<TD WIDTH=266 STYLE=border: 3.00pt solid #6773b6; padding-top: 0.08in; padding-bottom: 0.08in; padding-left: 0.08in; padding-right: 0.39in'><P CLASS='western' STYLE='margin-bottom: 0in; widows: 0; orphans: 0;padding-top:6px;'>" + "<FONT COLOR=\"#5162a5\"><FONT FACE=\"Arial, sans-serif\"><FONT SIZE=2><SPAN LANG=\"en-GB\"><B>Brief description of your work:</B></SPAN></FONT></FONT></FONT></P><P LANG=\"en-GB\" STYLE=\"margin-right: -0.34in; widows: 0; orphans: 0\">" + "<BR></P></TD></TR>"; using (StreamReader sr1 = new StreamReader(file)) { htmlString = sr1.ReadToEnd(); } htmlString = htmlString.Replace("@practicehours@", html); string baseUrl = System.Web.HttpContext.Current.Server.MapPath("~/"); string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; int webPageHeight = 0; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl); // save pdf document //doc.Save("Vehicle.pdf"); doc.Save(baseUrl + "Sample.pdf"); // close pdf document doc.Close(); }
public ActionResult VoteProofDownload(string candidateId) { // read parameters from the webpage string htmlString = GetProofPdfHtml(candidateId); string baseUrl = ""; string pdf_page_size = PdfPageSize.A4.ToString(); PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = PdfPageOrientation.Portrait.ToString(); PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { webPageWidth = Convert.ToInt32(""); } catch { } int webPageHeight = 0; try { webPageHeight = Convert.ToInt32(""); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); // return resulted pdf document FileResult fileResult = new FileContentResult(pdf, "application/pdf"); fileResult.FileDownloadName = "Vote-Proof-Download.pdf"; return(fileResult); }
public ActionResult SubmitAction(FormCollection collection) { // read parameters from the webpage string htmlString = collection["TxtHtmlCode"]; string baseUrl = collection["TxtBaseUrl"]; string pdf_page_size = collection["DdlPageSize"]; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = collection["DdlPageOrientation"]; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { webPageWidth = Convert.ToInt32(collection["TxtWidth"]); } catch { } int webPageHeight = 0; try { webPageHeight = Convert.ToInt32(collection["TxtHeight"]); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); // return resulted pdf document FileResult fileResult = new FileContentResult(pdf, "application/pdf"); fileResult.FileDownloadName = "Document.pdf"; return(fileResult); }
public ActionResult getPDF() { // read parameters from the webpage string htmlString = @"<html><body><h1>Pakistan</h1></body></html>"; string baseUrl = ""; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { webPageWidth = Convert.ToInt32("1024"); } catch { } int webPageHeight = 0; try { webPageHeight = Convert.ToInt32("1024"); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); // return resulted pdf document FileResult fileResult = new FileContentResult(pdf, "application/pdf"); fileResult.FileDownloadName = "Document.pdf"; return(fileResult); }
public ActionResult ExportToPdf(string pYear, string pMonth, string pCode) { // read parameters from the webpage string htmlString = "<html><body><div style=\" margin-top:30px; margin-left:20px;\"><p>" + pMonth + " | " + pYear + "</p><p><b><h2>Código de Inspección: " + pCode + "</h2></b></p><div></body></html>"; string baseUrl = string.Empty; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse( typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { webPageWidth = System.Convert.ToInt32(900); } catch { } int webPageHeight = 0; try { webPageHeight = System.Convert.ToInt32(500); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); // return resulted pdf document FileResult fileResult = new FileContentResult(pdf, "application/pdf"); fileResult.FileDownloadName = "Codigo_Inspeccion.pdf"; return(fileResult); }
public ActionResult GetPdf(string html) { // read parameters from the webpage string htmlString = html; string baseUrl = ""; string pdf_page_size = "Letter"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { // webPageWidth = Convert.ToInt32(TxtWidth.Text); } catch { } int webPageHeight = 0; try { //webPageHeight = Convert.ToInt32(TxtHeight.Text); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl); // save pdf document // doc.Save( false, "Sample.pdf"); doc.Save(Server.MapPath("~/" + "Sample" + ".pdf")); // close pdf document doc.Close(); return(Content("Documento Guardado!!")); }
public IActionResult OnPost() { // read parameters from the webpage PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), DdlPageSize, true); PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), DdlPageOrientation, true); int webPageWidth = 1024; try { webPageWidth = Convert.ToInt32(TxtWidth); } catch { } int webPageHeight = 0; try { webPageHeight = Convert.ToInt32(TxtHeight); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertHtmlString(TxtHtmlCode, TxtBaseUrl); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); // return resulted pdf document FileResult fileResult = new FileContentResult(pdf, "application/pdf"); fileResult.FileDownloadName = "Document.pdf"; return(fileResult); }
protected void BtnCreatePdf_Click(object sender, EventArgs e) { // read parameters from the webpage string htmlString = TxtHtmlCode.Text; string baseUrl = TxtBaseUrl.Text; string pdf_page_size = DdlPageSize.SelectedValue; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = DdlPageOrientation.SelectedValue; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { webPageWidth = Convert.ToInt32(TxtWidth.Text); } catch { } int webPageHeight = 0; try { webPageHeight = Convert.ToInt32(TxtHeight.Text); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl); // save pdf document doc.Save(Response, false, "Sample.pdf"); // close pdf document doc.Close(); }
public void ConvertPDF() { if (sesion == null) { sesion = SessionDB.start(Request, Response, false, db); } string htmlCode = @"<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>"; htmlCode = HttpUtility.UrlDecode(sesion.vdata["html"], System.Text.Encoding.Default); // read parameters from the webpage string htmlString = htmlCode; string baseUrl = "";// collection["TxtBaseUrl"]; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // license key GlobalProperties.LicenseKey = "KgEbChgfGwoZGx0fChsSBBoKGRsEGxgEExMTEw=="; // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = Convert.ToInt32(1024); converter.Options.WebPageHeight = Convert.ToInt32(0); converter.Options.MarginTop = 35; converter.Options.MarginBottom = 35; // create a new pdf document converting an url PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl); // save pdf document byte[] pdf = doc.Save(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", "inline; filename=ConstanciaRetencion.pdf"); Response.BinaryWrite(pdf); // close pdf document doc.Close(); }
private PdfPage In_CreatePage(float height, float width, PdfPageOrientation orientation) { if (orientation == PdfPageOrientation.Landscape) { float temp = width; width = height; height = width; } PdfPage newPage = new PdfPage(catalog.Pages, this, height, width); PdfDocument.RegisterForOutput(newPage); catalog.Pages.RegisterPage(newPage); return(newPage); }
public PdfPage CreatePage(PdfPageSizes pageSize, PdfPageOrientation orientation) { switch(pageSize) { case PdfPageSizes.A1: return In_CreatePage(31.45f, 22.22f, orientation); case PdfPageSizes.A2: return In_CreatePage(22.22f, 15.71f, orientation); case PdfPageSizes.A3: return In_CreatePage(15.71f, 11.11f, orientation); case PdfPageSizes.A4: return In_CreatePage(11.11f, 7.86f, orientation); case PdfPageSizes.A5: return In_CreatePage(7.86f, 5.54f, orientation); default: throw new InvalidOperationException("Parameter pageSize must be a member of the PdfPageSizes enumeration."); } }
public Byte[] ConvertToPdf(String html) { //string htmlString = html; //string baseUrl = ""; string pdf_page_size = "Custom"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Landscape"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = 1200; converter.Options.WebPageHeight = 0; PdfTextSection txtPageNum = new PdfTextSection(0, 10, "Page: {page_number} of {total_pages} ", new Font("Times New Roman", 10)); txtPageNum.HorizontalAlign = PdfTextHorizontalAlign.Right; converter.Footer.Add(txtPageNum); PdfTextSection txtDate = new PdfTextSection(0, 10, DateTime.Now.ToLongDateString(), new Font("Times New Roman", 10)); txtDate.HorizontalAlign = PdfTextHorizontalAlign.Left; converter.Footer.Add(txtDate); converter.Options.DisplayFooter = true; PdfDocument doc = converter.ConvertUrl(html); // save pdf document byte[] pdf = doc.Save(); // close pdf document doc.Close(); return(pdf); // return resulted pdf document }
public void ConvertToPdf() { string url = Url; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; int webPageHeight = 0; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; SetBusy(true, "Retrieving PDF..."); PdfDocument doc = null; Task.Factory.StartNew(() => { // create a new pdf document converting an url doc = converter.ConvertUrl(url); }).ContinueWith((t) => { // save pdf document doc.Save("Sample.pdf"); // close pdf document doc.Close(); FilePath = "Sample.pdf"; FilePath = Path.GetFullPath(FilePath); SetBusy(false, "Done!"); }); }
public IHttpActionResult ConvertHTML_PDF(String code_html) { try { string pagezise = "A4"; string orientation = "Portrait"; int width = 1024; int heigtn = 100; ApiHTMLtoPDF.Layout.PDF pdf = new Layout.PDF(); pdf._CodeHTML = code_html; pdf._PageZise = pagezise; pdf._Orientation = orientation; pdf._Width = width; pdf._Height = heigtn; PdfPageSize pagZise = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pagezise, true); PdfPageOrientation Orientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), orientation, true); int webPageWidth = Convert.ToInt32(width); int webPageHeight = Convert.ToInt32(heigtn); HtmlToPdf converter = new HtmlToPdf(); converter.Options.PdfPageSize = pagZise; converter.Options.PdfPageOrientation = Orientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; PdfDocument doc = converter.ConvertHtmlString(code_html, ""); HttpResponse httpResponse = new HttpResponse(new StreamWriter(new MemoryStream())); doc.Save(httpResponse, false, "Sample.pdf"); doc.Close(); return(Ok()); } catch (Exception ex) { throw; } }
public static async Task EmailUrlAsPdfAttachement(IEmailSender emailSender, string url, string recipient) { PdfPageSize pageSize = PdfPageSize.A4; PdfPageOrientation pdfOrientation = PdfPageOrientation.Portrait; int webPageWidth = 1024; int webPageHeight = 1000; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; converter.Options.CssMediaType = HtmlToPdfCssMediaType.Print; // create a new pdf document converting an url PdfDocument doc = converter.ConvertUrl(url); // create memory stream to save PDF MemoryStream pdfStream = new MemoryStream(); // save pdf document into a MemoryStream doc.Save(pdfStream); // reset stream position pdfStream.Position = 0; // create email message var subject = "Gym Card"; var message = "Print in colour and have it signed by Jeremie before laminating"; var attachment = new Attachment(pdfStream, "GymCard.pdf"); await emailSender.SendEmailAsync(recipient, subject, message, attachment); // close pdf document doc.Close(); }
public void GerarPDF(int idRelatorio, string conteudo) { string html = @"<html> <body style='background-color: gray;'> Hello World from selectpdf.com. </body> </html> "; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), "A4", true); PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), "Portrait", true); HtmlToPdf converter = new HtmlToPdf(); converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = 1024; converter.Options.WebPageHeight = 0; PdfDocument doc = converter.ConvertHtmlString(html); MemoryStream memoryStream = new MemoryStream(); doc.Save(memoryStream); byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); Response.Clear(); Response.ContentType = "application/force-download"; Response.AddHeader("content-disposition", "attachment; filename=arquivoPDF.pdf"); Response.BinaryWrite(bytes); Response.End(); doc.Close(); }
public PdfPage CreatePage(PdfPageSizes pageSize, PdfPageOrientation orientation) { switch (pageSize) { case PdfPageSizes.A1: return(In_CreatePage(31.45f, 22.22f, orientation)); case PdfPageSizes.A2: return(In_CreatePage(22.22f, 15.71f, orientation)); case PdfPageSizes.A3: return(In_CreatePage(15.71f, 11.11f, orientation)); case PdfPageSizes.A4: return(In_CreatePage(11.11f, 7.86f, orientation)); case PdfPageSizes.A5: return(In_CreatePage(7.86f, 5.54f, orientation)); default: throw new InvalidOperationException("Parameter pageSize must be a member of the PdfPageSizes enumeration."); } }
public static byte[] ToPdfBytes(string urlToConvert, PdfPageOrientation pageOrientation = PdfPageOrientation.Portrait) { // Create the PDF converter. Optionally the HTML viewer width can be specified as parameter // The default HTML viewer width is 1024 pixels. PdfConverter pdfConverter = new PdfConverter(); // set the license key - required pdfConverter.LicenseKey = "1f7n9ebm9eTl5uP15vvl9ebk++Tn++zs7Ow="; // set the converter options - optional pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4; pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Best; pdfConverter.PdfDocumentOptions.PdfPageOrientation = pageOrientation; pdfConverter.PdfDocumentOptions.TopMargin = 20; pdfConverter.PdfDocumentOptions.BottomMargin = 20; // set if the HTML content is resized if necessary to fit the PDF page width - default is true pdfConverter.PdfDocumentOptions.FitWidth = true; // set the embedded fonts option - optional - default is false pdfConverter.PdfDocumentOptions.EmbedFonts = true; // set if the JavaScript is enabled during conversion to a PDF - default is true pdfConverter.JavaScriptEnabled = true; // set if the images in PDF are compressed with JPEG to reduce the PDF document size - default is true pdfConverter.PdfDocumentOptions.JpegCompressionEnabled = true; pdfConverter.PdfDocumentOptions.LiveUrlsEnabled = false; pdfConverter.PdfDocumentOptions.InternalLinksEnabled = true; pdfConverter.ConversionDelay = 1; // Performs the conversion and get the pdf document bytes that can // be saved to a file or sent as a browser response return(pdfConverter.GetPdfBytesFromUrl(urlToConvert)); }
public void ConvertToPdf(object obj) { string url = "https://actionsport.spawtz.com/External/Fixtures/CricketScoreSheet.aspx?FixtureId=1518645"; string pdf_page_size = "A4"; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = "Portrait"; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; int webPageHeight = 0; // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; SetBusy(true, "Retrieving PDF..."); PdfDocument doc = null; Task.Factory.StartNew(() => { // create a new pdf document converting an url doc = converter.ConvertUrl(url); }).ContinueWith((t) => { // save pdf document doc.Save("Sample.pdf"); // close pdf document doc.Close(); SetBusy(false, "Done!"); }); }
public PdfPage CreatePage(PdfPageOrientation orientation) { return this.CreatePage(PdfPageSizes.A4, orientation); }
private PdfPage In_CreatePage(float height, float width, PdfPageOrientation orientation) { if(orientation == PdfPageOrientation.Landscape) { float temp = width; width = height; height = width; } PdfPage newPage = new PdfPage(catalog.Pages, this, height, width); PdfDocument.RegisterForOutput(newPage); catalog.Pages.RegisterPage(newPage); return newPage; }
/// <summary> /// Instantiates a new page format. /// Use predefined static instances for A3, A4, A5 and Letter. /// </summary> /// <param name="width">Width of the page in points (1 inch = 72 points).</param> /// <param name="height">Height of the page in points (1 inch = 72 points).</param> /// <param name="orientation">Page orientation.</param> public PdfPageFormat(double width, double height, PdfPageOrientation orientation = PdfPageOrientation.Portrait) { this.Height = height; this.Width = width; this.Orientation = orientation; }
public byte[] GenerarPDF_Horizontal(string viewName, object model, ControllerContext ctx, PdfPageSize pageSize, PdfPageOrientation orientation, float bottom, float top, float left, float right, bool hasFooter = true, bool hasHeader = false) { String View = RenderRazorViewToString(viewName, model, ctx); HiQPdf.HtmlToPdf docpdf = GetHtmlToPdf(bottom, top, left, right); docpdf.Document.PageOrientation = PdfPageOrientation.Landscape; SetFooter(docpdf.Document); if (hasFooter) SetFooter(docpdf.Document); if (hasHeader) SetHeader(docpdf.Document); byte[] archivo = docpdf.ConvertHtmlToPdfDocument(View, "").WriteToMemory(); return archivo; }