←Select platform

GetPDFFileType Method

Summary
Gets the type of a PDF or Postscript file.
Syntax
C#
C++/CLI
Java
Python
public static PDFFileType GetPDFFileType( 
   string fileName, 
   bool pdfTypesOnly 
) 
public static PDFFileType getPDFFileType( 
   java.lang.String fileName, 
   boolean pdfTypesOnly 
); 
public: 
static PDFFileType GetPDFFileType(  
   String^ fileName, 
   bool pdfTypesOnly 
)  
def GetPDFFileType(self,fileName,pdfTypesOnly): 

Parameters

fileName
The name of the PDF or Postscript file.

pdfTypesOnly
true to recognize only PDF files (Postscript files will not be recognized), and PDFFileType.Unknown will be returned when  fileName is a PS or EPS file. false to recognize both PDF and PS files.

Return Value

An PDFFileType enumeration member that specifies the type of the file. If the file is not PDF (or Postscript depending on  pdfTypesOnly), then PDFFileType.Unknown is returned.

Remarks

The Load method will internally call GetPDFFileType with  pdfTypesOnly set to true before loading the file properties.

Generally, when loading PDF files call GetPDFFileType first to determine whether the file provided by the user is a valid PDF. After that, it is best to call IsEncrypted to determine whether the file is encrypted and ask the user for a password before loading the file.

Example
C#
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Controls; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.Pdf; 
using Leadtools.Svg; 
 
 
public void PDFCompatibilityLevelExample() 
{ 
   string sourceFileName = Path.Combine(LEAD_VARS.ImagesDir, @"Leadtools.pdf"); 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, @"LEAD_14.pdf"); 
 
   // Check the version of the source file 
   PDFFileType fileType = PDFFile.GetPDFFileType(sourceFileName, true); 
   if (fileType == PDFFileType.Unknown) 
   { 
      Console.WriteLine("Not a valid PDF file"); 
      return; 
   } 
 
   if (fileType == PDFFileType.PDF14) 
   { 
      Console.WriteLine("Is PDF 1.4 already"); 
      return; 
   } 
 
   // Not PDF 1.4, convert 
   Console.WriteLine("Converting to PDF 1.4"); 
   PDFFile file = new PDFFile(sourceFileName); 
   file.CompatibilityLevel = PDFCompatibilityLevel.PDF14; 
   file.Convert(1, -1, destFileName); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

See Also

Reference

PDFFile Class

PDFFile Members

Help Version 22.0.2023.7.10
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.