Hi,
How can i add hyperlink with underline specific marked string(www.google.com) not for whole string using DocumentBuilder in aspose word, Pdf. And also we attached the screen shot, sample docments and sample project for your review.
We are using the following code for create the aspose documents.
protected void btn_Click(object sender, EventArgs e)
{
string File = “D:\Test-Word1.Docx”;
Aspose.Words.Document doc = new Aspose.Words.Document(File);
Aspose.Words.Tables.Table tb = (from Aspose.Words.Tables.Table table in doc.GetChildNodes(Aspose.Words.NodeType.Table, true) where table.FirstRow != null && table.FirstRow.Cells.Count > 0 let cell = table.FirstRow.Cells[0] where cell.ToString(Aspose.Words.SaveFormat.Text).Trim().Contains("Sample Test Table") select table).FirstOrDefault();
Dictionary<int, int> columnAlignment = new Dictionary<int, int>();
columnAlignment.Add(2, 2);
List<string> SampleColumn = new List<string>();
SampleColumn.Add("Test1");
SampleColumn.Add("See the page www.google.com");
PopulateTableWithSamples(doc, tb, SampleColumn, columnAlignment);
System.IO.MemoryStream pdfOoutStream = new System.IO.MemoryStream();
doc.Save(pdfOoutStream, Aspose.Words.SaveFormat.Pdf);
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(pdfOoutStream);
byte[] docBytes = null;
pdfOoutStream = new System.IO.MemoryStream();
pdfDocument.Save(pdfOoutStream);
docBytes = pdfOoutStream.ToArray();
FileStream output = new FileStream("D:\\Test-Pdf.Pdf", FileMode.Create,
FileAccess.Write);
// Write byte array contents in the output file stream
output.Write(docBytes, 0, docBytes.Length);
// Close output file
output.Close();
}
private void PopulateTableWithSamples(Aspose.Words.Document doc, Aspose.Words.Tables.Table table, List<string> services, Dictionary<int, int> alignment)
{
Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc);
string builderFontName = "Arial";
double builderFontSize = 10.0;
if (table != null && table.HasChildNodes)
{
foreach (Row row in table.Rows)
{
if (!row.IsFirstRow)
{
for (int i = 0; i < row.Cells.Count; i++)
{
row.Cells[i].RemoveAllChildren();
Paragraph paragraph = new Paragraph(doc);
row.Cells[i].AppendChild(paragraph);
}
int index = 0;
foreach (KeyValuePair<int, int> pair in alignment) //logic to place a service to the corresponding column
{
builder.MoveTo(row.Cells[pair.Key].FirstParagraph);
if (!string.IsNullOrEmpty(builderFontName))
{
builder.Font.Name = builderFontName;
builder.Font.Size = builderFontSize;
builder.ParagraphFormat.LineSpacing = 11;
}
builder.ListFormat.ApplyBulletDefault();
builder.ListFormat.List = doc.Lists.Add(Aspose.Words.Lists.ListTemplate.BulletDisk);
for (int j = index; j < pair.Value + index; j++)
{
if (services[j] != null)
{
builder.Writeln(services[j]);
}
}
index += pair.Value;
}
//remove empty paragraph at the end of each cell
for (int i = 0; i < row.Cells.Count; i++)
{
Node[] paragraphs = row.Cells[i].GetChildNodes(NodeType.Paragraph, true).ToArray();
foreach (Node paragraph in paragraphs)
{
if (string.IsNullOrEmpty(paragraph.ToString(SaveFormat.Text).Trim()))
paragraph.Remove();
}
}
row.RowFormat.TopPadding = 3;
}
}
}
}