在ASP.NET C#网站/服务器中,我使用名为ITextSharp的.pdf创建程序库来创建带有text&的.pdf文件。一些关于产品的图片。
像往常一样,老板不想购买许可证。我知道如果我使用ITextSharp版本4.1.6或更低版本,我可以使用免费许可证下的库(我不能吗?)我的问题:旧版本(4.1.6 - )/免费版本是否满足我生成pdf的需求,其中顶部是图像,中间是文本内容(某些段落),底部的图像?我会找到一些自己无法使用的API函数,因为我有旧版本吗?
您是否建议我转到另一个开源ASP.NET C#.pdf生成器?
答案 0 :(得分:3)
是的,您也可以使用旧版本。我附加了使用字符串生成器的代码,用mysxt生成html。
Document doc = new Document(PageSize.LETTER, 10, 10, 42, 35);
iTextSharp.text.pdf.PdfWriter wri = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream("D:\\PurchaseOrderDetails.pdf", FileMode.Create));
doc.Open();//
StringBuilder builder = new StringBuilder();
builder.Append("<html>");
builder.Append("<head>");
builder.Append("</head>");
builder.Append("<body>");
builder.Append("<img src=\"D:\\Images\\logo_left.png\" align=\"right\"/>");
builder.Append("<br/><br/><br/><br>");
builder.Append("");
builder.Append("<h1 style=\"font-weight: bold\">Purchase Order Details</h1> ");
builder.Append("");
builder.Append("<br /><br /> ");
builder.Append("<h2 style=\"font-weight: bold\">Purchase Order Information</h2> ");
builder.Append("<table> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">P.O.Number:</td> ");
builder.Append(" <td>" + txtPONumber.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Vendor:</td> ");
builder.Append(" <td>" + txtVendorName.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Entry Date:</td> ");
builder.Append(" <td>" + dtpickerEntryDate.SelectedDate + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Description:</td> ");
builder.Append(" <td>" + txtDescription.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Ship Method:</td> ");
builder.Append(" <td>" + drpShipMethod.SelectedItem.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Ship Carrier:</td> ");
builder.Append(" <td>" + drpShipCarrier.SelectedItem.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Price:</td> ");
builder.Append(" <td>" + txtPrice.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Shipping Cost:</td> ");
builder.Append(" <td>" + txtShippingCost.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Warranty Status:</td> ");
builder.Append(" <td>" + txtWarrantyStatus.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append(" <tr> ");
builder.Append(" <td style=\"font-weight: bold\">Part Requirement:</td> ");
builder.Append(" <td>" + drpPartRequirement.SelectedItem.Text + "</td> ");
builder.Append(" </tr> ");
builder.Append("</table> ");
builder.Append("<br /><br /> ");
builder.Append(" ");
builder.Append("<p style=\"text-align: center; font-style: italic; font-size: 10pt\"> ");
builder.Append(" Thank you for your business! If you have any questions about your order, please contact us at ");
builder.Append(" 800-555-. ");
builder.Append("</p> ");
builder.Append("</body>");
builder.Append("</html>");
var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(builder.ToString()), null);
foreach (var htmlElement in parsedHtmlElements)
doc.Add(htmlElement as IElement);
doc.Close();