We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Alternative to WrapLines

Hi,


In process to move from Aspose.Pdf.Generator to Aspose.Pdf I need to Move from Text to TextFragment. I am not sure how i can wrap lines in TextFragment.

Please share some example of Aspose.Pdf.Document for wrapped lines.

Regards,
Sandeep

Hi Sandeep,


Thanks for your inquiry. We will appreciate it if you please share your sample code using WrapLines. We will look into it and will guide you for solution or workaround.

We are sorry for the inconvenience caused.

Best Regards,

Hi,


I am using following code snippet and it is working fine for me. Now as I need to use Document object instead of Pdf object i need to use TextFragment class.

var title = new Text(section, text)
{
PositioningType = PositioningType.ParagraphRelative,
ReferenceParagraphID = root.ID,

Left = section.PageInfo.Margin.Left.ToFloat(),
Top = section.PageInfo.Margin.Top.ToFloat(),
TextInfo = MytTextStyle,
WrapLines = 1,
};
section.Paragraphs.Add(title);

Let me know how we can achieve same using TextFragment.

Regards,
Sandeep

Hi Sandeep,


Thanks you very much for sharing more information about the requirement. We have logged an enhancement ticket PDFNEWNET-37507 for implementing alternative of WrapLines in new Generator. We will keep you updated about the issue resolution progress via this forum thread.

We are sorry for the inconvenience caused.

Best Regards,

Any update on this? Is there any workaround for this?

Hi Sandeep,


Thanks for your inquiry. I am afraid it is not resolved yet, our product team has planned its investigation in coming month. We will let you know as soon as we made some significant progress towards issue resolution.

Thanks for your patience and cooperation.

Best Regards,

At least let me know some workaround to achieve this.

Hi Sandeep,


We have investigated the issue. We have plan to improve the TextParagraph to support WrapLines feature. However as workaround you can consider following code. TextParagraph has some functions to get the same behavior as WrapLines produce.



//The example demonstrates how to
create text paragraph object and append it to the Pdf page
<o:p></o:p>

Document doc = new Document();

Page page = doc.Pages.Add();

// create text paragraph

TextParagraph paragraph = new TextParagraph();

// set the paragraph rectangle

double left = page.PageInfo.Margin.Left;

double right = page.PageInfo.Width - page.PageInfo.Margin.Right;

double top = page.PageInfo.Height - page.PageInfo.Margin.Top;

paragraph.Rectangle = new Aspose.Pdf.Rectangle(left, top - 50, right, top);

// set word wrapping options

paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.ByWords;

paragraph.VerticalAlignment = VerticalAlignment.Top;

// append text fragment(s)

TextFragment textFragment = new TextFragment("In process to move from Aspose.Pdf.Generator to Aspose.Pdf I need to Move from Text to TextFragment. I am not sure how i can wrap lines in TextFragment. I am not sure how i can wrap lines in TextFragment");

paragraph.AppendLine(textFragment);

// append the paragraph to the Pdf page with the TextBuilder

TextBuilder textBuilder = new TextBuilder(page);

textBuilder.AppendParagraph(paragraph);

// save Pdf document

doc.Save(myDir + "wrapline_DOM.pdf");

If you change FormattingOptions.WrapMode, you can make single line paragraph. It produces the same behavior as 'WrapLines = 1'. See resultant wrapline_DOM_1.pdf.

paragraph.FormattingOptions.WrapMode = TextFormattingOptions.WordWrapMode.NoWrap;

</o:p>

<o:p> </o:p>

<o:p></o:p>

But if you need several lines, you must change Rectangle property to trim unnecessary lines. For example if rectangle height will be near double font size it saves two lines, It produces the same behavior as ‘WrapLines = 2’.

paragraph.Rectangle = new
Aspose.Pdf.Rectangle(left, top - 20, right,
top);<o:p></o:p>

Best Regards,

Hi,


I was using the text which i have shown in my earlier post for adding it to table cell. Now question remains how i can say WrapLine=1 and add that text to my table cell. Please provide code snippet for achieving the same.

Regards,
Sandeep

Hi Sandeep,


Thanks for your feedback. We have shared your concern with the product team for support of WrapLine property in TextFragment and also raised the issue priority in our issue tracking system. We will keep you updated about the issue resolution progress.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-37507) have been fixed in Aspose.Pdf for .NET 16.10.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Sandeep,


Thanks for your patience. In reference to above fix, you can use WrapLines property of TextFragment object as following. Hopefully it will help you to accomplish the task.

//WrapLines in plain text:<o:p></o:p>

string outFile = myDir+"37507.pdf";

Document doc1 = new Document();

Page page1 = doc1.Pages.Add();

TextFragment title = new TextFragment("In process to move from Aspose.Pdf.Generator to Aspose.Pdf I need to Move from Text to TextFragment. I am not sure how i can wrap lines in TextFragment. I am not sure how i can wrap lines in TextFragment");

title.WrapLinesCount = 1;

//title.WrapLinesCount = 2;

page1.Paragraphs.Add(title);

doc1.Save(outFile);

//WrapLines in Table:

outFile = myDir+"37507_3.pdf";

// Load source PDF document

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();

// Add page

Page page = doc.Pages.Add();

// Initializes a new instance of the Table

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

// Set the table border color as LightGray

table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// Set the border for table cells

table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// Create a loop to add 10 rows

for (int row_count = 1; row_count < 10; row_count++)

{ // Add row to table

Aspose.Pdf.Row row = table.Rows.Add();

// Add table cells

TextFragment fragment = new TextFragment("Very long text in column (" + row_count + ", 1)");

fragment.WrapLinesCount = 1;

Aspose.Pdf.Cell cell = new Aspose.Pdf.Cell();

cell.Paragraphs.Add(fragment);

row.Cells.Add(cell);

row.Cells.Add("Column (" + row_count + ", 2)");

row.Cells.Add("Column (" + row_count + ", 3)"); }

// Add table object to first page of input document

page.Paragraphs.Add(table);

doc.Save(outFile);

Best Regards,

Hi,

I am trying to convert some really old code from the Generator.Text to Text.TextFragment

The code was this:
Dim loText As New Pdf.Generator.Text(loSt.ReadToEnd()) With {.WrapLines = True}

The code is now this:
Dim loText As New Pdf.Text.TextFragment(loSt.ReadToEnd())

But I am unclear how the WrapLinesCount works as it is no longer a boolean. The above example has =1 (and =2 commented out) but no indication how to just let it wrap as required.

I don’t know how many I want. I just want it to be wrapping. Do I need to set anything?

Thanks, Julie

@t1jsw

Are you adding text inside table cells? Would you kindly share the complete code snippet that you are using to add text along with an expected output PDF. Please share the complete text as well. We will test the scenario in our environment and address it accordingly.