Reputation: 25928
In a ASP.NET C# website/server I am using the .pdf creater library called ITextSharp to create .pdfs with text & some images about a product.
As usual the boss doesn't want to purchase a licence. I know that if I use ITextSharp versions 4.1.6 or lower I can use the library under the free licence(cant I?)
My Question: Will the older versions(4.1.6-)/free versions meet my needs of generating a pdf with an image at the top, text content in the middle(some paragraphs) and an image at the bottom? Will I find some API functions not available to myself because I have the older versions?
Would you suggest I go to another open source ASP.NET C# .pdf generator?
Upvotes: 2
Views: 3365
Reputation: 1127
Yes you can do it, with older versions too. I have attached the code that uses the string builder to generate html with itext Sharp.
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();
Upvotes: 3