aspose-free-consulting / projects

The starting point for Aspose free consulting projects
5 stars 5 forks source link

How to add css to pdf #357

Closed onopriienkoalina closed 2 months ago

onopriienkoalina commented 6 months ago

invoices project, i want to generate PDF from HTML. But pdf generets without css styles. Maybe I call 1089 (Home controller) string Html = RazorViewToStringFormat.RenderRazorViewToString(this, "IndexSummaryInvoices", summaryinvoices); in not correct place? Which place is correct to call for method RazorViewToStringFormat? windows, asp.net mvc 5

LP.zip

I hope that the provided information and files encompass everything needed to thoroughly investigate the matter. Should any additional details or resources be required, please don't hesitate to reach out. Thank you for your assistance in addressing this concern.

asadalikhan90 commented 6 months ago

@onopriienkoalina

Thanks for providing the sample project. We are looking into it and will get back to you shortly.

asadalikhan90 commented 5 months ago

@onopriienkoalina

Upon reviewing your project, we attempted to execute it; however, we encountered a challenge as the .zip archive did not contain .proj or .sln files. Consequently, we were unable to seamlessly transfer the folders into a new MVC solution and initiate the application. Additionally, we identified several absent dependencies during this process.

Nevertheless, we did check the code in RazorViewToStringFormat.cs file. It looks like the path to CSS and other content is specified relatively in your entire project. In such case, you need to specify the absolute path while initializing the HtmlLoadOptions like below:

HtmlLoadOptions objLoadOptions = new HtmlLoadOptions(HttpContext.Current.Server.MapPath("~/Content/"));

Make sure that all required resources are present in the directory that has been specified like above. In case issue still persists, please feel free to create a post in our official and dedicated support forum which is recommended and appropriate place to post such issues. You will also be able to have proper follow ups there.

onopriienkoalina commented 3 months ago

Screenshot (14) Screenshot (15)

Screenshot (16)

I used this HtmlLoadOptions objLoadOptions = new HtmlLoadOptions(HttpContext.Current.Server.MapPath("~/Content/")); but styles in css still not work. I use also Layout for view. in folder Content I have file with css. Can you give me example please, how it should be set up?

asadalikhan90 commented 3 months ago

@onopriienkoalina

If possible, can you please share the exported HTML with CSS in .zip format for our reference? OR you can share the complete HTML string in .txt file that is coming in your method GeneratePDF(string HtmlContent). We will check and use it to generate a valid PDF.

onopriienkoalina commented 3 months ago

aspose-20240201T140225Z-001.zip

I hope that the provided information and files encompass everything needed to thoroughly investigate the matter. Should any additional details or resources be required, please don't hesitate to reach out. Thank you for your assistance in addressing this concern.

asadalikhan90 commented 3 months ago

@onopriienkoalina

The shared .zip contains .cshtml views that have Razor syntax. We believe you must be converting these views into pure HTML and CSS files in order to pass to the API so that it can generate PDF. We requested for that HTML + CSS. If you can please share that with us, we can further proceed with the testing.