PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Apr 28, 2024 5:38 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Fri Apr 02, 2010 6:34 pm 
Offline

Joined: Thu May 28, 2009 8:11 pm
Posts: 14
I want to sent a generated PDF document as an email attachment.

I do recieve an email with PDF attachment, but its size is 0 bytes!
Why?

Below my code:

Dim att As New System.Net.Mail.Attachment(getfile, "MY_ATTACHMENT.pdf", "application/pdf")
'The returned stream fro getfile is not empty, but somehow the attachment of the email is...
'Even when I check the att variable it holds the same size as the stream!
Msg.Attachments.Add(att)

Msg.Body = MailContent
Try
mailObj.Send(Msg)
Catch ex As Exception
End Try


Protected Function getfile() As MemoryStream
Dim document As PdfDocument = New PdfDocument
'removed lines where document is filled

Dim stream As MemoryStream = New MemoryStream

If document.PageCount > 0 Then 'pagecount = 1
document.Save(stream, False) 'STREAM actually holds a value since its capacity is now 73520 bytes and its length is now 39308 bytes
Return stream
End If
End Function

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Sat Apr 03, 2010 8:44 am 
Offline

Joined: Fri Apr 02, 2010 11:29 am
Posts: 2
Hi,

I didn’t try to save the document trough stream, but if you continue stuck in that, you could save the document as a file and attach it to e-mail trough path to file.

Code:
PdfDocument document = new PdfDocument();
(…)
String  filename = "HelloWorld.pdf";
document.Save(filename);

MailMessage mail = new MailMessage();
mail.Attachments.Add(new Attachment(filename));
(…)
//After send it and if want to delete the file, you have to explicitly dispose mail to release the file
mail.Dispose();
new FileInfo(filename).Delete();


Regards,
David


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 06, 2010 7:38 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
petersmith wrote:
Why?

I don't know for sure (you don't mention which version you have); and I never tried to e-mail attachments.

See also here:
viewtopic.php?f=3&t=923

You can create a new MemoryStream from the byte[] returned by "stream.ToArray());" and try that stream - capacity and length should then be the same.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 370 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group