예제 #1
0
        public static string PrintChildren(
            string AChildName,
            string ADonorName,
            bool AChildWithoutDonor,
            string APartnerStatus,
            string ASponsorshipStatus,
            string ASponsorAdmin,
            string ASortBy,
            string AReportLanguage)
        {
            SponsorshipFindTDSSearchResultTable table = FindChildren(AChildName, ADonorName, AChildWithoutDonor, APartnerStatus, ASponsorshipStatus, ASponsorAdmin, ASortBy);

            HtmlDocument HTMLDocument = HTMLTemplateProcessor.Table2Html(table, "Sponsorship/SponsoredChildrenList.html", AReportLanguage);

            string PDFFile = TFileHelper.GetTempFileName(
                "printchildrenlist",
                ".pdf");

            if (Html2Pdf.HTMLToPDF(HTMLDocument.DocumentNode.WriteTo(), PDFFile))
            {
                byte[] data   = System.IO.File.ReadAllBytes(PDFFile);
                string result = Convert.ToBase64String(data);
                System.IO.File.Delete(PDFFile);
                return(result);
            }

            return(String.Empty);
        }
예제 #2
0
        public async Task <IActionResult> OnGetAsync(int?emid, int?inid)
        {
            HttpClient hc          = new HttpClient();
            var        url         = $"http://localhost:52169/Pdfs/HtmlReport?emid=" + (int)emid + "&inid=" + (int)inid;
            var        htmlContent = await hc.GetStringAsync(url);

            var    file     = Html2Pdf.ExportarPDF(htmlContent);
            string FilePath = "";

            try
            {
                FilePath = Path.Combine(_environment.ContentRootPath, "Data", "Uploads");
                var filepath = Path.Combine(FilePath, file);
                if (System.IO.File.Exists(filepath))
                {
                    byte[] fileBytes = System.IO.File.ReadAllBytes(filepath);
                    return(File(fileBytes, "application/x-msdownload", "Informe.pdf"));
                }
                else
                {
                    return(Redirect("/Informes/Details?emid=" + emid + "&inid=" + inid));
                }
            }
            catch (Exception e)
            {
                return(null);
            }
        }
예제 #3
0
        private static bool PrintToPDF(string AFilename, HtmlDocument AHTMLDocument)
        {
            // transform the HTML output to pdf file
            Html2Pdf.HTMLToPDF(AHTMLDocument.DocumentNode.WriteTo(), AFilename);

            return(true);
        }
예제 #4
0
        static async Task Main(string[] args)
        {
            var html2Pdf   = new Html2Pdf();
            var viewEngine = new FluidHtmlViewEngine();
            var htmlBody   = await File.ReadAllTextAsync($"Views\\index.html");

            var body = await viewEngine.RenderAsync(new { Name = "Con bướm xinh", Job = 100 }, htmlBody);

            File.WriteAllBytes("tententen.pdf", html2Pdf.ExportFromHtml(body));
        }
예제 #5
0
        // POST: api/Barcode

        public string Post([FromBody] BarcodeRequest objBarcodeRequest)
        {
            //BarcodeRequest obj = new BarcodeRequest();
            //obj.BarcodeType = "APP";
            //obj.CreateBarcode("IS2020042200004,IS2020042200005,IS2020042200006,IS2020042200007");

            LoadSettingsFromConfig();
            LogRequestData(logFileName, DateTime.Now + " API Configuration loaded");


            if (objBarcodeRequest == null)
            {
                LogRequestData(logFileName, DateTime.Now + " Web API Request Exception:- Bad Request");
                return("Web API Request Exception:- Bad Request");
            }

            string strResult = null;

            try
            {
                if (!objBarcodeRequest.ValidRequest())
                {
                    LogRequestData(logFileName, DateTime.Now + " Web API Request Exception:- Bad Request(Invalid)");
                    return("Web API Request Exception:- Bad Request(Invalid)");
                }
                LogRequestData(logFileName, DateTime.Now + " BarcodeType:- " + objBarcodeRequest.BarcodeType);
                LogRequestData(logFileName, DateTime.Now + " Barcode:- " + objBarcodeRequest.BarcodeString);

                BarcodeRequest objBarcode = new BarcodeRequest();
                objBarcode.BarcodeType    = objBarcodeRequest.BarcodeType;
                objBarcode.CIFInformation = objBarcodeRequest.CIFInformation;

                LogRequestData(logFileName, DateTime.Now + " CreateBarcode() started");
                int pageno = objBarcode.CreateBarcode(objBarcodeRequest.BarcodeString, objBarcodeRequest.BarcodeHeader);
                LogRequestData(logFileName, DateTime.Now + " CreateBarcode() Finished," + " Total Pages:-" + pageno);

                string strHTMLTemplate = "";

                if (objBarcode.BarcodeType.ToUpper() == "TXN")
                {
                    strHTMLTemplate = AppDomain.CurrentDomain.BaseDirectory + @"\Utilities\HTML\" + objBarcode.BarcodeType + pageno + ".html";
                }
                else if (objBarcode.BarcodeType.ToUpper() == "EOS")
                {
                    strHTMLTemplate = AppDomain.CurrentDomain.BaseDirectory + @"\Utilities\HTML\" + objBarcode.BarcodeType + ".html";
                }
                else if (objBarcode.BarcodeType.ToUpper() == "APP" || objBarcode.BarcodeType.ToUpper() == "DOC")
                {
                    strHTMLTemplate = AppDomain.CurrentDomain.BaseDirectory + @"\Utilities\HTML\DOC.html";
                }
                else if (objBarcode.BarcodeType.ToUpper() == "CIF")
                {
                    strHTMLTemplate = AppDomain.CurrentDomain.BaseDirectory + @"\Utilities\HTML\CIF.html";
                }


                LogRequestData(logFileName, DateTime.Now + " Template Name:- " + strHTMLTemplate);

                //Make request to create PDF from selected HTML template
                LogRequestData(logFileName, DateTime.Now + " Call to CreateHTML2PDF() is to be started");
                Html2Pdf objPDFRequest = new Html2Pdf();
                string   fileName      = objPDFRequest.CreateHTML2PDF(strHTMLTemplate, "", "");
                strResult = fileName;

                LogRequestData(logFileName, DateTime.Now + " Call to CreateHTML2PDF() Finished");
                if (!string.IsNullOrEmpty(fileName))
                {
                    string file = AppDomain.CurrentDomain.BaseDirectory + @"\Utilities\GeneratedPDFs\" + fileName;

                    if (System.IO.File.Exists(file))
                    {
                        LogRequestData(logFileName, DateTime.Now + " Copy file to Big Storage started");
                        System.IO.File.Copy(file, PDFDirectory + fileName);
                        LogRequestData(logFileName, DateTime.Now + " Copy file to Big Storage finished");
                        System.IO.File.Delete(file);
                    }
                }
            }


            catch (Exception ex)
            {
                LogRequestData(logFileName, DateTime.Now + "Web API Request Exception:- " + ex.Message);
                return("Web API Request Exception:- " + ex.Message);
            }


            ApiResponse objresponse = new ApiResponse();

            objresponse.ResultFilePath = strResult;
            if (string.IsNullOrWhiteSpace(strResult))
            {
                objresponse.ResponseMessage = "NG";
            }
            else
            {
                objresponse.ResponseMessage = "OK";
            }

            System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
            var strResultJSON = js.Serialize(objresponse);

            LogRequestData(logFileName, DateTime.Now + " Serialization completed, ready to send response");
            LogRequestData(logFileName, DateTime.Now + " Result JSON:- " + strResultJSON);

            return(strResultJSON);
        }