Example #1
0
        public IActionResult createPDF(int orderId)
        {
            PdfInvoiceTemplateGenerator pdfGenerator = new PdfInvoiceTemplateGenerator(_iorder, _config);

            try
            {
                var globalSettings = new GlobalSettings
                {
                    ColorMode   = ColorMode.Color,
                    Orientation = Orientation.Portrait,
                    PaperSize   = PaperKind.A4,
                    Margins     = new MarginSettings {
                        Top = 10
                    },
                    DocumentTitle = "PDF Report",
                    Out           = _config["PdfPath"] + orderId + ".pdf"
                };
                var objectSettings = new ObjectSettings
                {
                    PagesCount  = true,
                    HtmlContent = pdfGenerator.GetHTMLString(orderId),
                    // WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "styles.css") },
                    WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(_config["PdfPath"], "Assets", "styles.css") },
                    HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                    FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Visit   http://dollaritem.co.nz/ecom/terms-and-conditions   for full return terms and conditions." }
                };
                var pdf = new HtmlToPdfDocument()
                {
                    GlobalSettings = globalSettings,
                    Objects        = { objectSettings }
                };
                _converter.Convert(pdf);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }

            return(Ok("Successfully created PDF document."));
        }
Example #2
0
        public IActionResult createPDF(int invoice_number, string gst)
        {
            PdfInvoiceTemplateGenerator pdfGenerator = new PdfInvoiceTemplateGenerator(_invoice);

            try
            {
                var globalSettings = new GlobalSettings
                {
                    ColorMode   = ColorMode.Color,
                    Orientation = Orientation.Portrait,
                    PaperSize   = PaperKind.A4,
                    Margins     = new MarginSettings {
                        Top = 10
                    },
                    DocumentTitle = "PDF Report",
                    Out           = _config["PdfPath"] + invoice_number + ".pdf"
                };
                var objectSettings = new ObjectSettings
                {
                    PagesCount     = true,
                    HtmlContent    = pdfGenerator.GetHTMLString(invoice_number),
                    WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(_config["PdfPath"], "Assets", "styles.css") },
                    HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                    FooterSettings = { FontName = "Arial", FontSize = 9, Line = true }
                };
                var pdf = new HtmlToPdfDocument()
                {
                    GlobalSettings = globalSettings,
                    Objects        = { objectSettings }
                };
                _converter.Convert(pdf);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }

            return(Ok("Successfully created PDF document."));
        }