HTML to PDF, No CSS and Unable to make landscape

3 posts, 0 answers
  1. Simon
    Simon avatar
    7 posts
    Member since:
    Sep 2015

    Posted 11 Jun 2019 Link to this post

    Hi, 

    I am looking at the WordsProcessing to use in a project to convert HTML to PDF, however I have two issues. One the CSS from the linked files are not being applied so the first and easy question is must this be inline styles \ css in the cshtml file

     

    The second is how do I get the output to show as landscape. My code below shows you how I am currently doing it and it is pushing out the HTML table and data but no styles from bootstrap (mentioned above) but its also very squashed so I need it to be in a landscape format. 

    public byte[] ConvertDocumentToPDF(byte[] fileData, string extension, ImageQuality exportQuality)
            {
                byte[] convertedData = null;
     
                RadFlowDocument document;
     
                IFormatProvider<RadFlowDocument> provider = this.providers
                    .FirstOrDefault(p => p.SupportedExtensions
                    .Any(e => string.Compare(extension, e, StringComparison.InvariantCultureIgnoreCase) == 0));
     
                if (provider == null)
                {
                    Log.Error($"No provider found that supports the extension: {extension}");
                    return null;
                }
     
                try
                {
                    using (Stream stream = new MemoryStream(fileData))
                    {
                        try
                        {
                            document = provider.Import(stream);
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex.ToString());
                            return null;
                        }
                    }
     
                    var quality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.Medium;
                    switch (exportQuality)
                    {
                        case ImageQuality.High:
                            quality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.High;
                            break;
     
                        case ImageQuality.Medium:
                            quality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.Medium;
                            break;
     
                        case ImageQuality.Low:
                            quality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.Low;
                            break;
                    }
     
                    PdfFormatProvider formatProvider = new PdfFormatProvider();
                    formatProvider.ExportSettings.ImageQuality = quality;
     
                    using (var stream = new MemoryStream())
                    {
                        formatProvider.Export(document, stream);
                        convertedData = stream.ToArray();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
     
                return convertedData;
            }

     

    Any and all help gratefully received. 

     

     

    Thanks

     

  2. Simon
    Simon avatar
    7 posts
    Member since:
    Sep 2015

    Posted 12 Jun 2019 in reply to Simon Link to this post

    In addition to the issue above, adding inline css \ pulling out bootstrap 4 css the html table that I have does not display correctly so inline CSS is not working as required either 
  3. Boby
    Admin
    Boby avatar
    751 posts

    Posted 14 Jun 2019 Link to this post

    Hello Simon,

    The CSS standard is not fully supported by the RadWordsProcessing's HTML import, so there is a chance there are some more advanced constructs/selectors that are not imported. Another possible reason could be that HTML is somewhat different from RadWordsProcessing's document model, and not every construct have one on one mapping. Still, I would suggest you to open a support ticket and send us the problematic HTML document for further investigation.

    You can also check the Section help article, and especially Rotating a Section and Modifying a Section sections for the possible methods change the section size or orientation, e.g. 
    section.Rotate(PageOrientation.Landscape);

    Regards,
    Boby
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top