DocxFormatProvider Export - Table width is not aligned to width of the document

1 Answer 95 Views
PdfProcessing WordsProcessing
steven littleford
Top achievements
Rank 1
steven littleford asked on 08 Feb 2022, 12:47 PM
Hi,

We are creating a document with multiple tables using RadFlowDocument and exporting to byte array through DocxFormatProvider. Later converting to PDF document.

We are facing the problem to set the width of the table to align with complete document. Please refer the attached DocxFormatProvider_Export_toBytes.pdf which is having the tables(consider from second table) with right side space is left out.

The same is working fine when we export the RadFlowDocument to byte array through PdfFormatProvider (PDFFormatProvider_Export_toBytes.pdf).  The attached PDF documents are created through below code. 

----- Code -----

RadFlowDocument Targetdoc = new RadFlowDocument();

//Added Contents to Targetdoc 

DocxFormatProvider rfDocxProvider = new DocxFormatProvider();
byte[] docxoutput = rfDocxProvider.Export(Targetdoc);

var rPdfProvider = new PdfFormatProvider();
byte[] pdfoutput = rPdfProvider.Export(Targetdoc);

//PDF Files created

Version: 2021.1.322

We need to export from DocxFormatProvider only as we need to repeat the table header row for next pages.
Please help us to resolve table width issue.

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 09 Feb 2022, 01:02 PM

Hello Steven,

If understand correctly, you are either directly creating a PDF or converting a docx document. Am I right? If yes you can set the table widht with the following code:

var tables = this.document.EnumerateChildrenOfType<Table>();

foreach (var table in tables)
{
    table.PreferredWidth = new Telerik.Windows.Documents.Flow.Model.Styles.TableWidthUnit(Telerik.Windows.Documents.Flow.Model.Styles.TableWidthUnitType.Percent, 100);
}

Let me know how this works for you.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

steven littleford
Top achievements
Rank 1
commented on 09 Feb 2022, 07:04 PM

Hi Dimitar,

Thank you for the code provided. By setting the width of the table to 100%, we were able to resolve the issue.

Thank You

Tags
PdfProcessing WordsProcessing
Asked by
steven littleford
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or