Hi comunidadmexi...,
There is no property to set the justify alignment.
You need to add the html content inside the a span with CSS text-justify Property.
Refer below example.
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string dest;
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("contents")
});
dt.Rows.Add("<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>");
string filename = @"C:\Management_" + Guid.NewGuid() + ".pdf";
PdfWriter writer = new PdfWriter(filename);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf, PageSize.A4, false);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
// Adding span with CSS text-justify Property to the html.
List<IElement> lst = HtmlConverter.ConvertToElements(string.Format("<span style='text-align: justify;text-justify: inter-word;'>{0}</span>", dt.Rows[i]["contents"].ToString())).ToList();
for (int j = 0; j < lst.Count; j++)
{
IBlockElement element = (IBlockElement)lst[j];
//element.SetProperty(Property.LEADING, new Leading(Leading.MULTIPLIED, -1f));
document.Add(element);
}
}
dest = filename.ToString();
}
else
{
Console.WriteLine("No rows found.");
}
document.Close();
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + dest);
Response.TransmitFile(dest);
Response.End();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) handles Me.Load
If Not Me.IsPostBack Then
Dim dest As String
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn() {New DataColumn("contents")})
dt.Rows.Add("<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>")
Dim filename As String = "C:\Management_" & Guid.NewGuid() & ".pdf"
Dim writer As PdfWriter = New PdfWriter(filename)
Dim pdf As PdfDocument = New PdfDocument(writer)
Dim document As Document = New Document(pdf, PageSize.A4, False)
If dt.Rows.Count > 0 Then
For i As Integer = 0 To dt.Rows.Count - 1
Dim lst As List(Of IElement) = HtmlConverter.ConvertToElements(String.Format("<span style='text-align: justify;text-justify: inter-word;'>{0}</span>", dt.Rows(i)("contents").ToString())).ToList()
For j As Integer = 0 To lst.Count - 1
Dim element As IBlockElement = CType(lst(j), IBlockElement)
document.Add(element)
Next
Next
dest = filename.ToString()
Else
Console.WriteLine("No rows found.")
End If
document.Close()
Response.Clear()
Response.ContentType = "application/pdf"
Response.AppendHeader("Content-Disposition", "attachment; filename=" & dest)
Response.TransmitFile(dest)
Response.[End]()
End If
End Sub
Screenshot