Leadtools.Pdfアセンブリ > Leadtools.Pdf名前空間 > PDFFileクラス > PDFFileコンストラクタ :PDFFileコンストラクタ(String、String) |
'Usage
Dim fileName As String Dim password As String Dim instance As New PDFFile(fileName, password)
このコンストラクタは、以下のようにPDFFileオブジェクトのプロパティを初期化します:
DocumentPropertiesは、nullに設定されます
ページコレクションは、nullに設定されます
ファイル名とオプションのパスワードが設定されたあと、DocumentPropertiesを値を入力するために、ロードメソッドを呼び出します、そして、値によるこのPDFFileオブジェクトのページプロパティはファイルから読みました。
特定の状況では、PostScriptとPDFファイルででなくPDFFileを関連付けたいかもしれません。たとえば、PDFFileオブジェクトを作成して、変換するために、そのDistillメソッドを呼び出すために、PostScriptはPDFにファイルします。
PDFファイルパスワードは64のASCII文字でなければならないか、より少なくなければなりません。これは、PDFDocument.MaximumPasswordLength定数によって定義されます。LEADTOOLSはASCIIにパスワードstringを自動的に変換します、そして、必要であるならば、切り捨てます。
このサンプルは、PDFファイルが暗号化されるかどうか決定して、ユーザーにパスワードを要求して、そして、それを開きます。
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Pdf Imports Leadtools.WinForms Imports Leadtools.Svg Imports Leadtools.ImageProcessing <TestMethod> _ Public Sub PDFFileEncryptedExample() Dim pdfFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf") Dim pdfFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Encrypted.pdf") ' Create an encrypted version of Leadtools.pdf Dim file As PDFFile = New PDFFile(pdfFileName1) file.SecurityOptions = New PDFSecurityOptions() file.SecurityOptions.UserPassword = "LEAD" file.Convert(1, -1, pdfFileName2) ' Now try to open it as a document Dim password As String = Nothing If PDFFile.IsEncrypted(pdfFileName2) Then Console.WriteLine("{0}" & Constants.vbLf & "Is encrypted. Enter the password:", pdfFileName2) password = Console.ReadLine() End If ' If the user entered the correct password (LEAD), you can open the file now Try file = New PDFFile(pdfFileName2, password) file.Load() Dim props As PDFDocumentProperties = file.DocumentProperties Console.WriteLine(" Title: {0}", props.Title) Console.WriteLine(" Author: {0}", props.Author) Console.WriteLine(" Subject: {0}", props.Subject) Console.WriteLine(" Keywords: {0}", props.Keywords) Console.WriteLine(" Creator: {0}", props.Creator) Console.WriteLine(" Producer: {0}", props.Producer) Console.WriteLine(" Created: {0}", props.Created) Console.WriteLine(" Modified: {0}", props.Modified) Console.WriteLine("----------:") Catch ex As Exception ' Otherwise, you will get an error that the PDF file is corrupted Console.WriteLine(ex.Message) End Try End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.Controls; using Leadtools.Drawing; using Leadtools.ImageProcessing; using Leadtools.Pdf; using Leadtools.Svg; using Leadtools.WinForms; [TestMethod] public void PDFFileEncryptedExample() { string pdfFileName1 = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); string pdfFileName2 = Path.Combine(LEAD_VARS.ImagesDir, @"Encrypted.pdf"); // Create an encrypted version of Leadtools.pdf PDFFile file = new PDFFile(pdfFileName1); file.SecurityOptions = new PDFSecurityOptions(); file.SecurityOptions.UserPassword = "LEAD"; file.Convert(1, -1, pdfFileName2); // Now try to open it as a document string password = null; if (PDFFile.IsEncrypted(pdfFileName2)) { Console.WriteLine("{0}\nIs encrypted. Enter the password:", pdfFileName2); password = Console.ReadLine(); } // If the user entered the correct password (LEAD), you can open the file now try { file = new PDFFile(pdfFileName2, password); file.Load(); PDFDocumentProperties props = file.DocumentProperties; Console.WriteLine(" Title: {0}", props.Title); Console.WriteLine(" Author: {0}", props.Author); Console.WriteLine(" Subject: {0}", props.Subject); Console.WriteLine(" Keywords: {0}", props.Keywords); Console.WriteLine(" Creator: {0}", props.Creator); Console.WriteLine(" Producer: {0}", props.Producer); Console.WriteLine(" Created: {0}", props.Created); Console.WriteLine(" Modified: {0}", props.Modified); Console.WriteLine("----------:"); } catch (Exception ex) { // Otherwise, you will get an error that the PDF file is corrupted Console.WriteLine(ex.Message); } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }