Row Height and text VerticalAlignment in WordsProcessing Table Cells

1 Answer 227 Views
General Discussions
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
Patgat asked on 21 Feb 2023, 01:22 PM

Hi,

first sorry for the general tag selected as I didn't find any specificone  about Document Processing.

I am creating a simple document mostly made up of tables  using the following code where neither the row.height, nor the VerticalAlignment are working (see attached screenshot).

I  would like much narrower cells and the text vertically centered.

How to achieve this ?

thanks

Patrick

 

RadFlowDocument document = new RadFlowDocument();
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);

Section section = new Telerik.Windows.Documents.Flow.Model.Section(document);
document.Sections.Add(section);

section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(40, 10, 40, 10);
section.PageSize = PaperTypeConverter.ToSize(PaperTypes.A4);

Table FactTable = section.Blocks.AddTable();

        for (int i = 0; i < datas.GetLength(0); i++)
        {
            TableRow row = new TableRow(document);
            row.Height = new TableRowHeight(HeightType.Exact, 14);
            PiedFactTable.Rows.Add(row);
            {
                TableCell cell = row.Cells.AddTableCell();
                cell.VerticalAlignment = VerticalAlignment.Center;
                Run run= cell.Blocks.AddParagraph().Inlines.AddRun(datas[i]);
            }
        }

Dimitar
Telerik team
commented on 22 Feb 2023, 08:28 AM

Hi Patgat,

I have tested your code and it works on my side. I wanted to ask you what is the format you are saving to? 

Patgat
Top achievements
Rank 2
Iron
Iron
Iron
commented on 22 Feb 2023, 12:23 PM

Hi Dimitar,

I am saving this in pdf format :

        Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider provider = new();
        RadFixedDocument PdfDocument = provider.ExportToFixedDocument(document);

Patgat
Top achievements
Rank 2
Iron
Iron
Iron
commented on 22 Feb 2023, 08:25 PM | edited

Hi again, 

effectively when saving as Docx it looks fine, while saving as Pdf has multiple incorrect rendering. See attached docs.

formatting is done with the following very standard code :


 IFormatProvider<RadFlowDocument> formatProvider = null;
        switch (selectedFromat)
        {
            case "Docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "Pdf":
                formatProvider = new PdfFormatProvider();
                break;
        }      
     
     using (var stream = dialog.OpenFile())
             {
                    formatProvider.Export(document, stream);
              }

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 24 Feb 2023, 08:28 AM

Hi Patgat,

Thank you for clarifying this. I was able to reproduce the case where the height is not respected. I have logged this issue on your behalf. You can track its progress, subscribe to status changes, and add your comment to it here: WordsProcessing: The Row Height is not respected when converting to pdf. I have updated your Telerik points for this report. 

I am afraid I cannot suggest a workaround for this.

The default paragraph spacing is affecting the alignment. You can set it to zero in order for this to work: 

 var p = cell.Blocks.AddParagraph();
 p.Spacing.SpacingAfter = 0;

 Run run = p.Inlines.AddRun("Test " + i);

Let me know if I can assist you further.

Regards,
Dimitar
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
General Discussions
Asked by
Patgat
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or