Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2005

Tip: Looking for answers? Try searching our database.

PDF gets corrupted when sent as an email attachment

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Covington - 26 Sep 2005 20:16 GMT
I have an app that creates customer information and creates a pdf
report.  It ecrypts it and password protects it.  The report is sent as
an email attachment. THe report is confidetial.  

All of the pdfs open fine on local machine but customer gets errors when
opened.  This is documented at
http://www.adobe.com/support/techdocs/322743.html

Attaching a pdf in an email somehow corrupts it.  Is there another way a
confidential report can be generated, encrypted and password protected
other than pdf?


 

jwc
Oliver Sturm - 27 Sep 2005 10:05 GMT
>I have an app that creates customer information and creates a pdf
>report.  It ecrypts it and password protects it.  The report is sent as
[quoted text clipped - 5 lines]
>
>Attaching a pdf in an email somehow corrupts it.

Well, if it does in your case, I'm sure this is the problem you should try
to solve. I have sent PDF files by email very many times without problems
- I'm pretty sure every mail program out there knows how to do that
correctly, because it's such a widely used feature.

The article you are referring actually gives a hint - the encoding of the
file when sent by mail may not be correct. I reckon if you were sending
the PDF file in some kind of text encoding (as opposed to a binary
encoding), this could certainly be the cause of the damage. You don't
mention how the "sending as email attachment" is actually done. Do you do
it from code? If so, show us the code, please!

               Oliver Sturm
Signature

Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Jim Bob - 27 Sep 2005 14:45 GMT
Private Sub btPDF_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
       'create & instantiate mail object
       Try
           SmtpMail.SmtpServer = "Exchange"
           Dim _mail As New MailMessage
           Dim _att As New MailAttachment(Application.StartupPath & "\"
& Trim(AchInfoRow.Item("TrsNme")) & ".zi3")
           'attach to, subject, attachment & body
           _mail.Attachments.Add(_att)
           _mail.From = "Brendam@Firstbankms.com"
           '_mail.To = AchInfoRow.Item("EmailAddress")
           '_mail.To = "jim@firstbankms.com"
           _mail.To = "jwcoving@cableone.net"
           '_mail.To = "marsalis@cableone.net"
           _mail.Subject = "Your Report of Transactions"
           _mail.Cc = "marsalis@cableone.net"

          ' set the default smtp server & send it
           SmtpMail.Send(_mail)
           MessageBox.Show("eMail to " &
Trim(AchInfoRow.Item("trName")) & " successful.")
       Catch Exp As Exception
           MessageBox.Show(Exp.Message)
           MessageBox.Show(Exp.ToString)
       Finally
           cn.Close()
       End Try
   End Sub

jwc
Oliver Sturm - 27 Sep 2005 15:10 GMT
<code cut>

Okay, this shows the problem. I have just made some tests with .NET 1.1
and it seems that the attachment functionality is a bit buggy there (don't
know about v2, I haven't tested it there yet). The problem in your sample
code is that you don't have any body text at all. This results in mail
messages that don't use any encoding for the PDF attachment at all, but
just use the application/pdf type for the whole message - just insert
something in the message's body (maybe a string like "here's your
document") and things should work fine for you.

The other funny thing I noticed is that the encoding that I set for the
attachment doesn't seem to be honored, whatever I do. MSDN docs say that
UUEncode should be default - nevertheless, once you get message to use an
encoding by having something in the body, it looks like Base64 is always
being used. Funny... just a side note. I'd expect this to work better in
.NET 2.

               Oliver Sturm
Signature

Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Jim Bob - 27 Sep 2005 15:35 GMT
Private Sub btPDF_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
       'create & instantiate mail object
       Try
           SmtpMail.SmtpServer = "Exchange"
           Dim _mail As New MailMessage
           Dim _att As New MailAttachment(Application.StartupPath & "\"
& Trim(AchInfoRow.Item("TrsNme")) & ".zi3")
           'attach to, subject, attachment & body
           _mail.Attachments.Add(_att)
           _mail.From = "Brendam@Firstbankms.com"
           '_mail.To = AchInfoRow.Item("EmailAddress")
           '_mail.To = "jim@firstbankms.com"
           _mail.To = "jwcoving@cableone.net"
           '_mail.To = "marsalis@cableone.net"
           _mail.Subject = "Your Report of Transactions"
           _mail.Cc = "marsalis@cableone.net"

          ' set the default smtp server & send it
           SmtpMail.Send(_mail)
           MessageBox.Show("eMail to " &
Trim(AchInfoRow.Item("trName")) & " successful.")
       Catch Exp As Exception
           MessageBox.Show(Exp.Message)
           MessageBox.Show(Exp.ToString)
       Finally
           cn.Close()
       End Try
   End Sub

jwc
Jim Bob - 27 Sep 2005 22:07 GMT
Oliver:

I did as you suggested but the problem remains. Mostly I get an
"Unregognized token" error.  Is there anything else I can try?  Thanks.

jwc
Oliver Sturm - 28 Sep 2005 10:17 GMT
>I did as you suggested but the problem remains. Mostly I get an
>"Unregognized token" error.  Is there anything else I can try?

Hm, that's interesting - I had no problems once I inserted some body text.
You could try using the two different encodings that are available,
although that didn't seem to make any difference in my tests. Just pass
the second parameter to the constructor of the MailAttachment class.

You are using .NET 1.1, aren't you? Not 1.0, by any chance?

               Oliver Sturm
Signature

Expert programming and consulting services available
See http://www.sturmnet.org (try /blog as well)

Jim Bob - 28 Sep 2005 21:01 GMT
Oliver:

Thank-you for your assistance.  I changed the encoding to
uuEncode and it appears now to be working.  

I am on v1.1 of the Framework.

jwc
Gav - 29 Sep 2005 01:19 GMT
Hi Jim,

I have previously looked into creating PDF programatically with password
protection and was lead to believe it could not be done. Do you have any
sources for password protecting pdf files in c#?

Thanks
Gav

> Oliver:
>
[quoted text clipped - 6 lines]
>
> *** Sent via Developersdex http://www.developersdex.com ***

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.