How to load css file

1 Answer 12 Views
PdfProcessing
Jay
Top achievements
Rank 1
Jay asked on 14 Jul 2021, 07:59 AM

Hi Team,

1.I want to load css file when import css file(bootstrap) and then export to a pdf file, but I find I lost all the css style, my code is below, did I miss something?

                    Telerik.Windows.Documents.Flow.FormatProviders.Html.HtmlFormatProvider htmlProvider
                        = new Telerik.Windows.Documents.Flow.FormatProviders.Html.HtmlFormatProvider();
                    // Create a document instance from the content. 
                    HtmlImportSettings importSettings = new HtmlImportSettings();
                    importSettings.LoadImageFromUri += (s, e) =>
                    {
                        // Load the data representing the resource  
                        SystemNet.WebClient webClient = new SystemNet.WebClient();
                        byte[] data = webClient.DownloadData(e.Uri);

                        // Pass the loaded data to the arguments 
                        string extension = SystemIO.Path.GetExtension(e.Uri).Substring(1); // Get the extension without the dot 
                        e.SetImageInfo(data, extension);
                    };
                    importSettings.LoadStyleSheetFromUri += (s, e) =>
                    {
                        string styles = fs.File.ReadAllText(Server.MapPath("~") + e.Uri);
                        e.SetStyleSheetContent(styles);
                    };
                    htmlProvider.ImportSettings = importSettings;
                    htmlProvider.ImportSettings.DefaultStyleSheet = string.Empty;
                    RadFlowDocument document = htmlProvider.Import(htmlStr);
                    Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider pdfProvider
                        = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
                    // Export the document. The different overloads enables you to export to a byte[] or to a Stream. 
                    byte[] pdfBytes = pdfProvider.Export(document);

2. Can I use the code like below to set the default style to empty?

                    htmlProvider.ImportSettings.DefaultStyleSheet = string.Empty;
 

'

 

 

1 Answer, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 19 Jul 2021, 05:05 AM

Hi Jay,

As far as I can see, your approach seems correct. Maybe there is some unsupported CSS construct, or there is some other issue that is specific to the document. I noticed that you sent the same inquiry through our support ticketing system. Would it be possible for you to send us the faulty HTML and CSS files and I will test the scenario on my side?

As for the DefaultStylesheet, you should be able to clear the defaults by setting it to empty.

Regards,
Ivan Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfProcessing
Asked by
Jay
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Share this question
or