End of text is being trimmed after using PdfFormatProvider to export an excel workbook

1 Answer 122 Views
PdfProcessing
Doug
Top achievements
Rank 1
Doug asked on 10 Nov 2022, 01:32 PM

I'm using Telerik.Documents.Spreadsheet (2022.3.1108) .Net C# 6.0.  I have my excel spreadsheet formated as I want (Excel.png).  The text in the cells are clearly visible.  Once the same spreadsheet is export using PdfFormatProvider.  The last half a character is trimmed (not visible). (Pdf.png).  While creating the excel file I do have "AutoFitWidth()" set for all the columns.

 

Export Code here


        public void CreatePdf(Workbook wb, string fileName)
        {
            var fixedProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();
            RadFixedDocument fixedDocument = fixedProvider.ExportToFixedDocument(wb);
                        

            var pdfFormatProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
            pdfFormatProvider.ExportSettings.ShouldEmbedFonts = true;

             using (Stream output = File.OpenWrite($"c:\\temp\\{fileName}.pdf"))
            {
                pdfFormatProvider.Export(fixedDocument, output);
            }
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay Demirev
Telerik team
answered on 10 Nov 2022, 03:46 PM

Hi Doug,

The AutoFitWidth feature requires the text in the cells of the document to be correctly measured. As the .NET Standard doesn't have any API for text measuring, we have implemented a simple text measurement suitable for most cases but not all. The good thing is that there is an easy way to implement better text measurement using the PdfProcessing library.

Before implementing the text measurement, you should use a custom font provider to measure the text correctly. The PdfProcessing needs to access the font of the measured text. In this article, you can find an example of how to implement that.

After implementing a custom font provider, it is time to provide the text measurement using the PdfProcessing library. This article explains how to do that.

After providing the required font and setting the SpreadFixedTextMeasurer, your document should size its columns perfectly.

Regards,
Nikolay Demirev
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
Doug
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Share this question
or