Question: How do I use the #PDF Library called iText 7 to write to the pdf in C-sharp?
Login to See the Rest of the Answer
Answer: Follow the steps below to write to the PDF using #iText7 Open Source PDF Library
//Initialize PDF writer
PdfWriter writer = new PdfWriter(location);?
PdfDocument pdf = new PdfDocument(writer);?
Document document = new(pdf);?
Image logo = new Image(ImageDataFactory.Create(logoPath));
logo.SetHorizontalAlignment(HorizontalAlignment.CENTER);
document.Add(logo);?
for (int i = 0; i < items.Count; i++)
{
document.Add(new Paragraph(items[i][0].ToString()));
}?
document.Close();?
private void createPdf(String dest, string logoPath, List<string[]> items)
{
//Initialize PDF writer
PdfWriter writer = new PdfWriter(dest);
//Initialize PDF document
PdfDocument pdf = new PdfDocument(writer);
// Initialize document
Document document = new(pdf);
document.SetFontSize(14);
document.SetTextAlignment(TextAlignment.CENTER);
//Add paragraph to the document
Image logo = new Image(ImageDataFactory.Create(logoPath));
logo.SetHorizontalAlignment(HorizontalAlignment.CENTER);
document.Add(logo);
for (int i = 0; i < items.Count; i++)
{
document.Add(new Paragraph(items[i][0].ToString()));
}
//Close document
document.Close();
}?