Click here to Skip to main content
13,046,464 members (72,416 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I need to convert encrypted pdf->text with the password given by the user.

IN C++

I am able to open(unencrypted) pdf by using VC++ using zlib.
I am opening pdf in 'rb' mode

Do I need to write a custom function to decrypt stream by the given password ?

[STATUS: code working for unencrypted PDF ]


I have found code in java which do PDF to Text extraction by using PDFBox-0.7.3, but have some issues with the code.
There is a null pointer exception at PDFBox-0.7.3\src\org\pdfbox\

 AccessPermission ap = document.getCurrentAccessPermission();  
if (!ap.canExtractContent())[^]

[STATUS: code just creates empty file ]

Am I doing extraction of the pdf in wrong way ?
What can be the correct steps to decrypt PDF ?
Posted 22-Mar-11 19:19pm
Updated 24-Mar-11 3:36am
Dalek Dave433.3K
Richard MacCutchan 23-Mar-11 5:05am
So what is your problem? Have you checked the zlib documentation?
01.mandar 24-Mar-11 8:53am
user inputs are pdf path ,password ,txt file
i need to decrypt pdf by user password
how to decrypt stream ?
will inflate() versions be useful

is above possible to do in zilb?
Richard MacCutchan 24-Mar-11 11:40am
I think you may be looking at this from the wrong point of view. You need to find a library that can handle encrypted PDF files. I am not certain, but I do not think you can just read it as a stream and pass it through a decryption process.
HimanshuJoshi 23-Mar-11 15:46pm
Edited to remove unnecessary bold tag.
Dalek Dave 24-Mar-11 9:37am
Edited for Grammar and Readability.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You either:

(the fast route)
  • Use a library (free or commercial). As already suggested, Google would help you finding it


(the 'scenic' route)
  • Study the PDF specifications (freely available) and write your own code to do the job.
01.mandar 24-Mar-11 9:02am
i have seen 2 library
zlib in c++
Pdfbox in java
coding for both mostly work on unencrypted pdf
my difficult is the pdf encryption
it just creates blank txt file when encrypted pdf is passed
Dalek Dave 24-Mar-11 9:38am
Good Call.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It sounds like what you need is an SDK that has APIs to allow you to open and extract text from a PDF file. I'm sure you will find lots by googling 'PDF SDK'.
01.mandar 24-Mar-11 9:08am
i have seen some pdf sdk but they are mostly in .NET or for trial/demo basis
i will continue looking more for c++ or java

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Mar 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100