I am rewriting a Sharepoint 2010 Webpart to move away from PDFSharp to iTextSharp. The formatting required on this projects seems to lend itself better to iTextSharp's capabilities. With that said, I am having a few issues getting iTextSharp to play ball this morning and hoping we maybe have someone around experienced with it. I have done a fair amount of googling before throwing in the towel and asking for help.
I am looking to create the PDF in a memorystream, then output to the browser (Worked in PDFSharp and same principals). For examples sake I have removed all of the intended content and just added a test paragraph to make the code sample more readable.
This is what SHOULD work. However upon calling the open method, it returns errors. I have found the reason is the document being created does not appear to be writable. I have tried removing the code to open, add paragraph and close the document. When that is done, the document does not give an error but prompts to open or save as expected. If you save and take a look you can see the metadata hasnt written and the document name is default.
Using ms = New IO.MemoryStream()
Dim pdfDoc AsNew iTextSharp.text.Document(PageSize.A4, 25, 25, 25, 25)
Dim writer AsPdfWriter = PdfWriter.GetInstance(pdfDoc, ms)
"Change Request " & viewID)
"content-disposition", "attachment;filename=First PDF document.pdf")
Response.OutputStream.Write(ms.GetBuffer, 0, ms.GetBuffer.Length)