LEADTOOLS PDF (Leadtools.Pdf assembly)

PDFFile Constructor(String,String)

Show in webframe
Example 





The name of the file associated with this PDFFile.
The password associated with the PDF file at fileName.
Initializes a new PDFFile object and associated it with the name of a PDF file and the password used to decrypt it.
Syntax
public PDFFile( 
   string fileName,
   string password
)
'Declaration
 
Public Function New( _
   ByVal fileName As String, _
   ByVal password As String _
)
'Usage
 
Dim fileName As String
Dim password As String
 
Dim instance As New PDFFile(fileName, password)

            

            
public:
PDFFile( 
   String^ fileName,
   String^ password
)

Parameters

fileName
The name of the file associated with this PDFFile.
password
The password associated with the PDF file at fileName.
Remarks

This constructor will initialize the properties of the PDFFile object as follows:

After the file name and optional password are set, call the Load method to populate the DocumentProperties and Pages properties of this PDFFile object with the values read from the file.

In certain situation, you may want to associate a PDFFile with a Postscript and not a PDF file. For example, to create a PDFFile object and call its Distill method to convert the Postscript file to PDF.

PDF files password must be 64 ASCII characters or less. This is defined by the PDFDocument.MaximumPasswordLength constant. LEADTOOLS will automatically convert the password string to ASCII and truncate if required.

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Pdf
Imports Leadtools.WinForms

Public Sub PDFFileEncryptedExample()
   Dim pdfFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "LEAD.pdf")
   Dim pdfFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Encrypted.pdf")

   ' Create an encrypted version of LEAD.pdf
   Dim pdfFileObj As New PDFFile(pdfFileName1)
   pdfFileObj.SecurityOptions = New PDFSecurityOptions()
   pdfFileObj.SecurityOptions.UserPassword = "LEAD"
   pdfFileObj.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}\nIs 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
      pdfFileObj = New PDFFile(pdfFileName2, password)
      pdfFileObj.Load()

      Dim props As PDFDocumentProperties = pdfFileObj.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.Pdf;
using Leadtools.WinForms;

public void PDFFileEncryptedExample()
{
   string pdfFileName1 = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD.pdf");
   string pdfFileName2 = Path.Combine(LEAD_VARS.ImagesDir, @"Encrypted.pdf");

   // Create an encrypted version of LEAD.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";
}
Requirements

Target Platforms

See Also

Reference

PDFFile Class
PDFFile Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.