Tuesday, March 18, 2014

PDF password protection

In this tutorial, I am going to show you how to protect a PDF document by passwords so that users that do not have permissions cannot open or modify the content of the PDF document. You can set two passwords to the PDF document,  a user password and an owner password. The user password must be entered before the PDF document can be opened in Adobe Reader or Foxit Reader. The owner password applies restrictions to the PDF document. For example, you can  allow only printing and copying to the PDF document.
By using iText library you can set the passwords to the PDF document by using the setEncryption method of PdfWriter class. The general form of the setEncryption method is shown below:

setEncryption(byte[] userPassword, byte[] ownerPassword, int permissions, int encryptionType)

- userPassword--an array of bytes that is the user password.

- ownerPassword--an array of bytes that is the owner password.

- permissions--permissions or restrictions that will be applied to the PDF document. These permissions can be AllowPrinting, AllowCopy, AllowScreenReaders, AllowFillIn, AllowAssembly, or AllowDegradedPrinting.
- encryptionType--the type of encryption. The encryption type can be one of the following STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.


import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class PdfItext {
public static void main(String[] args){

static void setPasswords(){
//create a document object
Document doc = new Document();
//FileOutputStream object to write the pdf file
String path="d:/pdfdocprotected.pdf";
FileOutputStream fos=new FileOutputStream(path);
//get PdfWriter object
PdfWriter writer =PdfWriter.getInstance(doc,fos);
//convert strings of passwords to arrays of bytes
byte[] USER="Hello".getBytes();
byte[] OWNER="world".getBytes();
//spcify encryption of the document
writer.setEncryption(USER, OWNER, PdfWriter.ALLOW_PRINTING,

//open the document for writing
//write a paragraph to the document
doc.add(new Paragraph("This PDF document is protected."));
//close the document
//view the result pdf file
Desktop dt=Desktop.getDesktop();
dt.open(new File(path));
}catch(Exception e){e.printStackTrace();}

When you run the example code above, you might get the dependency error as shown below. To fix the error, you will download the extra jar files from http://sourceforge.net/projects/itext/files/extrajars/. Then extract the zip file and add the bcprov-jdk15on-1.48.jar file to the project. After that, run the program again.

ASN1Encodable not found error


  1. Your technical information related with java programming is very useful and interesting. Also share updated details about java in your website. Thanks for sharing this article.
    Java training institute in chennai

    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

  2. Great insights about protecting PDF software. Really helpful for encrypting my personal PDF documents.

  3. Wonderful blog & good post.Its really helpful for me, awaiting for more new post. Keep Blogging!

    JAVA Training Institutes in Chennai

  4. Thanks for sharing this informative blog..

    Java Institutes in Chennai

  5. I usually set passwords on PDF files with the help of the program PDF Password Protect Free.http://manyprog.com/pdf-password-protect.php

  6. Thank you for this great information. It was really helpful.

    school website design

  7. Really awesome blog. Your blog is really useful for me.
    Thanks for sharing this informative blog. Keep update your blog.
    Oracle Training In Chennai

  8. very informative blog. helps to gain knowledge about the password protection. Thanks for posting this information
    SEO Training in Chennai

  9. Really a great article..Thanks for sharing this valuable information.

    CCNA Training in Chennai | CCNA Training Institute in Chennai | Best CCNA Training in Chennai

  10. Really great post thanks for useful sharing with lots of apps thanks for useful sharing ivr telephony

  11. Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting. So know it's helpful..

    Weblogic Training in Chennai

  12. Nice article. Keep posting on Java Programming Language.

  13. The war between humans, orcs and elves continues earn to die . Lead your race through a series of epic battles, using your crossbow to fend off foes and sending out units to destroy castleshappy wheels . Researching and upgrading wisely will be crucial to your success! There are 5 ages total and each one will bring you new units to train to fight in the war for you cause.
    earn to die 2
    Whatever you do, don’t neglect your home base because you cannot repair it and once it is destroyed, you lose! Age of War is the first game of the series and really sets the tone for the Age of War games . Also try out the Age of Defense series as it is pretty similar.
    In this game, you start at the cavern men’s age, then evolvetank trouble ! There is a total of 5 ages, each with its units and turrets. Take control of 16 different units and 15 different turrets to defend your base and destroy your enemy.
    The goal of the game also differs depending on the level. In most levels the goal is to reach a finish line or to collect tokens. Many levels feature alternate or nonexistent goals for the player.

  14. Really cool post, highly informative and professionally written and I am glad to be a visitor of this perfect blog, thank you for this rare info! , Regards, servicenow training in hyderabad

  15. It is really a great and useful piece of info. I’m glad that you shared this helpful info with us. Please keep us informed like this. Thank you for sharing.

    Digital marketing company in Chennai

  16. A good blog. Thanks for sharing the information. It is very useful for my future. keep sharing
    red ball 2 | duck life 2 | happy wheels | Red Ball | Red ball 3 | Flash Games| Tank trouble

  17. Inventory Management Solution is an inventory controlling system solution and yet still easy to use Inventory Management as well as billing management Solutions, introduced by Aavennue Softech. Basically it works between three different layers of Inventory system i.e. Supplier / Purchaser, inventory and Customers.visit this site

  18. My Arcus offer java training with 100% placement. Our java training course that includes fundamentals and advance java training program with high priority jobs. java j2ee training with placement having more exposure in most of the industry nowadays in depth manner of java

    java training in chennai

  19. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing.

    Best PMP Training in Chennai | SAP Training in Chennai

  20. Use same technique...but same error face!

  21. Very Nice Blog I like the way you explained these things. I’ve been looking for ways to improve my website and overall rankings.I hope your future article will help me further.Take SEO Training in Chennai to mould yourself.

  22. Finding the time and actual effort to create a superb article like this is great thing. I’ll learn many new stuff right here! Good luck for the next post buddy..
    PHP training in chennai

  23. Bán thuốc diệt kiến Nhật Bản Super Arinosu Koroki siêu an toàn, diệt 1 con lây chết cả tổ LH 0983131528

  24. There are so many useful information in your post, I like it all the time. And I want to share this boost app ranking with you, you can take a look. This is very useful.

  25. Thanks for sharing this blog. This is so informative blog
    Learned a lot of new things from your post! Good creation and HATS OFF to the creativity of your mind.
    Very interesting and useful blog!
    Best CCNA Training in Gurgaon

  26. Khi sử dụng vong huyet ap nhat ban sẽ làm cho huyết áp của bạn luôn cân bằng, ổn định, công dụng cụ thể như sau :

    - Điều hòa ổn định huyết áp
    - Chống đau cứng vai cổ
    - Khi đi tầu xe đeo rất tốt vì vòng này tuần hoàn máu rất tốt nên - không gây ra cảm giác chóng mặt, say xe.

  27. Dịch Vụ Làm Visa Trọn Gói 247 Thủ Tục Nhanh Chóng, Gọn Nhẹ, Giá Ưu Đãi​ 0983.1315.28

  28. Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    Mindmajix EMC Training

  29. Wethecoders provides standard Java Project Help to students at affordable rate.

  30. It is nice article to improve my knowledge.thank you for sharing useful post
    web programming tutorial

  31. Dapatkan freechips 10rb untuk member baru hanya di S1288poker. HOKI KAMU ADA DISINI
    Info Lebih Lanjut Bisa Hub kami Di :
    BBM : 7AC8D76B
    WA : 087782869981


  32. View mieng tham hut mo hoi vung nach
    The strongest and most secure level of encryption within PDF format is 256-bit AES (for Advanced Encryption Standard), which has never been cracked!

  33. Ensure that your digital books have the correct organization. On the off chance that a book has a defective configuration, it will probably get negative audits, poor deals execution, and expulsion from Amazon's Kindle Store. altocompresspdf.com

  34. Tìm mua sản phẩm máy lọc nước điện giải Panasonic hàng nội địa Nhật chuẩn chính hãng giá rẻ call 0983131528

  35. One program is Cute PDF Writer. This is a free for individual utilize program that relies on Ghostscript programming to create PDF records. unlock pdf

  36. nice work keep it up thanks for sharing the knowledge.Thanks for sharing this type of information, it is so useful. Epoxy Grout manufacturer in delhi

  37. hi, nice information is given in this blog. Thanks for sharing this type of information, it is so useful for me. nice work keep it up. Laminated Doors manufacturer in hubli

  38. hello sir,
    thanks for giving that type of information.led lawn lights in delhi


    you can search low-cost website with high-quality website functions.
    Today Join Us
    Call: +91 - 8076909847

    web development company in delhi

    interior designers delhi

    web design company

    top seo company in delhi

    Best It Service Provider:

    1. Website Designing And Development.
    2. SEO Services.
    3. Software Development.
    4. Mobile App Development.

  40. Thanks for sharing such helpful an informative article. I hope you will keep sharing such an informative articles more and more

  41. A lot of thanks for your whole hard work on this website. My mum takes pleasure in doing research and it is obvious why. I notice all of the dynamic way you convey great items by means of the website and therefore inspire contribution from other individuals on that issue while our own princess is always discovering a great deal. Have fun with the remaining portion of the new year. You are doing a glorious job. social media strategy










    * Melayani LiveChat 7 x 24 Jam Nonstop :
    - WA : +6281717177303
    - BBM : WINNING303
    - LINE : WINNING303*





    * Melayani LiveChat 7 x 24 Jam Nonstop :

    - WA : 08125522303
    - BBM : CSID303



  44. Hola! I've been reading your website for some time now and finally got the courage to go ahead and give you a shout out from Atascocita Tx! Just wanted to tell you keep up the good job! 10ft lorry rental

  45. I love this post.

    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสมาชิกที่นี่ >>> Gclub online

  46. I love this post.

    เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
    เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
    และยังมีเกมส์สล็อตออนไลน์ 1688 slot อีกมากมายให้คุณได้ลอง
    สมัครสมาชิกที่นี่ >>> Gclub Royal1688

  47. Thank you so much for providing individuals with such a wonderful chance to read articles and post posts from here. It is often very nice and packed with amusement for me personally and my office acquaintances to visit your web site particularly thrice weekly to study the latest guides you have. And of course, we are certainly amazed with all the incredible inspiring ideas served by you. Some two points in this post are without a doubt the very best we've had. Air Cargo Service

  48. I am grateful to the owner of this site which really shares this wonderful work of this site. That is actually great and useful information. I would also like to share some useful information regarding SEO services in Delhi(www.nexcuit.com)This is the best SEO company in Laxmi Nagar, East Delhi. So if anyone is looking out for
    the Best SEO company in Delhi then reach out to them on the given number+919910326510 and get more details related to the packages they offer and their prices. One thing I can bet on is that you will get 100% satisfaction from there services.

    seo services in delhi
    best seo company in delhi
    seo company in delhi
    seo company in laxmi nagar

  49. I am grateful to the owner of this site which really shares this wonderful work of this site. That is actually great and useful information. I would also like to share some useful information.If
    you are Looking for the satta result Delhi Darbar in delhi,ncr or satta result Gali, satta result Deshawar. Then open the below link for more details.

    satta result Taj
    satta result Delhi Darbar
    satta result Gali
    satta result Deshawar
    Disawar Satta Result
    satta result Ghaziabad
    satta result Faridabad

    satta king shri ganesh
    satta result chart
    satta king chart
    satta king result
    satta bazar result

  50. Thanks for sharing excellent informations. Your web site is very cool. I am impressed by the details that you have on this web site. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for more articles. You, my friend, ROCK! I found just the information I already searched everywhere and simply could not come across. What a great site. singapore domain

  51. Thanks for giving that type of information. Really enjoyed this blog post. I would also like to share some useful information.If you are Looking for the satta result Delhi Darbar in delhi,ncr or satta result Gali, satta result Deshawar. Then open the mention link for more details.

    satta king Faridabad satta king Gali satta king Desawar

  52. I am grateful to the owner of this site which really shares this wonderful work of this site. That is actually great and useful information. I would also like to share some useful information regarding digital marketing company in delhii(www.nexcuit.com)This is the digital marketing company in delhi located in Laxmi Nagar, East Delhi. So if anyone is looking out for the Best SEO company in Delhi then reach out to them on the given number+919910326510 and get more details.related to the packages they offer and their prices. One thing I can bet on is that you will get 100% satisfaction from there services.
    digital marketing company in delhii
    Best Digital marketing agency serving in Delhi
    best digital marketing company in Delhi NCR

  53. Hi, thanks for your blog, if you want to learn about programming languages like java, php, android app, embedded system etc. I think this training institute is the best one.
    Embedded systems training in coimbatore
    Android training in coimbatore
    Networking training in coimbatore

  54. Dapat Angka Bocor SGP.!! Terbukti 100%
    Begini Cara Menghitung Angka Bocor

  55. I think this is among the most vital info for me. And i am glad reading your article. But should remark on few general things, The website style is wonderful, the articles is really great : D. Good job, cheers. buy tea in singapore

  56. I am really impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you customize it yourself? Either way keep up the excellent quality writing, it’s rare to see a great blog like this one these days.secured payment gateways

  57. Hey there! Would you mind if I share your blog with my facebook group? There's a lot of people that I think would really appreciate your content. Please let me know. Cheers
    Top SEO Experts

  58. Hi there! This is kind of off topic but I need some advice from an established blog. Is it difficult to set up your own blog? I'm not very techincal but I can figure things out pretty fast. I'm thinking about creating my own but I'm not sure where to start. Do you have any ideas or suggestions? simple website design

  59. My wife and i ended up being thankful when Raymond could round up his analysis while using the ideas he made out of your weblog. It's not at all simplistic to simply possibly be releasing secrets which some others may have been selling. And we all fully grasp we have got the website owner to appreciate for this. Most of the explanations you've made, the easy web site navigation, the relationships you can give support to foster - it is many extraordinary, and it's helping our son in addition to the family reason why this issue is excellent, which is especially serious. Thank you for the whole lot!
    seo business

  60. hello!,I like your writing so much! share we communicate more about your article on AOL? I need an expert on this area to solve my problem. Maybe that's you! Looking forward to see you.
    oxford graphic Singapore

  61. I am really loving the theme/design of your web site. Do you ever run into any web browser compatibility problems? A couple of my blog audience have complained about my site not operating correctly in Explorer but looks great in Chrome. Do you have any tips to help fix this problem?
    promising the #1 ranking

  62. Woah! I'm really digging the template/theme of this blog. It's simple, yet effective. A lot of times it's very hard to get that "perfect balance" between superb usability and appearance. I must say you've done a excellent job with this. In addition, the blog loads very quick for me on Safari. Excellent Blog!
    international conferences singapore

  63. This comment has been removed by the author.

  64. This comment has been removed by the author.

  65. Hi Friend,

    This is definitely one of the best articles I have read in this website! Thanks for your wonderful article to share for us. We are doing the same service with affordable cost for chennai to tirupati car packages.

    chennai to tirupati car packages

  66. Thanks for sharing your info. I really appreciate your efforts and I will be waiting for your further write ups thanks once again.

    tirupati darshan package from chennai

  67. Thanks for put such an important thing in this blog. If you need website designing and digital marketing services in delhi, OGEN Infosystem is best place for you.
    Web Design Company

  68. Di https://tantepoker.me anda dapat
    bermain permainan yang ditawarkan tanpa takut dicurangi karena situs ini tidak memakai sisem bot.

    Judi Online
    Judi poker
    Poker pulsa
    Poker Online

  69. Appslure is a high rated Mobile Game development company in Delhi. We are no 1 company for IOS & Android games.
    Game Development company in Delhi

  70. Thanks for sharing this useful information with us .I am looking for this from a long time and I really very happy to say That I also deals with this service Yahoo Helpline, How to Contact Yahoo Support

  71. Thanks for sharing this useful information with us .I am looking for this from a long time and I really very happy to say That I also deals with this service contact outlook support,outlook coustomer support,outlook contact number,outlook help contact,outlook mail contact

  72. Android App Development Company Noida for iOS Apps. Android App Development Services in Noida.
    android app development company in noida

  73. thanks for the info. If you are interested in cars then make sure to checkout my website.

  74. It's very useful article with inforamtive and insightful content and i had good experience with this information.Enroll today to get free access to our live demo session which is a great opportunity to interact with the trainer directly which is a placement based Salesforce training India with job placement and certification . I strongly recommend my friends to join this Salesforce training institutes in hyderabad practical course, great curriculum Salesforce training institutes in Bangalore with real time experienced faculty Salesforce training institutes in Chennai. Never delay to enroll for a free demo at Salesforce training institutes in Mumbai who are popular for Salesforce training institutes in Pune.

  75. Mobile App Development Company Delhi: We have the Top iPhone Android app developers team, offering custom mobile app development Services in Delhi.
    mobile app development company in delhi

  76. Generous leads are cardinal for any business, this incorporates little Digital Marketing Company, medium and enormous undertakings. The ordinarily realized Digital Marketing Agency in India web-based promoting program that common computerized Digital Marketing Company in India can offer to its clients are Search Engine Optimization, Paid Marketing, Digital Marketing Company in Chennai

  77. Jungle boys is an award-winning Marijuana brand from Los Angeles. The Jungle boys farm is an authorized and licensed kush grower and distributor.
    Jungle boys also comprise of a jungle boy's clothing brand with fabrics such as hoodies, caps, t-shirts, and sucks. The Jungle boys kush strains are widespread across both Sativa, hybrid, and Indica species. Jungle boys Indica firebrands are usually recommended to patients with medical conditions such as insomnia.

    jungle boys weed
    tlc collective
    jungle boys
    pink cookies strain
    Buy seed rise with killer sunsets
    Buy jungle boys purple punchsicle
    Buy kush poppin seeds
    Buy jungle boys seed rise with killer sunsets online
    Buy jungle boys kush poppin seeds online
    Buy jungle boys kush seeds
    Buy jungle boys punch breath
    Jungle boys punch breath online
    where to buy jungle boys marijuana
    Buy Jungle boys Perfect OG
    buy jungle boys space center
    Buy Strawberry Shortcakes
    Buy jungle boys skywalker
    Buy Jungle boys Sunset Sherber
    Buy jungle boys Tk Lato
    Buy Jungle Boys Mimosa 14
    Buy citron cookie online
    Buy jungle boys Zkittlez cake
    Buy Jungle boys triangle larry
    Buy jungle boys 91 chemdawg
    Buy Jungle boys Coma online
    Buy jungle boys Valley Delight
    Buy jungle boys creamsicle
    Buy Jungle Boys Jungle Cake
    Buy jungle boys Orange Cookies
    Buy jungle boys Topanga Canyon
    Buy Wedding Crashers strain
    Buy Jungle boys Frosted Cakes
    Buy jungle boys sin mints
    Buy Jungle Boys Lava Cake
    Buy jungle boys hippy crasher
    Buy Jungle Boys Jungle Mints
    Buy Jungle Boys Motor Breath
    wedding cake strain
    The Beginning of the Jungle Boys

  78. Appslure is an award-winning mobile app development company building feature-packed and interactive mobile applications for startups, medium and large enterprises.