Question PDF file size concerns for email attachment


New member
Sep 24, 2013
Programming Experience
Hello VB.NET Forums members,

This is my first post on these forums and hope I am posting in the correct section. That being said, here is my concern.

I am creating a PDF document based on an html string using ExpertPDF (HTML to PDF Converter - HTML to PDF for .NET - ExpertPDF Library) and am emailing the PDF created to the user who requested it and then KILL()"ing" the file afterwords. I have tested using my browser as well as the visual web developer debugger to step through this process and what i've noticed is, the debugger's PDF email attachment is much smaller than the one created through my browser, about 4MB opposed to 15-16MB from the browser. My first question is, why is there a difference in PDF sizes? My second question is, at some point, the file size of the PDF document being generated through my browser increases and I no longer recieve the email with it attached, why is this? Something to do with IIS? (I'm not too experienced with modifying the IIS Manager, but I'm sure I could follow directions sufficently).

Steps I've taken to resolve the issue:

1. ExpertPDF has a document property for none, normal, or best compression. I have set this property to Best and reduces the PDF file size using the debugger from 4MB to just under 200KB; where as, the browser's pdf remains at 15-16MB in size.

"pdfConverter.PdfDocumentOptions.PdfCompressionLevel = HtmlToPdf.PdfCompressionLevel.Best"

2. I have taken the PDF document and compressed it into a .zip file using GZipStream

"'Dim zipName As String = FileName + ".zip
'Dim destFile As FileStream = File.Create(zipName)
'Dim compStream = New GZipStream(destFile, CompressionMode.Compress)
'Dim theByte As Integer = sourceFile.ReadByte()
'While (theByte <> -1)
'theByte = sourceFile.ReadByte()
'End While
'Catch ex As Exception
'End Try
'Delete non-compressed pdf
'End Try

Using this compression works, but not everyone of the users will have something to uncompress the file, which is a substantial consideration. I have used PeaZip utility to extract the files just fine, but others weren't able to extract it. Also, this doesn't solve the problem because the compressed file sizes were still greatly different between the debugger's and the browser's.

3. I have set the attachment mediaType to "application/octet-stream", but may simply be redundant and not actually add any performance to the situation. See applicable email code below.

'If Not IsNullOrEmpty(attachmentItem) Then
'Dim itemAttached As New Attachment(attachmentItem, attachmentName, "application/octet-stream")
Dim itemAttached AsNewAttachment(attachmentName, "application/octet-stream")
'End If
Dim mSmtpClient AsNewSmtpClient()
mSmtpClient.Timeout = 200000
' Send the mail message
Catch ex AsException
Dim exMessage AsObject = ex.InnerException
'required! File cannot be in use for it to be deleted

Exit Sub
'Delete attachment

Any assistance or information provided will be greatly helpful to me understanding the issue, because traditional Google/Bing seraches are overly generalized or simply ads to use some Microsoft or Adobe product.s


Last edited:
Top Bottom