Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the following code (C#) for generating a PDF using iTextSharp. This code currently svaes thePDF however I need it to automatically name the

I have the following code (C#) for generating a PDF using iTextSharp. This code currently svaes thePDF however I need it to automatically name the filename to the contents in txtID.Text. For example if the contents added in the txtID.Text is E1234, I want the file to automatically add the E1234 to the filename so the file will be E1234.pdf. I have tried a couple of things but with no luck.

Here is my current code without any auto naming included:

private void btnCreatePDF_Click(object sender, EventArgs e)//transfers data displayed in txtDisplay.Text into a PDF { using (SaveFileDialog sfd = new SaveFileDialog()

{ Filter = "PDF file|*.pdf", ValidateNames = true }) { if (sfd.ShowDialog() == DialogResult.OK) { iTextSharp.text.Document doc = new iTextSharp.text.Document(PageSize.A4.Rotate()); try { PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create)); doc.Open(); doc.Add(new iTextSharp.text.Paragraph(txtDisplay.Text)); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);

} finally { doc.Close(); } }

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago