System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); writer.SetEncryption(null, encoding.GetBytes("12345678"), PdfWriter.ALLOW_COPY, PdfWriter.STRENGTH40BITS);
And this is how to enable printing if you still want the pdf to be encrypted.
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); writer.SetEncryption(null, encoding.GetBytes("12345678"), PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING, PdfWriter.STRENGTH40BITS);
Thanks this saved lots of time...
ReplyDeleteGood to hear :)
ReplyDeleteThe code is useful to configure the printing mechanism. It's a useful tool.
ReplyDeletelarge printing
Thanks for sharing these wonderful and useful tips. I also experienced same problem and I wasn't able to resolve it, not until I read your blog.
ReplyDeletedata protection
I'm glad you shared this procedure to us. I've been thinking about it in a while now. Very useful indeed.
ReplyDeletelong island document scanning
I'm so grateful that you made this post about this common problem. The code really helps a lot.
ReplyDeletebristol printing
This is useful for secure documents. You can prevent it from being printed without permission.
ReplyDeleteseo company
Here is the code for VB.Net in pdf files exist
ReplyDeletePolicy: No Print
Params:
filename =file to apply Encrypt
strPass = password to apply
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.text.api
Imports System.IO
Public Class encriptaPDF
Public Sub EncriptaArchivo(ByVal filename As String, strPass As String)
Dim FileNew As String
Dim Encoding As New System.Text.UTF8Encoding()
Dim reader As New PdfReader(filename)
FileNew = Replace(filename, ".pdf", "excrypt.pdf")
Dim stamper = New PdfStamper(reader, New FileStream(FileNew, FileMode.Create))
stamper.SetEncryption(Nothing, Encoding.GetBytes(strPass), PdfWriter.AllowScreenReaders, PdfWriter.STRENGTH40BITS)
stamper.Close()
reader.Close()
File.Delete(filename)
File.Copy(FileNew, filename)
File.Delete(FileNew)
End Sub
End Class