Hi,
I'm using PdfProcessing to create invoices from a template and I have included a header and a footer. Following my template, the body
is a Table with TableRow and TableCell. In each row I have a text, big or small, the lenght of the text influence the height of the cell. I don't have issues so far.
When my text
contains \n (carriage return) then I use this code to have my new line:
string[] lines = invoice.Libelle.Split('\n');
for (int l = 0; l < lines.Count(); l++)
{
editor.InsertText(lines[l]);
if (l + 1 < lines.Count())
{
editor.InsertBreak(BreakType.LineBreak);
}
}
But I get
an error when I try to generate invoice:
Message
d'erreur :
Width and Height must be non-negative.
Sur la méthode :
Void .ctor(Double, Double)
La trace de la pile :
at System.Windows.Size..ctor(Double width, Double height) at
Telerik.Windows.Documents.Fixed.Model.Editing.Tables.TableCell.get_DesiredSize()
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.TableCell.Measure(Size
availableSize) at
Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.CalculateRowHeights()
at Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.Measure(Size
availableSize) at
Telerik.Windows.Documents.Fixed.Model.Editing.Tables.Table.Draw(FixedContentEditor
editor, Rect boundingRect) at
Telerik.Windows.Documents.Fixed.Model.Editing.Flow.SectionInfo.InsertBlockElement(IBlockElement
blockElement) at
Telerik.Windows.Documents.Fixed.Model.Editing.RadFixedDocumentEditor.InsertBlock(IBlockElement
block) at
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.Export.PdfExporter.ExportSection(Section
section, RadFixedDocumentEditor editor) at
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.Export.PdfExporter.ExportDocument(RadFlowDocument
document, RadFixedDocumentEditor editor) at
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.Export.PdfExporter.Export() at
Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider.ExportToFixedDocument(RadFlowDocument
document) at Facturation_FacturePdf.<>c__DisplayClass3.b__2(FactureForPrintEntity
f) in
So, I find
out the issue. Contrary to this editor.InsertBreak(BreakType.LineBreak), with editor.InsertText(Environement.NewLine) I
don’t get an error but I have a big space between my two lines. So I remove the old code and I use this simple instruction :
editor.InsertText(invoice.Libelle.Replace("\n", " \n"));
I have a carriage return but I still have the same problem, a big space.
I have two questions:
1) What are the differences between these two instructions and why I get an error ?
2) Is it possible to remove or reduce the space between two lines using my last code?
3) There is maybe an other way?
The error
comes not always but only in specific invoices and depends on the text inside
my cell. I can post the code if you need it.
NB : In
addition, I use negative padding in my cells to have a good height, I don’t
know if this influence the error.
7 Answers, 1 is accepted
From the stack trace and your description, it seems like a table cell is left with a negative size. This could be caused by the indent you are setting. However, this is a blind guess and I will need to test the case before telling exactly what the reason for this behavior is.
If you are still experiencing this issue, I would like to ask you to share the code that is dealing with the document as well as a sample content that will help us reproduce the error you are getting on our side.
On a side note, I would like to mention that I deleted the other thread you posted as it was a duplicate of this one.
Regards,
Tanya
Progress Telerik

Hi,
Thank you for deleting the other thread (I made a mistake :s).
I'm posting the code, I tried to post my whole project but it is too heavy :s
I use a Button and when I click on, I call GeneratePDF() method.
Code generating the pdf :
private void GeneratePDF()
{
PdfFormatProvider provider = new PdfFormatProvider();
RadFlowDocument document1 = Template.DocumentFlowPDF(Page.ResolveUrl(Request.PhysicalApplicationPath));
byte[] renderedBytes = provider.Export(document1);
Response.Clear();
Response.ContentType = "application/pdf";
//Response.AddHeader("content-length", result.DocumentBytes.Length.ToString());
Response.AppendHeader("content-disposition", "attachment; filename=Invoice1.pdf");
Response.BinaryWrite(renderedBytes);
Response.Flush();
Response.End();
}
Code creating Pdf :
using System;
using System.Linq;
using System.Web.Script.Serialization;
using Telerik.Windows.Documents.Flow.Model.Styles;
using Telerik.Windows.Documents.Flow.Model;
using Telerik.Windows.Documents.Flow.Model.Editing;
using System.IO;
using Telerik.Windows.Documents.Flow.Model.Watermarks;
using Drawing = System.Drawing;
using System.Windows.Media;
using Telerik.Windows.Documents.Fixed.Model.Extensions;
using Telerik.Windows.Documents.Flow.Model.Shapes;
using Telerik.Windows.Documents.Spreadsheet.Model;
using WebGrease.Css.Extensions;
using System.Collections.Generic;
using System.Drawing.Imaging;
namespace PDF
{
public class Template
{
public class TypeTemplateFacture
{
public string Position { get; set; }
public string Size { get; set; }
public string Police { get; set; }
public string Couleur { get; set; }
public string Bold { get; set; }
}
public static Telerik.Windows.Documents.Flow.Model.RadFlowDocument DocumentFlowPDF(string path)
{
RadFlowDocument document = new RadFlowDocument();
Section sectionBody = new Section(document);
sectionBody.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(37, 0, 37, 0);
sectionBody.PageSize = new System.Windows.Size(816, 1200);
sectionBody.PageNumberingSettings.StartingPageNumber = 1;
document.Sections.Add(sectionBody);
document.HasDifferentEvenOddPageHeadersFooters = false;
Header defaultHeader = document.Sections.First().Headers.Add();
Footer defaultFooter = document.Sections.First().Footers.Add();
string watermark = "Pro format. En attente de validation. .";
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
if (!string.IsNullOrEmpty(watermark))
{
TextWatermarkSettings settings = new TextWatermarkSettings()
{
Angle = 55,
Width = 1060,
Height = 50,
Opacity = 1,
FontFamily = new System.Windows.Media.FontFamily("Helvetica"),
ForegroundColor = Color.FromArgb(128, 255, 0, 0),
Text = watermark,
};
settings.Text = watermark;
Watermark textWatermark = new Watermark(settings);
defaultHeader.Watermarks.Add(textWatermark);
}
//f.Langue = string.IsNullOrEmpty(f.Langue) ? "fr" : f.Langue;
//AppConstants.Langues langue = (AppConstants.Langues)Enum.Parse(typeof(AppConstants.Langues), f.Langue);
//FactureFields fields = new FactureFields(langue.ToString());
Color colorBorder = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#000000");
Color bckcolorHeader = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#BFBFBF");
var border = new Telerik.Windows.Documents.Flow.Model.Styles.Border(0.5, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(bckcolorHeader));
var borderTop = new Telerik.Windows.Documents.Flow.Model.Styles.Border(3, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(colorBorder));
/*********/
/*DETAILS*/
/*********/
int rowToAdd = 2;
int rowNb = 3 + rowToAdd;
int colNb = 4;
Table table = new Table(document);
// Content Table
document.StyleRepository.AddBuiltInStyle(BuiltInStyleNames.TableGridStyleId);
//table.StyleId = BuiltInStyleNames.TableGridStyleId;
string[] text = new string[]
{
"Centre de Compétences ST POP / ALCYOR Avril 2017\n\n\ndont Coeff. révision des prix 0.02704 = 1 500.71 eur\n\n\n\n\n\ndont CD2 remise sur volume = - 855.00 eur",
"Centre de Compétences ST POP / ALCYOR Avril 2017\n\n\ndont Coeff. révision des prix 0.02704 = 1 500.71 eur\n\n\n\n\n\ndont CD2 remise sur volume = - 855.00 eur",
"Centre de Compétences ST POP / ODEFEL Avril 2017\n\n"
};
//string[] text = new[] {""};
editor.CharacterFormatting.FontSize.LocalValue = 15;
editor.CharacterFormatting.BackgroundColor.LocalValue = (ThemableColor)Colors.Transparent;
for (int i = 0; i < rowNb; i++)
{
TableRow row = table.Rows.AddTableRow();
//row.Height = new TableRowHeight(Telerik.Windows.Documents.Flow.Model.Styles.HeightType.AtLeast, 50);
for (int j = 0; j < colNb; j++)
{
TableCell cell = row.Cells.AddTableCell();
cell.VerticalAlignment = Telerik.Windows.Documents.Flow.Model.Styles.VerticalAlignment.Center;
cell.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 0, -8);
cell.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border);
if (i == 0)
{
cell.Shading.BackgroundColor = new ThemableColor(bckcolorHeader);
cell.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border);
}
else if (i == 1)
{
var borderNone = new Telerik.Windows.Documents.Flow.Model.Styles.Border(0, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(Colors.White));
cell.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(borderNone);
cell.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 0, 0, -16);
break;
}
else if (i == 2)
{
cell.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border, borderTop, border, border);
}
Paragraph paragraphHeaderTable = cell.Blocks.AddParagraph();
paragraphHeaderTable.TextAlignment = Alignment.Center;
editor.CharacterFormatting.FontSize.LocalValue = 15;
switch (j)
{
case 0:
cell.PreferredWidth = new TableWidthUnit(435);
paragraphHeaderTable.TextAlignment = Alignment.Left;
editor.MoveToParagraphStart(paragraphHeaderTable);
cell.Padding = new Telerik.Windows.Documents.Primitives.Padding(5, 5, 0, -8);
cell.IgnoreCellMarkerInRowHeightCalculation = true;
if (i == 0)
editor.InsertText("Designation");
else
{
string[] lines = text[i - rowToAdd].Split('\n');
for (int l = 0; l < lines.Count(); l++)
{
editor.InsertText(lines[l]);
if (l + 1 < lines.Count())
{
editor.InsertBreak(BreakType.LineBreak);
}
}
}
break;
case 1:
cell.PreferredWidth = new TableWidthUnit(70);
editor.MoveToParagraphStart(paragraphHeaderTable);
if (i == 0)
editor.InsertText("Quantite");
else
{
editor.InsertText("0.00");
}
break;
case 2:
cell.PreferredWidth = new TableWidthUnit(120);
editor.MoveToParagraphStart(paragraphHeaderTable);
if (i == 0)
editor.InsertText("Price");
else
{
editor.InsertText("0,0.00");
}
break;
case 3:
cell.PreferredWidth = new TableWidthUnit(120);
paragraphHeaderTable.TextAlignment = Alignment.Right;
cell.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 10, -8);
editor.MoveToParagraphStart(paragraphHeaderTable);
if (i == 0)
editor.InsertText("MontantHT");
else
{
editor.InsertText("0,0.00");
}
break;
}
}
}
sectionBody.Blocks.Add(table);
// HEADER
Header(defaultHeader, document, path, colorBorder);
// FOOTER
Footer(defaultFooter, document, "");
/********/
/*TOTAUX*/
/********/
#region TOTAUX
Table tableTT = new Table(document);
tableTT.Rows.AddTableRow();
TableCell cell1 = tableTT.Rows[0].Cells.AddTableCell();
cell1.PreferredWidth = new TableWidthUnit(510);
cell1.IgnoreCellMarkerInRowHeightCalculation = true;
cell1.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 20, 0, 10);
TableCell cell2 = tableTT.Rows[0].Cells.AddTableCell();
cell2.PreferredWidth = new TableWidthUnit(240);
cell2.IgnoreCellMarkerInRowHeightCalculation = true;
cell2.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 20, 0, 10);
// Mentions
Table tableMentions = cell1.Blocks.AddTable();
tableMentions.Rows.AddTableRow();
//tableMentions.StyleId = BuiltInStyleNames.TableGridStyleId;
TableCell cellMentions = tableMentions.Rows[0].Cells.AddTableCell();
cellMentions.PreferredWidth = new TableWidthUnit(435);
cellMentions.Padding = new Telerik.Windows.Documents.Primitives.Padding(1, 0, 10, -14);
cellMentions.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border);
Paragraph paragraphMentions = cellMentions.Blocks.AddParagraph();
paragraphMentions.TextAlignment = Alignment.Left;
editor.MoveToParagraphStart(paragraphMentions);
string ibanToDisplay = "IBAN";
string swiftToDisplay = "SWIFT";
editor.InsertText("DestinatairePaiement");
editor.InsertBreak(BreakType.LineBreak);
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("CoordonneesBancaires");
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("IBAN");
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("BIC");
//Totaux
Table tableNumbers = cell2.Blocks.AddTable();
tableNumbers.Rows.AddTableRow();// Montant HT
tableNumbers.Rows.AddTableRow();// Montant TVA
tableNumbers.Rows.AddTableRow();// Montant TTC
tableNumbers.Rows.AddTableRow();// Style Empty Cell
//tableNumbers.StyleId = BuiltInStyleNames.TableGridStyleId;
// Row HT
TableCell cellNumbersCellHT1 = tableNumbers.Rows[0].Cells.AddTableCell();
TableCell cellNumbersCellHT2 = tableNumbers.Rows[0].Cells.AddTableCell();
cellNumbersCellHT1.PreferredWidth = cellNumbersCellHT2.PreferredWidth = new TableWidthUnit(120);
cellNumbersCellHT1.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumbersCellHT1.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 0, -8);
cellNumbersCellHT2.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumbersCellHT2.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 10, -8);
cellNumbersCellHT1.Borders = cellNumbersCellHT2.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border);
Paragraph paragraphNumbersHeaderHT1 = cellNumbersCellHT1.Blocks.AddParagraph();
paragraphNumbersHeaderHT1.TextAlignment = Alignment.Center;
editor.MoveToParagraphStart(paragraphNumbersHeaderHT1);
editor.InsertText("MontantHT");
Paragraph paragraphNumbersHeaderHT2 = cellNumbersCellHT2.Blocks.AddParagraph();
paragraphNumbersHeaderHT2.TextAlignment = Alignment.Right;
editor.MoveToParagraphStart(paragraphNumbersHeaderHT2);
/*if (f.TotalHTC.HasValue)
editor.InsertText(f.TotalHTC.Value.ToString("0,0.00"));
else*/
editor.InsertText(" 0 000");
// Row TVA
TableCell cellNumbersCellTVA1 = tableNumbers.Rows[1].Cells.AddTableCell();
TableCell cellNumbersCellTVA2 = tableNumbers.Rows[1].Cells.AddTableCell();
cellNumbersCellTVA1.PreferredWidth = cellNumbersCellTVA2.PreferredWidth = new TableWidthUnit(120);
cellNumbersCellTVA1.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumbersCellTVA1.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 0, -8);
cellNumbersCellTVA2.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumbersCellTVA2.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 15, 10, -11);
cellNumbersCellTVA1.Borders = cellNumbersCellTVA2.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border);
Paragraph paragraphNumbersHeaderTVA1 = cellNumbersCellTVA1.Blocks.AddParagraph();
paragraphNumbersHeaderTVA1.TextAlignment = Alignment.Center;
editor.MoveToParagraphStart(paragraphNumbersHeaderTVA1);
string tva = string.Empty;
//tva = f.TauxTVA.Value.ToString("0.00");
editor.InsertText("MontantTVA" + " ( 20 %)");
Paragraph paragraphNumbersHeaderTVA2 = cellNumbersCellTVA2.Blocks.AddParagraph();
paragraphNumbersHeaderTVA2.TextAlignment = Alignment.Right;
editor.MoveToParagraphStart(paragraphNumbersHeaderTVA2);
//if (f.TotalTTC.HasValue || f.TotalHTC.HasValue)
// editor.InsertText((f.TotalTTC.Value - f.TotalHTC.Value).ToString("0,0.00"));
//else
editor.InsertText(" ");
// Row TTC
TableCell cellNumbersCellTTC1 = tableNumbers.Rows[2].Cells.AddTableCell();
TableCell cellNumbersCellTTC2 = tableNumbers.Rows[2].Cells.AddTableCell();
cellNumbersCellTTC1.PreferredWidth = cellNumbersCellTTC2.PreferredWidth = new TableWidthUnit(120);
cellNumbersCellTTC1.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumbersCellTTC1.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 0, -8);
cellNumbersCellTTC2.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumbersCellTTC2.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 10, -8);
cellNumbersCellTTC1.Shading.BackgroundColor = cellNumbersCellTTC2.Shading.BackgroundColor = new ThemableColor(bckcolorHeader);
Paragraph paragraphNumbersHeaderTTC1 = cellNumbersCellTTC1.Blocks.AddParagraph();
paragraphNumbersHeaderTTC1.TextAlignment = Alignment.Center;
editor.MoveToParagraphStart(paragraphNumbersHeaderTTC1);
editor.InsertText("MontantTTC");
Paragraph paragraphNumbersHeaderTTC2 = cellNumbersCellTTC2.Blocks.AddParagraph();
paragraphNumbersHeaderTTC2.TextAlignment = Alignment.Right;
editor.MoveToParagraphStart(paragraphNumbersHeaderTTC2);
//if (f.TotalTTC.HasValue)
// editor.InsertText(f.TotalTTC.Value.ToString("0,0.00"));
//else
editor.InsertText(" ");
// Empty cell for style border
TableCell cellEmpty1 = tableNumbers.Rows[3].Cells.AddTableCell();
TableCell cellEmpty2 = tableNumbers.Rows[3].Cells.AddTableCell();
cellEmpty1.PreferredWidth = cellNumbersCellTTC2.PreferredWidth = new TableWidthUnit(120);
cellEmpty1.IgnoreCellMarkerInRowHeightCalculation = true;
cellEmpty1.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 0, 0, -18);
cellEmpty2.IgnoreCellMarkerInRowHeightCalculation = true;
cellEmpty2.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 0, 0, -18);
var borderWhite = new Telerik.Windows.Documents.Flow.Model.Styles.Border(0, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(Colors.White));
var borderBottom = new Telerik.Windows.Documents.Flow.Model.Styles.Border(3, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(colorBorder));
cellEmpty1.Borders = cellEmpty2.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(borderWhite, borderWhite, borderWhite, borderBottom);
#endregion
sectionBody.Blocks.Add(tableTT);
return document;
}
private static void Header(Header defaultHeader, RadFlowDocument document, string path, Color colorBorder)
{
//f.Langue = string.IsNullOrEmpty(f.Langue) ? "fr" : f.Langue;
//AppConstants.Langues langue = (AppConstants.Langues)Enum.Parse(typeof(AppConstants.Langues), f.Langue);
//FactureFields fields = new FactureFields(langue.ToString());
string date = "dd/MM/yyyy";
//Calcul du délai de règlement
DateTime datedecréation = new DateTime();
datedecréation = DateTime.Now;
DateTime datepaiement = new DateTime();
datepaiement = DateTime.Now;
string delaidepaiement = "10 jours";
string datePaiement = DateTime.Now.ToString("dd/MM/yyyy");
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
Table bodyTable = defaultHeader.Blocks.AddTable();
//bodyTable.StyleId = BuiltInStyleNames.TableGridStyleId;
TableRow row1 = bodyTable.Rows.AddTableRow();
TableCell cell1 = row1.Cells.AddTableCell();
cell1.PreferredWidth = new TableWidthUnit(350);
cell1.IgnoreCellMarkerInRowHeightCalculation = true;
cell1.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 0, 0, 0);
TableCell cell2 = row1.Cells.AddTableCell();
cell2.PreferredWidth = new TableWidthUnit(350);
cell2.IgnoreCellMarkerInRowHeightCalculation = true;
cell2.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, -0, 0, 0);
/*FACTURE*/
Paragraph paragraphFacture = cell2.Blocks.AddParagraph();
paragraphFacture.TextAlignment = Alignment.Right;
paragraphFacture.Indentation.RightIndent = 30;
editor.MoveToParagraphStart(paragraphFacture);
var codeFont = new ThemableFontFamily(new FontFamily("Calibri"));
editor.CharacterFormatting.FontFamily.LocalValue = codeFont;
editor.CharacterFormatting.FontSize.LocalValue = 35;
editor.InsertText("INVOICE").FontWeight = System.Windows.FontWeights.Bold;
/*ORIGINAL*/
Paragraph paragraphOriginal = cell2.Blocks.AddParagraph();
paragraphOriginal.TextAlignment = Alignment.Right;
paragraphOriginal.Indentation.RightIndent = 30;
editor.MoveToParagraphStart(paragraphOriginal);
editor.CharacterFormatting.FontFamily.LocalValue = codeFont;
editor.CharacterFormatting.FontSize.LocalValue = 17;
Color colorGray = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#808080");
editor.CharacterFormatting.ForegroundColor.LocalValue = new ThemableColor(colorGray);
editor.InsertText("ORIGINAL").FontWeight = System.Windows.FontWeights.Bold;
/*COORDONNEES CLIENTS*/
Paragraph paragraphAdressClient = cell2.Blocks.AddParagraph();
paragraphAdressClient.TextAlignment = Alignment.Left;
paragraphAdressClient.Indentation.LeftIndent = 100;
//paragraphAdressClient.Spacing.SpacingBefore = 30;
editor.InsertBreak(BreakType.LineBreak);
editor.InsertBreak(BreakType.LineBreak);
editor.MoveToParagraphStart(paragraphAdressClient);
editor.CharacterFormatting.FontFamily.LocalValue = codeFont;
editor.CharacterFormatting.FontSize.LocalValue = 14;
editor.CharacterFormatting.ForegroundColor.LocalValue = new ThemableColor(Colors.Black);
editor.InsertText("NomSociete");
editor.InsertBreak(BreakType.LineBreak);
// coordonnés de facturation
editor.InsertText("InterLocuteurFacturesRecues");
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("AdresseClient1");
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("AdresseClient2");
editor.InsertBreak(BreakType.LineBreak);
//editor.InsertText("AdresseClient3");
//editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("CodePostalClient CommuneClient");
editor.InsertBreak(BreakType.LineBreak);
/*COORDONNEES ENTITE*/
Paragraph paragraphEntite = cell1.Blocks.AddParagraph();
paragraphEntite.TextAlignment = Alignment.Left;
editor.CharacterFormatting.FontSize.LocalValue = 14;
editor.MoveToParagraphStart(paragraphEntite);
/*IMAGE*/
string imgPath = path + @"Images\alcyor.png";
cell1.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 132, 0, 0);
editor.InsertBreak(BreakType.LineBreak);
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("Entite.Libelle");
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("CoordEntite.Adresse1");
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("CoordEntite.CodePostal CoordEntite.Commune");
editor.InsertBreak(BreakType.LineBreak);
// Add a paragraph to the section
Paragraph paragraphEntiteData = cell1.Blocks.AddParagraph();
paragraphEntiteData.TextAlignment = Alignment.Left;
editor.MoveToParagraphStart(paragraphEntiteData);
editor.CharacterFormatting.FontFamily.LocalValue = codeFont;
editor.InsertText("N° SIRET : " + "CoordEntite.Siren");
/** Line TVA INTRACOMMUNAUTAIRE **/
TableRow rowTvaIntra = bodyTable.Rows.AddTableRow();
TableCell cellTvaIntraEntite = rowTvaIntra.Cells.AddTableCell();
cellTvaIntraEntite.PreferredWidth = new TableWidthUnit(350);
cellTvaIntraEntite.IgnoreCellMarkerInRowHeightCalculation = true;
cellTvaIntraEntite.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, -11, 0, -11);
Paragraph paragraphTvaIntraEntite = cellTvaIntraEntite.Blocks.AddParagraph();
paragraphTvaIntraEntite.TextAlignment = Alignment.Left;
editor.MoveToParagraphStart(paragraphTvaIntraEntite);
editor.InsertText("N° TVA Intracommunautaire : CoordEntite.TVAIntracom");
TableCell cellTvaIntraClient = rowTvaIntra.Cells.AddTableCell();
cellTvaIntraClient.PreferredWidth = new TableWidthUnit(350);
cellTvaIntraClient.IgnoreCellMarkerInRowHeightCalculation = true;
cellTvaIntraClient.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, -11, 0, -11);
Paragraph paragraphTvaIntraClient = cellTvaIntraClient.Blocks.AddParagraph();
paragraphTvaIntraClient.Indentation.LeftIndent = 100;
paragraphTvaIntraClient.TextAlignment = Alignment.Left;
editor.MoveToParagraphStart(paragraphTvaIntraClient);
editor.InsertText("N° TVA Intracommunautaire : TvaIntraClient");
/** Line INTERLOCUTEUR FACTURATION **/
TableRow rowInterFactu = bodyTable.Rows.AddTableRow();
TableCell cellInterFactu = rowInterFactu.Cells.AddTableCell();
cellInterFactu.PreferredWidth = new TableWidthUnit(750);
cellInterFactu.IgnoreCellMarkerInRowHeightCalculation = true;
cellInterFactu.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 0, 0);
cellInterFactu.ColumnSpan = 2;
Table tableInterlocuteur = cellInterFactu.Blocks.AddTable();
tableInterlocuteur.Rows.AddTableRow();
TableCell cellInterlocuteur = tableInterlocuteur.Rows[0].Cells.AddTableCell();
cellInterlocuteur.PreferredWidth = new TableWidthUnit(330);
cellInterlocuteur.IgnoreCellMarkerInRowHeightCalculation = true;
cellInterlocuteur.Padding = new Telerik.Windows.Documents.Primitives.Padding(5, 3, 10, -10);
var border = new Telerik.Windows.Documents.Flow.Model.Styles.Border(0.5, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(colorBorder));
cellInterlocuteur.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border);
Paragraph paragraphInterlocuteur = cellInterlocuteur.Blocks.AddParagraph();
paragraphInterlocuteur.TextAlignment = Alignment.Left;
editor.MoveToParagraphStart(paragraphInterlocuteur);
Run run = editor.InsertText("Interlocuteur facturation");
run.Underline.Pattern = Telerik.Windows.Documents.Flow.Model.Styles.UnderlinePattern.Single;
editor.InsertBreak(BreakType.LineBreak);
string interlocuteurMail = "";//f.Parametrage.Where(w => w.Cle == AppConstants.InterlocuteurFacturationMail).FirstOrDefault().Valeur;
string interlocuteurTel = "";//f.Parametrage.Where(w => w.Cle == AppConstants.InterlocuteurFacturationTel).FirstOrDefault().Valeur;
editor.InsertText(string.Format("Mail : {0}", !string.IsNullOrEmpty(interlocuteurMail) ? interlocuteurMail : ""));
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText(string.Format("Tél. : {0}", !string.IsNullOrEmpty(interlocuteurTel) ? interlocuteurTel : ""));
/* CASES */
// Première ligne
TableRow row2 = bodyTable.Rows.AddTableRow();
TableCell cell = row2.Cells.AddTableCell();
cell.PreferredWidth = new TableWidthUnit(750);
cell.IgnoreCellMarkerInRowHeightCalculation = true;
cell.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 0, 0);
cell.ColumnSpan = 2;
Table table = cell.Blocks.AddTable();
TableRow rowCase1 = table.Rows.AddTableRow();
rowCase1.Height = new TableRowHeight(Telerik.Windows.Documents.Flow.Model.Styles.HeightType.Auto, 100);
TableCell cellDate = rowCase1.Cells.AddTableCell();
TableCell cellNumFacture = rowCase1.Cells.AddTableCell();
TableCell cellNumContrat = rowCase1.Cells.AddTableCell();
TableCell cellNumLibFacture = rowCase1.Cells.AddTableCell();
cellDate.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumFacture.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumContrat.IgnoreCellMarkerInRowHeightCalculation = true;
cellNumLibFacture.IgnoreCellMarkerInRowHeightCalculation = true;
cellDate.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 10, 10);
cellNumFacture.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 10, 10);
cellNumContrat.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 10, 10);
cellNumLibFacture.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 0, 10);
CreateGrid(cellDate, editor, 3, 1, 95, "Date", date, colorBorder, null);
CreateGrid(cellNumFacture, editor, 3, 1, 170, "N° d'Avoir", "0000", colorBorder, null);
CreateGrid(cellNumContrat, editor, 3, 1, 170, "NumeroContrat", "000", colorBorder, null);
//if (!string.IsNullOrEmpty(f.Contrat.LibelleFacture))
CreateGrid(cellNumLibFacture, editor, 3, 1, 275, "InformationsFacture", "text", colorBorder, null);
// Deuxième ligne
TableRow row3 = bodyTable.Rows.AddTableRow();
TableCell cellCases2 = row3.Cells.AddTableCell();
cellCases2.PreferredWidth = new TableWidthUnit(750);
cellCases2.IgnoreCellMarkerInRowHeightCalculation = true;
cellCases2.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 0, 0, 0);
cellCases2.ColumnSpan = 2;
Table tableCases2 = cellCases2.Blocks.AddTable();
tableCases2.Rows.AddTableRow();
TableCell cellDelai = tableCases2.Rows[0].Cells.AddTableCell();
TableCell cellDateEcheance = tableCases2.Rows[0].Cells.AddTableCell();
TableCell cellInfoCommande = tableCases2.Rows[0].Cells.AddTableCell();
cellDelai.IgnoreCellMarkerInRowHeightCalculation = true;
cellDateEcheance.IgnoreCellMarkerInRowHeightCalculation = true;
cellInfoCommande.IgnoreCellMarkerInRowHeightCalculation = true;
cellDelai.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 10, 20);
cellDateEcheance.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 10, 20);
cellInfoCommande.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 10, 0, 20);
CreateGrid(cellDelai, editor, 3, 1, 275, "DelaiReglement", delaidepaiement, colorBorder, null);
CreateGrid(cellDateEcheance, editor, 3, 1, 170, "DateEcheance", datePaiement, colorBorder, null);
string dateCommande = DateTime.Now.ToString("dd/MM/yyyy");
CreateGrid(cellInfoCommande, editor, 3, 2, 80, "InformationsCommande", dateCommande, colorBorder, null, "BonCommandeNumero");
}
public const string optionnel = "";
private static void CreateGrid(TableCell cell1, RadFlowDocumentEditor editor, int nbRows, int nbColumns, int widthColumn, string header, string data, Color colorBorder, string fields, string data2 = optionnel)
{
Color bckcolorHeader = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#BFBFBF");
Color borderColorBottom = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#FFFFFF");
var border = new Telerik.Windows.Documents.Flow.Model.Styles.Border(0.5, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(bckcolorHeader));
var borderTop = new Telerik.Windows.Documents.Flow.Model.Styles.Border(3, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(colorBorder));
var borderBottom = new Telerik.Windows.Documents.Flow.Model.Styles.Border(3, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(borderColorBottom));
Table table = cell1.Blocks.AddTable();
nbRows = nbRows - 1;
for (int row = 0; row <= nbRows; row++)
{
TableRow tbrow = table.Rows.AddTableRow();
for (int column = 1; column <= nbColumns; column++)
{
if (header == "InformationsCommande" && row == 0 && column == 2)//Cas de fusion d'en-tête
break;
TableCell cell = tbrow.Cells.AddTableCell();
if (header != "InformationsCommande")
cell.PreferredWidth = new TableWidthUnit(widthColumn);
else
{
if (column == 1)
cell.PreferredWidth = new TableWidthUnit(widthColumn);
else
cell.PreferredWidth = new TableWidthUnit(275 - widthColumn);
}
cell.IgnoreCellMarkerInRowHeightCalculation = true;
cell.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 3, 0, -10);
if (row == 1)
cell.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 0, 0, -27);
if (row == 2)
cell.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border, borderTop, border, border);
if (header == "InformationsCommande" && row == 0 && column == 1)//Cas de fusion d'en-tête
cell.ColumnSpan = 2;
Paragraph paragraph = cell.Blocks.AddParagraph();
paragraph.TextAlignment = Alignment.Center;
editor.MoveToParagraphStart(paragraph);
editor.CharacterFormatting.FontSize.LocalValue = 15;
editor.CharacterFormatting.BackgroundColor.LocalValue = (ThemableColor)Colors.Transparent;
if (!string.IsNullOrEmpty(data2) && column == 2)
{
editor.CharacterFormatting.FontSize.LocalValue = 13;
if (row == 2)
cell.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 0, -8);
}
if (row == 0)
{
cell.Shading.BackgroundColor = new ThemableColor(bckcolorHeader);
cell.Borders = new Telerik.Windows.Documents.Flow.Model.Styles.TableCellBorders(border, border, border, borderBottom);
editor.InsertText(header);
}
else if (row == 2)
{
if (column == 1)
editor.InsertText(data);
else if (column == 2)
editor.InsertText(data2);
}
}
}
}
private static void Footer(Footer defaultFooter, RadFlowDocument document, string fields)
{
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);
Table tableFooter = defaultFooter.Blocks.AddTable();
//tableFooter.StyleId = BuiltInStyleNames.TableGridStyleId;
Color colorGray = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#90A6A6");
TableRow row1 = tableFooter.Rows.AddTableRow();
TableCell cell1 = row1.Cells.AddTableCell();
cell1.PreferredWidth = new TableWidthUnit(200);
cell1.IgnoreCellMarkerInRowHeightCalculation = true;
cell1.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 0, 0);
//cell1.VerticalAlignment = VerticalAlignment.Bottom;
TableCell cell2 = row1.Cells.AddTableCell();
cell2.PreferredWidth = new TableWidthUnit(400);
cell2.IgnoreCellMarkerInRowHeightCalculation = true;
cell2.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 0, 0);
cell2.ColumnSpan = 2;
//cell2.VerticalAlignment = VerticalAlignment.Bottom;
// OBLIGATION LEGALS
Paragraph footerParagraphLegal = cell1.Blocks.AddParagraph();
footerParagraphLegal.TextAlignment = Alignment.Left;
//footerParagraphLegal.Spacing.SpacingBefore = 30;
editor.MoveToParagraphStart(footerParagraphLegal);
editor.CharacterFormatting.FontSize.LocalValue = 10;
editor.CharacterFormatting.ForegroundColor.LocalValue = new ThemableColor(colorGray);
editor.InsertBreak(BreakType.LineBreak);
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("En application de la loi, cette facture est payable à l’échéance indiquée ci-dessus, sans escompte pour paiement anticipé. La société acquitte la TVA sur les encaissements.");
editor.InsertBreak(BreakType.LineBreak);
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("Pénalités de retard conformément au code du commerce Article L 441-6 Trois fois le taux d’intérêt légal.");
//ParametrageEntity p = f.Parametrage.Where(w => w.Cle == AppConstants.TemplateCommentaire.ToString()).FirstOrDefault();
//if (p != null && !string.IsNullOrEmpty(p.Valeur))
//{
// string[] linesMentions = f.Mentions.Split('\n');
// linesMentions.ForEach(t =>
// {
// Paragraph footerParagraphCommentaire = cell2.Blocks.AddParagraph();
// footerParagraphCommentaire.TextAlignment = Alignment.Left;
// JavaScriptSerializer jsValue = new JavaScriptSerializer();
// var val = jsValue.Deserialize(p.Valeur, typeof(TypeTemplateFacture)) as TypeTemplateFacture;
// footerParagraphCommentaire.Indentation.LeftIndent = string.IsNullOrEmpty(val.Position) ? 150 : int.Parse(val.Position);
// editor.MoveToParagraphStart(footerParagraphCommentaire);
// editor.InsertText(f.Mentions);
// editor.CharacterFormatting.FontSize.LocalValue = string.IsNullOrEmpty(val.Size) ? 11 : int.Parse(val.Size);
// editor.CharacterFormatting.FontFamily.LocalValue = new ThemableFontFamily(new FontFamily(string.IsNullOrEmpty(val.Police) ? "Calibri" : val.Police));
// editor.CharacterFormatting.FontWeight.LocalValue = string.IsNullOrEmpty(val.Bold) ? System.Windows.FontWeights.Normal : System.Windows.FontWeights.Bold;
// Color color = (Color)System.Windows.Media.ColorConverter.ConvertFromString(string.IsNullOrEmpty(val.Couleur) ? "#000000" : val.Couleur);
// editor.CharacterFormatting.ForegroundColor.LocalValue = new ThemableColor(color);
// });
//}
//else
//{
string Mentions = "* Dont 7 560.00 € TTC à ODEFEL sous traitant de 1er rang (copie fact. en PJ)\n* Dont : 74 720.17 € TTC à SOLUTEC sous traitant de 1er rang (copie fact. en PJ)\n* Dont : 59 838.72 € TTC à mon entreprise ALCYOR";// "* Dont 7 560.00 € TTC à ODEFEL sous traitant de 1er rang (copie fact. en PJ)\n* Dont : 74 720.17 € TTC à SOLUTEC sous traitant de 1er rang (copie fact. en PJ)\n* Dont : 59 838.72 € TTC à mon entreprise ALCYOR";
string[] linesMentions = Mentions.Split('\n');
linesMentions.ForEach(t =>
{
Paragraph footerParagraphCommentaire = cell2.Blocks.AddParagraph();
footerParagraphCommentaire.TextAlignment = Alignment.Left;
footerParagraphCommentaire.Indentation.LeftIndent = 150;
editor.MoveToParagraphStart(footerParagraphCommentaire);
editor.CharacterFormatting.FontFamily.LocalValue = new ThemableFontFamily(new FontFamily("Calibri"));
editor.CharacterFormatting.FontSize.LocalValue = 11;
editor.CharacterFormatting.FontWeight.LocalValue = System.Windows.FontWeights.Normal;
editor.CharacterFormatting.ForegroundColor.LocalValue = new ThemableColor(Colors.Black);
editor.InsertText(t);
});
//}
TableRow row2 = tableFooter.Rows.AddTableRow();
TableCell cellLegal = row2.Cells.AddTableCell();
cellLegal.PreferredWidth = new TableWidthUnit(200);
cellLegal.IgnoreCellMarkerInRowHeightCalculation = true;
cellLegal.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 0, 0, -28);
TableCell cellCoord = row2.Cells.AddTableCell();
cellCoord.PreferredWidth = new TableWidthUnit(350);
cellCoord.IgnoreCellMarkerInRowHeightCalculation = true;
cellCoord.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 5, 0, -28);
TableCell cellNbrPage = row2.Cells.AddTableCell();
cellNbrPage.PreferredWidth = new TableWidthUnit(236);
cellNbrPage.IgnoreCellMarkerInRowHeightCalculation = true;
cellNbrPage.Padding = new Telerik.Windows.Documents.Primitives.Padding(0, 0, 0, -28);
// INDEMNITES
Paragraph footerParagraphIndemnite = cellLegal.Blocks.AddParagraph();
footerParagraphIndemnite.TextAlignment = Alignment.Left;
editor.MoveToParagraphStart(footerParagraphIndemnite);
editor.CharacterFormatting.FontSize.LocalValue = 9;
editor.CharacterFormatting.FontWeight.LocalValue = System.Windows.FontWeights.Normal;
editor.CharacterFormatting.ForegroundColor.LocalValue = new ThemableColor(colorGray);
editor.InsertText("Indemnité forfaitaire pour frais de recouvrement : 40 euros (fixé par le décret n°2012-115 du 2 octobre 2012).");
// COORDONNEES
Paragraph footerParagraph = cellCoord.Blocks.AddParagraph();
footerParagraph.TextAlignment = Alignment.Center;
editor.MoveToParagraphStart(footerParagraph);
editor.CharacterFormatting.FontSize.LocalValue = 8;
editor.CharacterFormatting.ForegroundColor.LocalValue = new ThemableColor(Colors.Black);
editor.InsertText("Entite.Libelle").FontWeight = System.Windows.FontWeights.Bold;
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText(string.Format("{0} - {1} {2} - Tel {3}{4} - {5}", "Adresse1", "CodePostal", "Commune", "NoTelephone", " Fax ", "SiteWeb"));
editor.InsertBreak(BreakType.LineBreak);
editor.InsertText("RCS ");
// NBR PAGES
Paragraph footerParagraphNumber = cellNbrPage.Blocks.AddParagraph();
footerParagraphNumber.TextAlignment = Alignment.Right;
editor.MoveToParagraphStart(footerParagraphNumber);
editor.CharacterFormatting.FontSize.LocalValue = 12;
editor.CharacterFormatting.ForegroundColor.LocalValue = new ThemableColor(Colors.Black);
editor.CharacterFormatting.FontWeight.LocalValue = System.Windows.FontWeights.Normal;
editor.InsertText("Page ");
editor.InsertField("PAGE", null);
//decimal numPageTT = Math.Round((decimal.Parse(heghtLine.ToString()) / 16), 0);
editor.InsertText("/");
editor.InsertField("NUMPAGES", null);
//defaultFooter.Document.
}
public static ImageFormat GetImageFormatByExtension(string extension)
{
ImageFormat item = null;
switch (extension.ToLower())
{
case ".bmp":
item = ImageFormat.Bmp;
break;
case ".gif":
item = ImageFormat.Gif;
break;
case ".png":
item = ImageFormat.Png;
break;
case ".tiff":
item = ImageFormat.Tiff;
break;
default:
item = ImageFormat.Jpeg;
break;
}
return item;
}
}
}
I have investigated your problem and as Tanya mentioned the problem is related to negative value for the table and table cell paddings. Once you fix those negative value the document should be exported as expected.
Regards,
Mihail
Progress Telerik

Hi Mihail's,
I removed the negative values that I had in my table cell paddings and there is no bug anymore. Thanks for that.
But I still have a problem because now I don't have a good template that I wanted :s
So I tried to insert a specific height on my rows but it does'nt work. I'm using this code below but that not work...
myrow.Height = new TableRowHeight(HeightType.Exact, myvalue);
There is a specific place to input this code?
Thank you for your helping.
Regards
Damien

Hi,
I made different research on this issue and I didn't find anything. So I tried to export to PDF a simple template with one Table, TableRow and TableCell (using a specific height on the TableRow) but that not change at all.
The Height property of TableRow is not respected when exporting with PdfFormatProvider. Is it a issue of RadFlowDocument library?
Thank you for your reply !
Damien
You are correct, the Words processing does not export the Height of the Table Row to PDF format. We already have this logged into our feedback portal as a feature request. Here is a link if you would like to follow the item and receive status updates: Add support for of a table row when exporting to PDF.
I am afraid that for this particular case there is no workaround.
Regards,
Mihail
Progress Telerik