As I explain in my book about iText, you should create a PDF in 5 steps when using iText(Sharp). Creating the writer
is step 2 and opening the document is step 3. You have switched these two steps and this is what causes the error.
You need to move the line document.Open()
down a couple of lines. After where you create the writer
and before creating the cb
instance.