01.
void
TestCreateFile() {
02.
03.
Document doc =
new
Document();
04.
file = $
"D:\\example{DateTime.Now:yyyyMMdd hhmmss ffff}.pdf"
;
05.
try
06.
{
07.
08.
PdfWriter writer = PdfWriter.GetInstance(doc,
new
FileStream(file, FileMode.Create));
09.
10.
11.
doc.Open();
12.
13.
14.
15.
16.
17.
18.
19.
Paragraph paragraph =
new
Paragraph(
"Test การใช้งาน iTextSharp"
);
20.
21.
doc.Add(paragraph);
22.
}
23.
catch
(DocumentException ex)
24.
{
25.
26.
Console.WriteLine(ex.Message);
27.
}
28.
catch
(IOException ex)
29.
{
30.
31.
Console.WriteLine(ex.Message);
32.
}
33.
finally
34.
{
35.
36.
doc.Close();
37.
}
38.
}