Esempio n. 1
0
        public async Task <SubjectCardPDF> Execute(int subjectCardId)
        {
            var subjectCard = await _subjectCardRepository.GetSubjectCardForReport(subjectCardId);

            var template       = GetHTMLString(subjectCard);
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "Karta przedmiotu"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount  = true,
                HtmlContent = template,
                WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "pdf.css") },
            };

            var document = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var pdfBytes  = _pdfConverter.Convert(document);
            var pdfReport = new SubjectCardPDF(pdfBytes, subjectCard.SubjectCode, subjectCard.Id);

            return(pdfReport);
        }
Esempio n. 2
0
        public async Task <IActionResult> GetStatisticsPdf()
        {
            var statistics = await _statisticsService.GetStatisticsAsync();

            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = $"Statistics Raport {DateTime.UtcNow}"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = RaportTemplate.GetHTMLTemplate(statistics),
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "SimpleBlog raport" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf"));
        }
Esempio n. 3
0
        private void setDocumentSettings()
        {
            globalSettings = new GlobalSettings()
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = Title,
            };

            objectSettings = new ObjectSettings()
            {
                PagesCount  = true,
                HtmlContent = htmlData,//TemplateGenerator.GetHTMLString(),    // HTML String Goes here for the data
                // PDF stylesheet is saved into PdfGenerator/assets/styles.css
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "CSUN Student Report" }
            };

            pdfDocument = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };
        }
Esempio n. 4
0
        public byte[] ConvertToPdfReport(string htmlReport)
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,

                Margins = new MarginSettings {
                    Top = 20
                }
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount = true,

                HtmlContent    = htmlReport,
                WebSettings    = { DefaultEncoding = "utf-8" },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Line = true, Spacing = 1.8, Center = "Test Report" },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Right = "Trang [page] / [toPage]", Spacing = 1.8 }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            return(pdfConverter.Convert(pdf));
        }
Esempio n. 5
0
        private static List <GenericSensorTarget> GetTargetFromName(string response, string tableName)
        {
            var checkboxes = CreateFromCheckbox(response, tableName, o => new GenericSensorTarget(o));

            if (checkboxes.Count > 0)
            {
                return(checkboxes);
            }

            var options = CreateFromDropDownOptions(response, tableName, o => new GenericSensorTarget(o));

            if (options.Count > 0)
            {
                return(options);
            }

            //todo: we should filter out the common items, and then dont display that item type description entirely if there are none
            //if there are none of EITHER, fall back and just list all of them (including hidden)

            var allCheckboxes = ObjectSettings.GetInput(response).Where(i => i.Type == InputType.Checkbox).ToList();
            var allDropdowns  = ObjectSettings.GetDropDownList(response).ToList();

            if (allCheckboxes.FirstOrDefault(c => c.Name == tableName) == null &&
                allDropdowns.FirstOrDefault(d => d.Name == tableName) == null)
            {
                throw GetInvalidNameException(allCheckboxes, allDropdowns, tableName);
            }

            return(new List <GenericSensorTarget>());
        }
Esempio n. 6
0
        public byte[] GetInvoicePdfDocument(Invoice invoice)
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = $"Faktura - {invoice.InvoiceNumber}"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = HtmlStringBuilder.HtmlInvoiceDocument(invoice),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "css/site.css") },
                HeaderSettings = { FontName = "Calibri", FontSize = 10, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Calibri", FontSize = 10, Line = true, Center = $"Faktura - {invoice.InvoiceNumber}" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            return(file);
        }
Esempio n. 7
0
        public IActionResult Privacy()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                Margins     = new MarginSettings {
                    Top = 10
                },
                PaperSize     = PaperKind.A4,
                DocumentTitle = "PDF Report"
            };
            var objectSettings = new ObjectSettings()
            {
                PagesCount = true,
                //HtmlContent = TemplateGeneratorForInvoice.GetHTMLString(),
                Page           = "https://code-maze.com",
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "invoiceStyleSheet.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true, Spacing = 2.812 },
                FooterSettings = { FontName = "Arial", FontSize = 9, Center = "Report Header" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };
            var file = _converter.Convert(pdf);

            return(File(file, "applicatio/pdf", "Invoice.pdf"));
        }
Esempio n. 8
0
    public static IObjectController CreateObjectController(ObjectSettings settings)
    {
        IObjectController result = (settings.PINK ? new PinkObject() : (IObjectController) new BlueObject());

        result.Initialise(settings);
        return(result);
    }
Esempio n. 9
0
        public async Task <byte[]> Create()
        {
            try
            {
                var model = new List <CarModel>()
                {
                    new CarModel {
                        NameOfCar = "Audi Q7", FirstRegistration = DateTime.UtcNow.AddYears(-3), MaxSpeed = 200, NumberOfDoors = 4
                    },
                    new CarModel {
                        NameOfCar = "Audi A5", FirstRegistration = DateTime.UtcNow, MaxSpeed = 180, NumberOfDoors = 4
                    },
                    new CarModel {
                        NameOfCar = "Audi Q3", FirstRegistration = DateTime.UtcNow, MaxSpeed = 245, NumberOfDoors = 2
                    },
                    new CarModel {
                        NameOfCar = "Mercedes SLI", FirstRegistration = DateTime.UtcNow, MaxSpeed = 150, NumberOfDoors = 4
                    },
                    new CarModel {
                        NameOfCar = "Chevrolet", FirstRegistration = DateTime.UtcNow, MaxSpeed = 220, NumberOfDoors = 4
                    },
                    new CarModel {
                        NameOfCar = "BMW", FirstRegistration = DateTime.UtcNow, MaxSpeed = 200, NumberOfDoors = 4
                    },
                };
                var    templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), $"PdfTemplates/CarPdf.cshtml");
                string template     = await _razorEngine.CompileRenderAsync(templatePath, model);

                var globalSettings = new GlobalSettings
                {
                    ColorMode   = ColorMode.Color,
                    Orientation = Orientation.Portrait,
                    PaperSize   = PaperKind.A4,
                    Margins     = new MarginSettings()
                    {
                        Top = 10, Bottom = 10, Left = 10, Right = 10
                    },
                    DocumentTitle = "Simple PDF document",
                };
                var objectSettings = new ObjectSettings
                {
                    PagesCount     = true,
                    HtmlContent    = template,
                    WebSettings    = { DefaultEncoding = "utf-8" },
                    HeaderSettings = { FontName = "Arial", FontSize = 12, Line = true, Center = "Fun pdf document" },
                    FooterSettings = { FontName = "Arial", FontSize = 12, Line = true, Right = "Page [page] of [toPage]" }
                };
                var pdf = new HtmlToPdfDocument()
                {
                    GlobalSettings = globalSettings,
                    Objects        = { objectSettings }
                };
                byte[] file = _pdfConverter.Convert(pdf);
                return(file);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 10
0
        public IActionResult ShowPdf()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report",
                //Out = @"D:\PDFCreator\Employee_Report.pdf"  USE THIS PROPERTY TO SAVE PDF TO A PROVIDED LOCATION
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount = true,
                // HtmlContent = TemplateGenerator.GetHTMLString(),
                Page           = "https://www.ideashubs.com/everest-base-camp-trek-best-time-to-trek-in-everest-base-camp/", //USE THIS PROPERTY TO GENERATE PDF CONTENT FROM AN HTML PAGE
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var file = _pdfConverterService.ConvertToPdfFile(globalSettings, objectSettings);

            return(File(file, "application/pdf", $"pdf_generated_{DateTime.Now.Ticks}.pdf"));
        }
        public IActionResult CreatePDF()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report",
                Out           = @"C:\PDFCreator\Employee_Report.pdf"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = "<!DOCTYPEhtml><html><head><style>table{font-family:arial,sans-serif;border-collapse:collapse;width:100%;}td,th{border:1pxsolid#dddddd;text-align:left;padding:8px;}tr:nth-child(even){background-color:#dddddd;}</style></head><body><h5>Thank you for your order.....</h5><br /><h5>We will contact you soon for delivery and payment.</h5><br /><h3>Your Order Details:</h3><div><table><tr style='background-color:#1f3933;color:white'><th style='text-align:center;width:20%'>{0}</th><th style='text-align:center;'><label>ProductName</label></th><th style='text-align:center;'><label>Type</label></th><th style='text-align:center;'><label>QTY</label></th><th style='text-align:center;'><label>Price</label></th><th style='text-align:center;'><label>Total</label></th><th style='text-align:center;'><label>Vat</label></th><th style='text-align:center;'><label>Total with VAT</label></th></tr> < tr style = 'padding:50px' >< td >< img src = '{0}' width = '50px' style = 'margin:auto; display:block;border-radius:5px;border:1px solid #bbb9b9' /></ td >< td style = 'text-align:center' >{ 1 }</ td >< td style = 'text-align:center' >{ 2 }</ td >< td style = 'text-align:center' >{ 3 }</ td >< td style = 'text-align:center' >{ 4 }</ td >< td style = 'text-align:center' >{ 5 }</ td >< td style = 'text-align:center' >{ 6 }</ td >< td style = 'text-align:center' >{ 7 }</ td ></ tr >< tr style = 'background-color:#1f3933;color:white' >< th style = 'text-align:center; width:30%;' >{ 0 }</ th >< th style = 'text-align:center;' >< label ></ label ></ th >< th style = 'text-align:center;' >< label ></ label ></ th >< th style = 'text-align:center;' ></ th >< th style = 'text-align:center;' >< label >{ 1 }</ label ></ th >< th style = 'text-align:center;' >< label > Total </ label ></ th >< th style = 'text-align:center;' >< label >{ 1 }</ label ></ th >< th style = 'text-align:center;' >< label >{ 2 }</ label ></ th ></ tr ></ table ></ div >< br />< br />< br />< div >< a href = 'https://www.primoceramic.com' style = 'text-decoration:none;color: #1f3933' > PrimoCermaic </ a >< br />< br />< a href = 'mailto:[email protected]' style = 'text-decoration:none;color: #1f3933' > [email protected] </ a ></ div ></ body ></ html > ",
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };


            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf", "EmployeeReport.pdf"));
        }
Esempio n. 12
0
        public TemplateGeneratorAll(IConverter converter)
        {
            _converter     = converter;
            globalSettings = new GlobalSettings();

            ObjectSettingsTrituration    = new ObjectSettings();
            StringBuilderTrituration     = new StringBuilder();
            HtmlToPdfDocumentTrituration = new HtmlToPdfDocument();

            ObjectSettingsAchat    = new ObjectSettings();
            StringBuilderAchat     = new StringBuilder();
            HtmlToPdfDocumentAchat = new HtmlToPdfDocument();

            ObjectSettingsVente    = new ObjectSettings();
            StringBuilderVente     = new StringBuilder();
            HtmlToPdfDocumentVente = new HtmlToPdfDocument();

            ObjectSettingsGrignon    = new ObjectSettings();
            StringBuilderGrignon     = new StringBuilder();
            HtmlToPdfDocumentGrignon = new HtmlToPdfDocument();

            globalSettings.ColorMode   = ColorMode.Color;
            globalSettings.Orientation = Orientation.Landscape;
            globalSettings.PaperSize   = PaperKind.A5;
            globalSettings.Margins     = new MarginSettings {
                Top = 10
            };
        }
Esempio n. 13
0
        public async Task <byte[][]> GetBillsBinary()
        {
            byte[][] billAsBinaryData = new byte[3][]; //jagged array, or array of arrays. Declares an array which has 3 elements, each of which is an array of bytes
            var      apartments       = await this.apartmentRepository.GetAllAsync();

            for (int i = 0; i < apartments.Count(); i++)
            {
                Bill bill = await billRepository.GetBillCurrentMonthAsync(apartments.ElementAt(i).number);

                double debt = await billRepository.GetDebtAsync(apartments.ElementAt(i).number);

                var objectSettings = new ObjectSettings
                {
                    PagesCount  = true,
                    HtmlContent = HTMLGenerator.GetBillAsHtmlString(apartments.ElementAt(i), bill, debt),
                    WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "bills.scss") },
                };

                var pdf = new HtmlToPdfDocument()
                {
                    GlobalSettings = globalSettings,
                    Objects        = { objectSettings }
                };

                billAsBinaryData[i] = this.converter.Convert(pdf);
            }

            return(billAsBinaryData);
        }
Esempio n. 14
0
        public static byte[] PrintView(IConverter converter, string view, string title)
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = title
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = view,
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "app-assets/css", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = converter.Convert(pdf);

            return(file);
        }
Esempio n. 15
0
        public ReportObject(object _model, GlobalSettings _globalSettings, ObjectSettings _objectSettings)
        {
            this.Model          = _model;
            this.GlobalSettings = _globalSettings;

            if (GlobalSettings == null)
            {
                GlobalSettings = new GlobalSettings {
                    ColorMode   = ColorMode.Color,
                    Orientation = Orientation.Portrait,
                    PaperSize   = PaperKind.A4,
                    Margins     = new MarginSettings {
                        Top = 10
                    },
                    DocumentTitle = "ArcLan Report"
                }
            }
            ;

            this.ObjectSettings = _objectSettings;
            if (ObjectSettings == null)
            {
                ObjectSettings = new ObjectSettings();
            }
        }
    }
        public IActionResult CreatePDF()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.Letter,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "My PDF Report",
                Out           = @"C:\Moje\Visual Studio Projects\PDFGenerator\Report.pdf"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHtmlString(_dbRepository),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Right = "[page]", Center = "Report Footer", HtmUrl = Path.Combine(Directory.GetCurrentDirectory(), "assets", "footer.html") }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            _converter.Convert(pdf);

            return(Ok("Successfully created PDF document."));
        }
Esempio n. 17
0
        public byte[] ConvertToPdfFile(GlobalSettings globalSettings, ObjectSettings objectSettings, bool saveToDirectory)
        {
            try
            {
                if (saveToDirectory && string.IsNullOrEmpty(globalSettings.Out))
                {
                    throw new Exception("Out property should initialize to save");
                }

                var pdf = new HtmlToPdfDocument()
                {
                    GlobalSettings = globalSettings,
                    Objects        = { objectSettings }
                };

                var file = _converter.Convert(pdf);
                //
                //IF WE USE Out PROPERTY IN THE GlobalSettings CLASS, THIS IS ENOUGH FOR CONVERSION

                return(file);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Esempio n. 18
0
        public byte[] ConvertToPdf()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Invoice"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = "",
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var doc = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            return(_convertor.Convert(doc));
        }
Esempio n. 19
0
        public IActionResult CreatePdfForUser(int userId)
        {
            var templateGenerator = new TemplateGenerator(_repo, _mapper);
            var globalSettings    = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 15, Bottom = 20
                },
                DocumentTitle = "بطاقة مشترك"
            };
            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = templateGenerator.GetHTMLStringForUser(userId),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Impact", FontSize = 12, Spacing = 5, Line = false },
                FooterSettings = { FontName = "Geneva", FontSize = 15, Spacing = 7, Line = true, Center = "ZwajApp By Eng Muhammad Reda Sobh", Right = "[page]" }
            };
            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };
            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf"));
        }
Esempio n. 20
0
        public ActionResult Contact()
        {
            DinkToPdf.Contracts.IConverter _converter = new SynchronizedConverter(new PdfTools());
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = DinkToPdf.Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "Owned",
                Out           = @"C:\Users\Jodson\test.pdf"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLString(),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf"));
        }
Esempio n. 21
0
        public byte[] GeneratePDFFromView <TModel>(string templateName, TModel model)
        {
            var documentContent = _templateService.RenderTemplateAsync(templateName, model);

            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount  = true,
                HtmlContent = documentContent,
                WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "Views", "style.css") }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            return(_converter.Convert(pdf));
        }
Esempio n. 22
0
        public IActionResult CreatePDF()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "Loai Report"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLString(),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Trang [page]/[toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf"));
        }
        public IActionResult CreatePdf(PriceReport report)
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                Out = @"C:\Data\PriceReport.pdf"
            };
            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLString(report),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            _converter.Convert(pdf);
            return(Ok("Successfully created PDF document at C:\\Data\\PriceReport.pdf"));

            // return View();
        }
Esempio n. 24
0
        public IActionResult CreateReport()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "Wypłaty wynagrodzeń za ostatni miesiąc",
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = GetHTMLString(),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/css", "ReportStyle.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Strona [page] z [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "2020 - HRMS_Project" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };


            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf"));
        }
Esempio n. 25
0
        public byte[] CreatePdf(string htmlContent)
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                //Margins = new MarginSettings
                //{
                //    Top = 10,
                //    Left = 0,
                //    Right = 0,
                //},
                DocumentTitle = "PDF Report",
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount  = true,
                HtmlContent = htmlContent,
                WebSettings = { DefaultEncoding = "utf-8" },
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            return(file);
        }
        public IActionResult CreatePDFForVaccinations(int id)
        {
            var lists = _repo.GetVaccinationList(id).ToList();

            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report",
                Out           = $"D:\\Vaccination_List_Report_{DateTime.Now.Second.ToString()}.pdf"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLStringForVaccinations(lists),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Content", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Страница [page] из [toPage]", Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Left = "Дата " + DateTime.Now.Date.ToShortDateString() }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            _converter.Convert(pdf);

            return(Ok("Отчет загружен в папку D"));
        }
Esempio n. 27
0
        public HtmlToPdfDocument getPdf()
        {
            var incidents = _incidentService.GetAll();

            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "PDF Report",
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount     = true,
                HtmlContent    = TemplateGenerator.GetHTMLString(incidents),
                WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                HeaderSettings = { FontName = "Arial", FontSize = 25, Right = "Raport Watchman, " + DateTime.Now.ToString("dd.MM.yyyy"), Line = true },
                FooterSettings = { FontName = "Arial", FontSize = 25, Line = true, Center = "WATCHMAN" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            return(pdf);
        }
Esempio n. 28
0
        public async Task <byte[]> CreatePDF(string titleName, string htmlText)
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 15, Bottom = 25, Left = 25, Right = 15
                },
                DocumentTitle = titleName
            };
            var objectSettings = new ObjectSettings
            {
                HtmlContent    = htmlText,
                WebSettings    = { DefaultEncoding = "utf-8" },
                FooterSettings = new FooterSettings {
                    HtmUrl = Path.Combine(path, "Templates/Htmls/PRL/Htmls/PDFTemplate_Footer.html"), Line = true, Spacing = 5
                }
            };
            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings },
            };

            return(await Task.FromResult(_converter.Convert(pdf)));
        }
Esempio n. 29
0
        private byte[] GetPdfWithTableOfContents(string templatePage = "template.html")
        {
            var globalSettings = new GlobalSettings
            {
                PaperSize   = PaperKind.A4,
                Orientation = Orientation.Portrait
            };
            var templateSettings = new ObjectSettings
            {
                Page = templatePage
            };

            var tableOfContentSettings = new TableOfContentsSettings
            {
                IsTableOfContent = true
            };

            var doc = new HtmlToPdfDocument
            {
                GlobalSettings = globalSettings,

                Objects = { tableOfContentSettings, templateSettings }
            };

            byte[] pdf = Converter.Convert(doc);

            return(pdf);
        }
Esempio n. 30
0
        public IActionResult CreatePDF()
        {
            var globalSettings = new GlobalSettings
            {
                ColorMode   = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize   = PaperKind.A4,
                Margins     = new MarginSettings {
                    Top = 10
                },
                DocumentTitle = "百度"
                                // Out = @"D:\PDFCreator\Employee_Report.pdf"
            };

            var objectSettings = new ObjectSettings
            {
                PagesCount = true,
                // HtmlContent = TemplateGenerator.GetHTMLString(),
                Page = "https://www.cnblogs.com/",
                //WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "styles.css") },
                //HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                //FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
            };

            var pdf = new HtmlToPdfDocument()
            {
                GlobalSettings = globalSettings,
                Objects        = { objectSettings }
            };

            var file = _converter.Convert(pdf);

            return(File(file, "application/pdf", "百度.pdf"));
            //  return Ok("Successfully created PDF document.");
        }
Esempio n. 31
0
        public FileResult ScratchPad()
        {
            var doc = new HtmlToPdfDocument();
            var obj = new ObjectSettings();

            obj.PageUrl = Url.Action("PostAnything", "Home", routeValues: null, protocol: Request.Url.Scheme);
            obj.LoadSettings.CustomHeaders.Add("X-MY-HEADER", "my value");
            obj.LoadSettings.Cookies.Add("my_awesome_cookie", "cookie value");
            obj.LoadSettings.PostItems.Add(new PostItem 
            { 
                Name = "my_special_value", 
                Value = "is an amazing value" 
            });

            doc.Objects.Add(obj);

            var result = anotherConverter.Convert(doc);

            return File(result, "application/pdf");
        }