我正在使用itext shapf来处理一些pdf内容。我添加了一个这样的表: -
PdfPTable tabler1Top = new PdfPTable(1);
tabler1Top.TotalWidth = 450f;
tabler1Top.LockedWidth = true;
//int[] intTblWidth1 = { 20, 50, 20, 40 };
//tabler1Top.SetWidths(intTblWidth1);
tabler1Top.SpacingBefore = 20f;
tabler1Top.HorizontalAlignment = Element.ALIGN_LEFT;
PdfPCell Order_Nbr = new PdfPCell(new Phrase("Order Nbr: " + _orderNumber + " Order Status:" + _order_Status + " Order Taker: " + _orderTakenBy, bodyFont));
//Order_Nbr.Border = Rectangle.NO_BORDER;
Order_Nbr.HorizontalAlignment = 0;
tabler1Top.AddCell(Order_Nbr);
PdfPCell Order_date = new PdfPCell(new Phrase("Orderedr: " + _orderDate + " " + _orderTime + " Received: " + _recivedDate + " " + _recivedTime + " ***Paper Work Required***", bodyFont));
tabler1Top.AddCell(Order_date );
doc.Add(tabler1Top);
并显示输出如: -
Orderedr: 09-Jan-14 12:00 AM Received: 09-Jan-14 1:22 AM ***Paper Work Required***
现在我想加粗像 Orderedr:这样的标题,它应该是粗体收到:像这样
我见过一个例子here
我试过这样: -
PdfPCell Order_Nbr = new PdfPCell(new Phrase("<b>Order Nbr: </b>" + _orderNumber + " Order Status:" + _order_Status + " Order Taker: " + _orderTakenBy));
但它显示的输出如下: -
<b>Order Nbr: </b>14MA09A8936 Order Status:AD
Order Taker: sbornstein
这个例子属于段落但是我在这里使用像PdfPCell Order_date = new PdfPCell(new Phrase("Orderedr: " +
这样的单元格。我在new new Phrase("Orderedr: "
中有一个字符串,所以有没有办法加粗标题。任何建议将不胜感激,如果它对我有用,我会给你答案。在此先感谢快乐编码:)
答案 0 :(得分:2)
首先,您需要制作两个 Phrase,一个正常,一个粗体。
Phrase p1 = new Phrase("Actividad Económica: ", FontFactory.getFont(FontFactory.HELVETICA, 11, Font.NORMAL, new Color(0, 0, 0)));
Phrase p2 = new Phrase(" Actividad ", FontFactory.getFont(FontFactory.HELVETICA, 11, Font.BOLD, new Color(0, 0, 0)));
然后你必须制作一个段落并添加短语
Paragraph paraDec = new Paragraph();
paraDec.add(p1);
paraDec.add(p2);
然后你只需要将段落添加到单元格
PdfPCell cPrueba = new PdfPCell(paraDec);
答案 1 :(得分:1)
可能这段代码会帮助你。
PdfPCell cell = PhraseCell(new Phrase("Orderedr", FontFactory.GetFont("Arial", 15, Font.UNDERLINE, BaseColor.BLACK)));