Click here to Skip to main content
Licence CPOL
First Posted 4 Dec 2008
Views 30,364
Downloads 747
Bookmarked 65 times

PDF Security Remover

By | 4 Dec 2008 | Article
Remove security from PDF files.

Introduction

This tool allows you to remove the "security" from a PDF File. It has not been widely tested, but has worked on any PDF file that was marked Secure that I was able to open without a password.

Why would you want to do this? Many secure PDF files are set so that you can not copy text from them or print them. This can be really frustrating at times, especially when you are studying the material and you want to put together a study sheet, or something to that effect.

Background

A while back, I purchased an exam study guide, which came with a companion CD containing the book in PDF format. Unfortunately, the file was marked as secure, so when I tried to copy out the "Suggested Practices" section from each chapter, I was not able to, nor could I print any of the pieces. This led me to develop this very small application.

Using the code

The tool is very simple. I use the PDFSharp library to read in the original PDF. I then copy each page to a new PDF file and save it.

Private Sub Form1_Load(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MyBase.Load
    'Show open file dialog box,
    'this is where you choose what file to load
    Dim ofd As New OpenFileDialog()
    'if you say OK, then continue
    If ofd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
        Exit Sub
    End If

    'import document using PDFSharp
    Dim maindoc As PdfDocument = PdfReader.Open(ofd.OpenFile(), _
                                 PdfDocumentOpenMode.Import)

    'Create the Output Document as a new PDF Document
    Dim OutputDoc As PdfDocument = New PdfDocument()

    'Copy over pages from original document
    For Each page As PdfPage In maindoc.Pages
        OutputDoc.AddPage(page)
    Next

    'Show the Save File Dialog box
    Dim sfd As New SaveFileDialog()
    'if user clicks ok then continue, else dispose objects
    If sfd.ShowDialog() <> Windows.Forms.DialogResult.OK Then
        maindoc.Dispose()
        OutputDoc.Dispose()
        Exit Sub
    End If

    'save new document
    OutputDoc.Save(sfd.OpenFile(), True)
    'dispose of objects
    maindoc.Dispose()
    OutputDoc.Dispose()
    'close the form
    Me.Close()
End Sub

Points of interest

I thought it was funny how easy it was to do this. I expected something a little more complicated, though if it had been, I probably would have just given up on it.

History

  • Version 1.0 - Initial release.

License

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

About the Author

Patricker

Web Developer

United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmembermanoj kumar choubey0:45 10 May '12  
GeneralInteresting Topic. PinmemberChris Meech2:57 24 Nov '10  
GeneralMy vote of 5 PinmemberHeaven202011:14 3 Nov '10  
GeneralThanksssss Pinmembergaandkaisshi22:10 3 Jun '09  
GeneralMy Vote of 5 Pinmemberthund3rstruck4:51 8 Jan '09  
GeneralProblem running executable Pinmemberserbach3:48 12 Dec '08  
I ran the release version of the your executable and got a .NET Framework error: "Cannot handle iref streams. The current implementation of PDFSharp cannot handle this PDF feature introduced with Acrobat 6." The document is Acrobat version 7.
 
Not really an issue for me, but I was curious whether it would actually work. I tried it on a very long PDF document (1100 pages). I, too, was looking for a way to quote passages.
 
Steve Erbach
Neenah, WI
http://www.TheTownCrank.com
GeneralRe: Problem running executable PinmemberPatricker5:13 12 Dec '08  
GeneralMy vote of 1 PinmemberGiri Ganji19:00 8 Dec '08  
GeneralRe: My vote of 1 PinmemberLloyd Atkinson2:45 3 Dec '10  
GeneralStrips bookmarks Pinmemberccfoo2425:07 5 Dec '08  
GeneralRe: Strips bookmarks PinmemberPatricker13:11 5 Dec '08  
GeneralI think this tool is great. Pinmembershogunz0r20:35 4 Dec '08  
GeneralCopyright violation Pinmemberhaathi12:31 4 Dec '08  
GeneralRe: Encouraging Copyrights Violation ? PinPopularmemberPatricker15:14 4 Dec '08  
GeneralRe: Encouraging Copyrights Violation ? Pinmemberfaulty21:04 4 Dec '08  
GeneralMy vote of 1 Pinmemberhaathi12:29 4 Dec '08  
GeneralRe: My vote of 1 PinmemberMatware17:33 11 Dec '08  
GeneralRe: My vote of 1 PinmemberTim Cabrera17:26 21 Jun '09  
GeneralRe: My vote of 1 PinmemberLloyd Atkinson2:48 3 Dec '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 4 Dec 2008
Article Copyright 2008 by Patricker
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid