我在 ckeditor 粗体、斜体等中使用了一些基本样式,以允许我的用户为他们的文本设置样式以编写报告。
当将此字符串传递给 iTextSharp 时,我将删除 html,否则 html 将打印在 pdf 上。我正在删除这个
Regex.Replace(item.DevelopmentPractice.ToString(), @"<[^>]*>| ", String.Empty)
有没有办法格式化pdf上的文本以保留粗体但不显示
<strong></strong>
更新
我已按要求在下面提供了完整代码。
public FileStreamResult pdf(int id)
{
// Set up the document and the Memory Stream to write it to and create the PDF writer instance
MemoryStream workStream = new MemoryStream();
Document document = new Document(PageSize.A4, 30, 30, 30, 30);
PdfWriter.GetInstance(document, workStream).CloseStream = false;
// Open the pdf Document
document.Open();
// Set up fonts used in the document
Font font_body = FontFactory.GetFont(FontFactory.HELVETICA, 10);
Font font_body_bold = FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD);
Chunk cAreasDevelopmentHeading = new Chunk("Areas identified for development of practice", font_body_bold);
Chunk cAreasDevelopmentComment = new Chunk(item.DevelopmentPractice != null ? Regex.Replace(item.DevelopmentPractice.ToString(), @"<[^>]*>| ", String.Empty) : "", font_body);
Paragraph paraAreasDevelopmentHeading = new Paragraph();
paraAreasDevelopmentHeading.SpacingBefore = 5f;
paraAreasDevelopmentHeading.SpacingAfter = 5f;
paraAreasDevelopmentHeading.Add(cAreasDevelopmentHeading);
document.Add(paraAreasDevelopmentHeading);
Paragraph paraAreasDevelopmentComment = new Paragraph();
paraAreasDevelopmentComment.SpacingBefore = 5f;
paraAreasDevelopmentComment.SpacingAfter = 15f;
paraAreasDevelopmentComment.Add(cAreasDevelopmentComment);
document.Add(paraAreasDevelopmentComment);
document.Close();
byte[] byteInfo = workStream.ToArray();
workStream.Write(byteInfo, 0, byteInfo.Length);
workStream.Position = 0;
// Setup to Download
HttpContext.Response.AddHeader("content-disposition", "attachment; filename=supportform.pdf");
return File(workStream, "application/pdf");