我需要在我生成的PDF文件中写一个段落。所述段落由红色的粗体第一个单词组成,有些"常规"之后的红色文字,然后是一个链接(蓝色),一些更常规的红色文本,最后是另一个链接(也是蓝色)。我想我可以使用Chunks来做到这一点,像这样(伪代码):
Chunk boldChunk = new Chunk("Important:"); // add font via GetFont?
boldChunk.SetBold();
boldChunk.SetColor(red);
Chunk beginChunk = new Chunk("Form must be filled out in ");
beginChunk.SetColor(red);
Chunk underlinedAdobeReader = new Chunk("Adobe Reader");
underlinedAdobeReader.SetUnderline(0.5f, -1.5f);
underlinedAdobeReader.SetColor(blue);
underlinedAdobeReader.SetHRef("http://www.adobe.com");
Chunk middleChunk = new Chunk("or Acrobat Professional
8.1 or above. To save completed forms, Acrobat Professional is required. For
technical and accessibility assistance, contact the ");
middleChunk.SetColor(red);
Chunk underlinedJefe = new Chunk("Chief Platypus");
underlinedJefe.SetUnderline(0.5f, -1.5f);
underlinedJefe.SetColor(blue);
underlinedJefe.SetHref("http://twaincentral.azurewebsites.net/");
doc.Add(boldChunk);
doc.Add(beginChunk);
doc.Add(underlinedJefe);
doc.Add(middleChunk);
doc.Add(underlinedCampusOffice);
....但这似乎是边缘的古怪;有没有办法可以切断追逐"并为文档分配一些HTML,如:
String composite = "<strong>Important:</strong> Form must be filled out in <a href="http://www.adobe.com" target="_blank">Adobe Reader</a>
or Acrobat Professional
8.1 or above. To save completed forms, Acrobat Professional is required. For
technical and accessibility assistance, contact the <a href="http://twaincentral.azurewebsites.net/" target="_blank">Chief Platypus</a>");
doc.Add(composite);
我还想将此段限制在密西西比河以西(也就是说,页面的左半部分),但这是一个separate issue。