PDF file size while encryptiing a PDF

We are experiencing issue with the file size increase while using this type of encryption. Many of our files are tripling in size making them hard to download. The perfect level of security is less than important then keeping the documents move in our case.

Do you have any recommendations or solution to help control file size?

Dim DocSecurity As New PdfFileSecurity(outFinalStream, finalOut)
'Create a document privilege to meet the requirements of the overload
'could not demonstrate how it works
Dim DocPriv As DocumentPrivilege = DocumentPrivilege.Print
'Apply the security password and encryption
'Parameters
'User Password - Use a value if the user need to enter a password to open the file “” for none
'Owner Password - The password that locks down the document to enforce the limitations
'Assign the document privilege from above
'Assign the encryption level
Dim pwd As String = ########
If DocSecurity.EncryptFile(String.Empty, pwd, DocPriv, KeySize.x256) Then
'successfully encrypted
'Use the PDF privilege to make sure users can print the manual
Dim pdfPriv As PdfPrivilege = PdfPrivilege.Print
DocSecurity.SetPrivilege(pdfPriv)
pdfByteArray = New Byte(CType(finalOut.Length, Integer)) {}
pdfByteArray = finalOut.GetBuffer()

Thanks,
Alan

Hi Alan,

Thank you for using our products and sharing the sample source code with us. I tried using your code to test your issue but due to missing variables, I was unable to replicate the scenario at my end. However, to exactly replicate your issue at our end, we would appreciate, if you create a sample application along with template documents and post here to show the issue. This will help us to regenerate the issue and get the cause of the issue soon.

We apologize for your inconvenience.

Thanks & Regards,

If you go here http://www.generac.com/Service/ManualSearch/

and enter model number 0055040

You will get


The number on the right are the actual PDF fils sizes as stored on the server.

If you download any of them they pass through encryption routine above the size of the PDF at least doubles and can triple making them hard to download.

Doe this answer your question?

Alan

Hi Alan,

Thanks for sharing the details.

First of all, I would like to inform you that Aspose.Pdf for .NET and Aspose.Pdf.Kit for .NET have been merged into a single product and Aspose.Pdf.Kit for .NET has been discontinued as a separate product. All the features of Aspose.Pdf.Kit for .NET are available under Aspose.Pdf.Facades namespace of Aspose.Pdf for .NET v6.x. You can check the following documentation links to upgrade your code from Aspose.Pdf.Kit for .NET to the new merged Aspose.Pdf for .NET.

I tested the scenario with below mentioned source code (shared over Encrypt PDF File using Different Encryption Types and Algorithms (Facades)) using Aspose.Pdf for .NET v7.0 and unable to see huge difference in size. During my testing, I was used a sample document of size 57KB and after encryption the resultant file size increase to 63KB. Source and resultant PDF documents are attached for your reference.

[VB.NET]

'create PdfFileSecurity object with input and output files<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Dim fileSecurity As New PdfFileSecurity("d:\pdffiles\adobe.pdf", "d:\pdffiles\output.pdf")

'encrypt file using 256-bit encryption

fileSecurity.EncryptFile(String.Empty, "ownerpassword", DocumentPrivilege.Print, KeySize.x256, Algorithm.AES)

Kindly use the latest version of Aspose.Pdf for .NET v7.0 and check if it works fine for you.

Please feel free to contact support in case you need any further assistance.

Thanks & Regards,

Thank you for your help. I will try 7.0 and see if that is the cure we need.

Alan

Rashid,

I am trying version 7 and it has introduced an out of memory error at the encryption step

You can get the source files I am using at:
http://www.honeywellgenerators.com/ManualSearch/

Enter Model Number 0055040

I am trying to stitch together the 3 highlighted manuals and am getting an out of memory error.
You can download the source files from there.


For PageCount = 0 To totalDrawings Step 1 Dim pdfFilePath As String = String.Format("{0}{1}", mPDFPath, manualList(PageCount)) Dim fi As System.IO.FileInfo = New System.IO.FileInfo(pdfFilePath) If fi.Exists AndAlso fi.Length > 0 Then inStreams(PageCount) = New FileStream(pdfFilePath, FileMode.Open, FileAccess.Read, FileShare.Read) inStreams(PageCount).Position = 0 inStreams(PageCount).Seek(0, SeekOrigin.Begin) Else TraceLog.WriteTrace(System.Diagnostics.TraceLevel.Error, "ProductManuals2", itemNbr, "AssemblePDF", String.Format("Invalid or missing manual: {0}", pdfFilePath)) completeManual = False End If Next If completeManual = True AndAlso inStreams(0) IsNot Nothing AndAlso pdfEditor.Concatenate(inStreams, outFinalStream) Then outFinalStream.Position = 0 outFinalStream.Seek(0, SeekOrigin.Begin) 'Attach meta data to the PDF Dim pdfFi As New PdfFileInfo(outFinalStream) pdfFi.Title = "Generac Power Systems, Inc." pdfFi.Author = "Generac Power Systems, Inc." pdfFi.SaveNewInfo(outFinalStream) 'Encrypt the final PDF in a new memory stream 'Move the output to the Document Security object Dim DocSecurity As New PdfFileSecurity(outFinalStream, finalOut) 'Create a document privilege to meet the requirements of the overload 'could not demonstrate how it works Dim DocPriv As DocumentPrivilege = DocumentPrivilege.Print 'Apply the security password and encryption 'Parameters 'User Password - Use a value if the user need to enter a password to open the file "" for none 'Owner Password - The password that locks down the document to enforce the limitations 'Assign the document privilege from above 'Assign the encryption level Dim pwd As String = "tempPwd" If DocSecurity.EncryptFile(String.Empty, pwd, DocPriv, KeySize.x40) Then 'successfully encrypted 'Use the PDF privilege to make sure users can print the manual Dim pdfPriv As DocumentPrivilege = DocumentPrivilege.ForbidAll 'Dim pdfPriv As DocumentPrivilege = Nothing pdfPriv.AllowPrint = True DocSecurity.SetPrivilege(pdfPriv) pdfByteArray = New Byte(CType(finalOut.Length, Integer)) {} pdfByteArray = finalOut.GetBuffer() Else 'If the encryption fails go ahead and give out the unencrypted manual 'and raise a tracelog pdfByteArray = New Byte(CType(outFinalStream.Length, Integer)) {} pdfByteArray = outFinalStream.GetBuffer() TraceLog.WriteTrace(System.Diagnostics.TraceLevel.Error, "ProductManuals2", "AssemblePDF", String.Format("Failure to Encrypt ItemNbr: {0}", itemNbr)) End If 'Use for testing to write the document to your desktop 'Make sure it is commented out for any other use 'Dim fs As New FileStream("D:\ManualPDFs\TestManuals2.pdf", FileMode.Create, FileAccess.Write) 'fs.Write(pdfByteArray, 0, pdfByteArray.Length) 'fs.Close() 'fs.Dispose() 'pdfByteArray = Nothing 'End test area End If Catch ex As Exception TraceLog.WriteTrace(System.Diagnostics.TraceLevel.Error, "ProductManuals2", "AssemblePDF", String.Format("ItemNbr: {0}", itemNbr), ex.Message) Finally If inStreams(0) IsNot Nothing Then For Each st As Stream In inStreams If st IsNot Nothing Then st.Dispose() Next End If outFinalStream.Dispose() End Try

Hi Alan,


Thanks for sharing the code snippet. We are working over this query and will get back to you soon. We are sorry for this delay and inconvenience.

Has there been any update on this I need to restore encryption to these files asap?

Thanks,
Alan
Generac Power Systems

Hi Alen,

Sorry for the delay in response.

I have tested your issue by using "0G8280.pdf", "0G8334.pdf", "0G8573.pdf" files with the latest version of Aspose.Pdf for.NET 7.1.0 and I am unable to reproduce any issue. The files are getting merged and security settings are applied without any exception. Please download and try the latest version and if you face any issue, please create a sample application and share with us. We will check it soon.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Sorry for the inconvenience,