We have a scenario to keep the shapes and text in the same and we are able to achieve the requirement by keep the WrapType to None for the shapes.
But it does not work for the shapes and Tables. Let us know if there is a way to keep the shapes and Tables in the same line.
Word file is generated and converted to PDF at the end. The generated PDF is shown here.
The sample code used to achieve the current behavior :
Shape shape = this.Builder.InsertImage("<Path of the icon .PNG>");
shape.CustomNodeId = 9999;
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.LeftMargin;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Line;
shape.Width = 10;
shape.Height = 10;
shape.Left = 5;
this.Builder.ParagraphFormat.ClearFormatting();
this.Builder.ParagraphFormat.StyleName = this.PdfStyles.Fetch(PdfStylingAttributes.CautionOrWarning).Name;
Table cautionWarningTable = this.Builder.StartTable();
#region First Row "Caution Title"
this.Builder.InsertCell();
this.Builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
this.Builder.CellFormat.SetPaddings(3.75, 3.75, 3.75, 3.75); // 5px is set in points
this.Builder.Font.Underline = Underline.Single;
this.Builder.Font.DoubleStrikeThrough = isStrikedOut;
this.Builder.Font.AllCaps = false;
this.Builder.Write("CAUTION");
this.Builder.EndRow();
#endregion
#region "Caution Description - Text or Table"
this.Builder.InsertCell();
this.Builder.Font.ClearFormatting();
this.Builder.Font.DoubleStrikeThrough = isStrikedOut;
this.Builder.CellFormat.SetPaddings(3.75, 3.75, 3.75, 3.75); // 5px is set in points
this.Builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
string content = "THIS IS CAUTION TEXT";
this.Builder.InsertHtml(content, true);
this.Builder.EndRow();
#endregion
cautionWarningTable = this.Builder.EndTable();
cautionWarningTable.AllowAutoFit = false;
cautionWarningTable.PreferredWidth = PreferredWidth.FromPercent(80);
cautionWarningTable.ClearBorders();
cautionWarningTable.SetShading(TextureIndex.TextureNone, paraBackground, paraBackground);
cautionWarningTable.StyleName = itemType == PdfConstants.Warning ? this.WarningTableStyle.Name : this.CautionTableStyle.Name;
this.Builder.CellFormat.ClearFormatting();
this.Builder.ParagraphFormat.ClearFormatting();
this.Builder.Font.ClearFormatting();
@MonishaRaja
To keep shapes and tables on the same line without overlapping in your document, you can adjust the wrapping type and positioning of the shapes relative to the table. Here are some suggestions to achieve this:
-
Wrap Type: Ensure that the WrapType
for the shapes is set to WrapType.None
. This will prevent the shape from wrapping around the text or table, allowing for better control over positioning.
-
Positioning: You can set the RelativeHorizontalPosition
and RelativeVerticalPosition
properties of the shape to position it accurately in relation to the table. For example, you can set the shape to be positioned relative to the left margin or the line, depending on your layout needs.
-
Adjusting Table Width: If the table is too wide, it may push the shape down to the next line. You can adjust the table’s width or the shape’s position to ensure they align properly.
Here is a modified version of your code that incorporates these suggestions:
Shape shape = this.Builder.InsertImage("<Path of the icon .PNG>");
shape.CustomNodeId = 9999;
shape.WrapType = WrapType.None; // Ensure no wrapping
shape.BehindText = true; // Optional, depending on your layout
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.LeftMargin; // Adjust as needed
shape.RelativeVerticalPosition = RelativeVerticalPosition.Line; // Adjust as needed
shape.Width = 10;
shape.Height = 10;
shape.Left = 5; // Adjust position as needed
this.Builder.ParagraphFormat.ClearFormatting();
this.Builder.ParagraphFormat.StyleName = this.PdfStyles.Fetch(PdfStylingAttributes.CautionOrWarning).Name;
Table cautionWarningTable = this.Builder.StartTable();
// First Row "Caution Title"
this.Builder.InsertCell();
this.Builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
this.Builder.CellFormat.SetPaddings(3.75, 3.75, 3.75, 3.75);
this.Builder.Font.Underline = Underline.Single;
this.Builder.Font.DoubleStrikeThrough = isStrikedOut;
this.Builder.Font.AllCaps = false;
this.Builder.Write("CAUTION");
this.Builder.EndRow();
// Caution Description - Text or Table
this.Builder.InsertCell();
this.Builder.Font.ClearFormatting();
this.Builder.Font.DoubleStrikeThrough = isStrikedOut;
this.Builder.CellFormat.SetPaddings(3.75, 3.75, 3.75, 3.75);
this.Builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
string content = "THIS IS CAUTION TEXT";
this.Builder.InsertHtml(content, true);
this.Builder.EndRow();
cautionWarningTable = this.Builder.EndTable();
cautionWarningTable.AllowAutoFit = false;
cautionWarningTable.PreferredWidth = PreferredWidth.FromPercent(80);
cautionWarningTable.ClearBorders();
cautionWarningTable.SetShading(TextureIndex.TextureNone, paraBackground, paraBackground);
cautionWarningTable.StyleName = itemType == PdfConstants.Warning ? this.WarningTableStyle.Name : this.CautionTableStyle.Name;
this.Builder.CellFormat.ClearFormatting();
this.Builder.ParagraphFormat.ClearFormatting();
this.Builder.Font.ClearFormatting();
By following these adjustments, you should be able to align the shapes and tables on the same line effectively. If you continue to experience issues, consider checking the overall layout and margins of your document to ensure there is enough space for both elements.
@MonishaRaja Could you please create the expected output in MS Word and attach it here for our reference? We will check the document and provide you more information.
Expected Output.docx (33.8 KB)
Attached the required output as word file.
We trying to achieve the shape to be the aligned to the table in the same line.
We are using the same shape options you have suggested and reduced the table width to 50%, still we see that table is moved to the next line.
Attaching the expected output as Image from MS Word File
Expected Output Word as Image.png (7.0 KB)
@MonishaRaja The shape is inserted in the paragraph before the table, so it is expected it is a little upper than the table. You can try shifting the shape down. For example, try modifying the code like this:
Shape shape = builder.InsertImage(@"C:\temp\test.png");
shape.CustomNodeId = 9999;
shape.WrapType = WrapType.None;
shape.BehindText = true;
shape.RelativeHorizontalPosition = RelativeHorizontalPosition.LeftMargin;
shape.RelativeVerticalPosition = RelativeVerticalPosition.Line;
shape.Width = 10;
shape.Height = 10;
shape.Left = 5;
// Shift the shape down.
shape.Top += builder.CurrentParagraph.ParagraphBreakFont.Size + builder.CurrentParagraph.ParagraphFormat.SpaceAfter;