iTextSharp “The document has no pages.”

2020-08-18 05:54发布

问题:

I'm using iTextSharp to update A PDF's file properties:

FileStream fs = File.Open(@"C:\Developer\C#Projects\BylawSearch\0001.pdf", FileMode.Open);
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.Open();
document.AddSubject("Blah");
document.AddTitle("Blah blah");
document.AddKeywords("Blah blah blah");
document.Close();

I'm getting a "The document has no pages." error from iTextSharp. Any help appreciated.

回答1:

You haven't added any information to put on a page ... !!

document.Add(new Paragraph("Hello World!"));

... for example.

Your title etc are part of the document properties (rather than something that's "printed" to the pdf).

Check out this introductory example, that seems to cover what you're after.



标签: c# itextsharp