Visual Basic 9 (2008)Visual Basic 8 (2005).NET 3.0.NET 2.0.NET 3.5Windows Forms初学者.NETVisual BasicASP.NET
PDF 安全移除器
移除 PDF 文件的安全设置。
引言
这个工具可以移除 PDF 文件的“安全”设置。它没有经过广泛的测试,但对于所有我能够打开的、被标记为安全的 PDF 文件都有效(无需密码)。
为什么要这样做?许多安全的 PDF 文件设置了不允许复制文本或打印的功能。这有时会非常令人沮丧,尤其是在学习材料时,你想整理一份学习资料等等。
背景
前段时间,我购买了一本考试复习指南,随附一张包含书籍 PDF 格式的配套光盘。不幸的是,该文件被标记为安全,当我尝试从每个章节中复制“建议实践”部分时,我无法做到,也无法打印任何内容。这促使我开发了这个非常小的应用程序。
使用代码
这个工具非常简单。我使用 PDFSharp 库读取原始 PDF。然后,我将每一页复制到一个新的 PDF 文件并保存它。
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
关注点
我觉得能够做到这一点非常容易,有点出乎意料。如果它更复杂,我可能就会放弃了。
历史
- 版本 1.0 - 初始发布。