Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap format in html partial view #169

Open
mkkb917 opened this issue Jan 4, 2023 · 1 comment
Open

bootstrap format in html partial view #169

mkkb917 opened this issue Jan 4, 2023 · 1 comment

Comments

@mkkb917
Copy link

mkkb917 commented Jan 4, 2023

Hi
I am generating the pdf from razor partial view in asp.net core
the pdf is working fine but the style and format are not applied to the pdf
I am using bootstrap for styling and formatting the web pages
plz consider for my help

`

public async Task<byte[]> CreatePdf(PaperViewVM paperViewVM)
        {
            var view = await _renderer.RenderPartialToStringAsync("_PaperViewBoardLayout", paperViewVM);
            string webRootPath = _webHostEnvironment.WebRootPath;
            string PaperPath = webRootPath + WC.PaperPathPDF;
            string guid = Guid.NewGuid().ToString();
            string fileName = paperViewVM.Setting.SubjectName + guid;
            string UniqueFileName = fileName + ".pdf";   
            var globalSettings = new GlobalSettings
            {
                ColorMode = ColorMode.Color,
                Orientation = Orientation.Portrait,
                PaperSize = PaperKind.A4,
                DPI = 300,
                ImageDPI = 900,
                Margins = new MarginSettings() { Top = 10, Bottom = 10, Left = 10, Right = 10 },
                Out = PaperPath + UniqueFileName,
            };
            var objectSettings = new ObjectSettings
            {
                PagesCount = true,
                HtmlContent = view,             // view is a html string from rendererhtmltostring method
                WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = Path.Combine(Directory.GetCurrentDirectory(), "assets", "bootstrap.css") }, 
                HeaderSettings = { FontName = "Arial", FontSize = 12, Line = true, Center = "Pdf Paper Generated by ExamSystem.com" },
                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);         
            var obj = new GeneratedPaper();
            obj.IsSuccess = true;
            obj.PaperPath = WC.PaperPathPDF + UniqueFileName;
            obj.CreatedBy = paperViewVM.Setting.CreatedBy;
            obj.SubjectName = paperViewVM.Setting.SubjectName;
            obj.CreateDate = DateTime.Now.Date;
            return file;
        }`

I tried to use bootstrap file for format reference but its not working
am i need to apply html formating styles on view for proper renderring the pdf

@eliseumade
Copy link

eliseumade commented May 30, 2023

sorted out? I have the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants