Itextsharp - Sending In-Memory PDF in an Email Attachment

iTextSharp - Sending in-memory pdf in an email attachment

Have you tried:

PdfWriter writer = PdfWriter.GetInstance(doc, memoryStream);

// Build pdf code...

writer.CloseStream = false;
doc.Close();

// Build email

memoryStream.Position = 0;
mm.Attachments.Add(new Attachment(memoryStream, "test.pdf"));

If my memory serves me correctly, this solved a similar problem in a previous project.

See http://forums.asp.net/t/1093198.aspx

iTextSharp send PDF as attachment using Memorystream

You should call pdfMemoryStamper.Close() after pdfMemoryStamper.Writer.CloseStream = false;

Like this:

// *snip*

pdfFileStamper.FormFlattening = true;
pdfMemoryStamper.FormFlattening = true;
pdfMemoryStamper.Writer.CloseStream = false;

pdfMemoryStamper.Close();

memoryStream.Position = 0;

// *snip*

C#: Attach an in-memory iTextSharp pdf as an Outlook attachment

As posted by Paul-Jan in the comments, attaching an in-memory pdf is not possible with Outlook. I have switched to a MailMessage.

VB.net itextsharp attachment

Try flushing the writer and rewinding the stream:

Dim pdfFile As MemoryStream = New MemoryStream()
Dim d As Document = New Document(PageSize.A4, 60, 60, 40, 40)
Dim w As PdfWriter = PdfWriter.GetInstance(d, pdfFile)
w.Open()
w.Add(New Paragraph("do foo something "))

w.CloseStream = false;
d.Close();
pdfFile.Position = 0;

Adapted from: iTextSharp - Sending in-memory pdf in an email attachment

Create a document in memory?

Here's a code example that looks like it should work... (havent tried it myself)

http://www.nabble.com/Re%3A-Create-Pdfreader-from-Memory-Stream-p22792260.html



Related Topics



Leave a reply



Submit