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
Why Enums Require an Explicit Cast to Int Type
C# Windows Forms Application - Updating Gui from Another Thread and Class
For I = 0, Why Is (I += I++) Equal to 0
Write to Windows Application Event Log Without Event Source Registration
Why Does the Lock Object Have to Be Static
How to Solve Operator '!=' Cannot Be Applied to Operands of Type 'T' and 'T'
Is There a Way of Setting a Property Once Only in C#
Observablecollection and Threading
How Does Comparison Operator Works with Null Int
C# Implementation of Deep/Recursive Object Comparison in .Net 3.5
Serialize Property, But Do Not Deserialize Property in JSON.Net
For Loop Not Returning Expected Value - C# - Blazor
How to Write One to Many Query in Dapper.Net
Is Enabling Double Escaping Dangerous
How to Install a Certificate into the Local MAChine Store Programmatically Using C#