可以';不要将pdf中的文本加粗
本文关键字:文本 pdf 可以 | 更新日期: 2023-09-27 18:07:17
我想用pdf加粗求和。我尝试了下一个:
var phraseTotal = new Paragraph();
phraseTotal.Font.SetStyle(Font.BOLD);
phraseTotal.Add(new Chunk(string.Format("Total earned for period {0} - {1} : ", invoice.FromDate.ToShortDateString(), invoice.ToDate.ToShortDateString())));
phraseTotal.Add(new Chunk("£" + Math.Round(invoice.TotalAmount / 100.0, 2, MidpointRounding.AwayFromZero)));
list.Add(phraseTotal);
还试图在段落中添加一些字体。。。尝试将段落更改为短语。。。
但这个总和总是看不见的,或者没有以pdf格式呈现。
更新:问题在列表中。如果我对不在列表中的对象应用相同的方法,它是粗体的。
我会走这条路,而不是麻烦地写代码:
private MemoryStream createPDF(string html)
{
MemoryStream msOutput = new MemoryStream();
TextReader reader = new StringReader(html);
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 30, 30, 30, 30);
// step 2:
// we create a writer that listens to the document
// and directs a XML-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document, msOutput);
// step 3: we create a worker parse the document
HTMLWorker worker = new HTMLWorker(document);
// step 4: we open document and start the worker on the document
document.Open();
worker.StartDocument();
// step 5: parse the html into the document
worker.Parse(reader);
// step 6: close the document and the worker
worker.EndDocument();
worker.Close();
document.Close();
return msOutput;
}
Chunk c1 = new Chunk("Concentrate:", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD, BaseColor.BLUE)));
Chunk c2 = new Chunk("In order to remember something you need to learn it. Learning is possible only if you pay enough attention to it. You will retain information for a longer period of time only if you concentrate properly at the time of learning.", new Font(iTextSharp.text.Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLUE)));
Pharagraph p2 = new Pharagraph();
p2.Add(c1);
p2.Add(c2);
ListItem firstRecommend = new ListItem(p2);
这个样本来自这个答案https://stackoverflow.com/a/9227686/3917754。
我能够产生的问题是,我没有创建新的ListItem
,而是立即将Paragraph
添加到列表中。有了List Item
,一切都正常。