/// <summary> /// Gets the javascript script to prompt the printer with the pdf document /// </summary> /// <param name="SameWindow"></param> /// <returns></returns> public static string GetPrintInBrowser(this PdfMake pdfMake, bool SameWindow) { if (SameWindow) { return($"pdfMake.createPdf({pdfMake.GetDocumentDefinition()}).print({{}}, window);"); } else { return($"pdfMake.createPdf({pdfMake.GetDocumentDefinition()}).print({{}}, window.open('', '_blank'));"); } }
/// <summary> /// Sends a json result with the pdf document definition /// </summary> /// <returns></returns> public static ContentResult DocumentDefinitionInBrowser(this PdfMake pdfMake) { return(new ContentResult() { Content = pdfMake.GetDocumentDefinition(), ContentType = "application/json", StatusCode = 200 }); }
/// <summary> /// Gets the javascript script to display the pdf document in iframe /// </summary> /// <param name="IFrameQuerySelector"></param> /// <returns></returns> public static string GetEmbedInBrowserIframe(this PdfMake pdfMake, string IFrameQuerySelector) { if (string.IsNullOrWhiteSpace(IFrameQuerySelector)) { throw new ArgumentNullException("The IframeQuerySelector is null, empty or whitespace."); } return($@"pdfMake.createPdf({pdfMake.GetDocumentDefinition()}).getDataUrl(function(dataUrl) {{ document.querySelector('{IFrameQuerySelector }').src = dataUrl }});"); }
/// <summary> /// Gets the javascript script to dowload the pdf document /// </summary> /// <param name="Filename"></param> /// <returns></returns> public static string GetDownloadInBrowser(this PdfMake pdfMake, string Filename) { if (string.IsNullOrWhiteSpace(Filename)) { throw new ArgumentNullException("The Filename is null, empty or whitespace."); } if (!Filename.EndsWith(".pdf")) { throw new FormatException("The Filename does not end with .pdf extension."); } return($"pdfMake.createPdf({pdfMake.GetDocumentDefinition()}).download({Filename});"); }