Automatic Conversion from PDF to JPG

Universal Document Converter allows saving any type of a document as a PDF, JPEG, TIFF, or PNG image file. Software developers can benefit from the Universal Document Converter resources using the COM-interface with Adobe Acrobat as COM-server for converting PDF to JPG.

PDF conversion source code examples:

Visual Basic.NET

VB.NET PDF to JPG conversion code example:

'----------------------------------------------------------------------
' 1) Adobe Acrobat version 4.0 or higher should be installed and activated on your PC.
'    Please note that Adobe Acrobat Reader does not have COM interface and
'    cannot be used as COM-server!
'
' 2) Universal Document Converter version 5.2 or higher should be installed as well.
'
' 3) Open your project in Microsoft Visual Basic.NET.
'
' 4) In the Visual Basic main menu press Project->Add Reference...
'
' 5) In Add Reference window go to COM tab and double click on 
'    Universal Document Converter Type Library
'----------------------------------------------------------------------

Private Sub PrintAdobePDFToJPEG(ByVal strFilePath As String)

    Dim objAdobeApp As Object
    Dim itfAVDocument As Object
    Dim itfPDDocument As Object
    Dim nPages As Long

    Dim objUDC As UDC.IUDC
    Dim itfPrinter As UDC.IUDCPrinter
    Dim itfProfile As UDC.IProfile
    
    Dim AppDataPath As String
    Dim ProfilePath As String       

    ' Use Universal Document Converter API to change settings of converterd document
    objUDC = New UDC.APIWrapper
    itfPrinter = objUDC.Printers("Universal Document Converter")
    itfProfile = itfPrinter.Profile

    ' Adobe Acrobat API allow to print only on the default printer
    objUDC.DefaultPrinter = "Universal Document Converter"

    ' Load profile located in folder "%APPDATA%\UDC Profiles".
    ' Value of %APPDATA% variable should be received using Environment.GetFolderPath
    ' method. Or you can move default profiles into a folder you prefer.
    AppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
    ProfilePath = Path.Combine(AppDataPath, "UDC Profiles\PDF to JPEG.xml")            
    itfProfile.Load(ProfilePath)

    itfProfile.OutputLocation.Mode = UDC.LocationModeID.LM_PREDEFINED
    itfProfile.OutputLocation.FolderPath = "C:\Out"

    itfProfile.PostProcessing.Mode = UDC.PostProcessingModeID.PP_OPEN_FOLDER

    ' Run Adobe Acrobat as COM-server
    On Error Resume Next
    objAdobeApp = CreateObject("AcroExch.App")
    itfAVDocument = CreateObject("AcroExch.AVDoc")

    ' Open PDF document from file
    If itfAVDocument.Open(strFilePath, "") = True Then

        itfPDDocument = itfAVDocument.GetPDDoc()
        nPages = itfPDDocument.GetNumPages()

        ' Print all pages of the document
        Call itfAVDocument.PrintPagesSilent(0, nPages - 1, 0, True, True)

        ' Close the document
        Call itfAVDocument.Close(True)
        itfAVDocument = Nothing
        itfPDDocument = Nothing

    End If

    ' Close Adobe Acrobat Writer
    Call objAdobeApp.Exit()
    objAdobeApp = Nothing

End Sub

Visual Basic 6

VB PDF to JPG conversion code example:

'----------------------------------------------------------------------
' 1) Adobe Acrobat version 4.0 or higher should be installed and activated on your PC.
'    Please note that Adobe Acrobat Reader does not have COM interface and
'    cannot be used as COM-server!
'
' 2) Universal Document Converter 5.2 or above should be installed as well
'
' 3) Open your project in Microsoft Visual Basic 6.0.
'
' 4) In Visual Basic main menu press Project->References
'
' 5) In the list of references check Universal Document Converter Type Library
'----------------------------------------------------------------------

Private Sub PrintAdobePDFToJPEG(strFilePath As String)

  Dim objAdobeApp As Object
  Dim itfAVDocument As Object
  Dim itfPDDocument As Object
  Dim nPages As Long

  Dim objUDC As IUDC
  Dim itfPrinter As IUDCPrinter
  Dim itfProfile As IProfile

' Use Universal Document Converter API to change settings of converterd document
  Set objUDC = New UDC.APIWrapper
  Set itfPrinter = objUDC.Printers("Universal Document Converter")
  Set itfProfile = itfPrinter.Profile
  
' Adobe Acrobat API allow to print only on the default printer
  objUDC.DefaultPrinter = "Universal Document Converter"

' Load profile located in folder "%APPDATA%\UDC Profiles".
' Value of %APPDATA% variable should be received using Windows API's
' SHGetSpecialFolderPath function. Or you can move default profiles into a
' folder you prefer.

  itfProfile.Load("PDF to JPEG.xml")
  
  itfProfile.OutputLocation.Mode = LM_PREDEFINED
  itfProfile.OutputLocation.FolderPath = "C:\Out"
  
  itfProfile.PostProcessing.Mode = PP_OPEN_FOLDER

' Run Adobe Acrobat as COM-server
  On Error Resume Next
  Set objAdobeApp = CreateObject("AcroExch.App")
  Set itfAVDocument = CreateObject("AcroExch.AVDoc")
    
  ' Open PDF document from file
  If itfAVDocument.Open(strFilePath, "") = True Then
  
    Set itfPDDocument = itfAVDocument.GetPDDoc()
    nPages = itfPDDocument.GetNumPages()
       
  ' Print all pages of the document
    Call itfAVDocument.PrintPagesSilent(0, nPages - 1, 0, True, True)

  ' Close the document
    Call itfAVDocument.Close(True)
    Set itfAVDocument = Nothing
    Set itfPDDocument = Nothing
    
  End If
    
' Close Adobe Acrobat Writer
  Call objAdobeApp.Exit
  Set objAdobeApp = Nothing

End Sub

Visual C++

C++ PDF to JPG conversion code example

//////////////////////////////////////////////////////////////////
// This example was designed to be used in Microsoft Visual C++ from 
// Microsoft Visual Studio version 2003 or higher.
//
// 1. Adobe Acrobat version 4.0 or higher should be installed and activated on your PC.
//    Please note that Adobe Acrobat Reader does not have COM interface and
//    cannot be used as COM-server!
//
// 2. Universal Document Converter version 5.2 or higher should be installed as well.
//
// 3. You must initialize the COM before you call any COM method.
// Please insert ::CoInitialize(0); in your application initialization
// and ::CoUninitialize(); before closing it.
//
// 4. Import Acrobat libraries for 32-bit version of Windows.
// For 64-bit version please change C:\\Program Files\\ to
// C:\\Program Files (x86)\\ in all paths.

#pragma message("Import Acrobat API")
// Acrobat 4.0 -> "C:\\Program Files\\Adobe\\Acrobat 4.0\\Acrobat\\acrobat.tlb"
// Acrobat 5.0 -> "C:\\Program Files\\Adobe\\Acrobat 5.0\\Acrobat\\acrobat.tlb"
// Acrobat 6.0 -> "C:\\Program Files\\Adobe\\Acrobat 6.0\\Acrobat\\acrobat.tlb"
// Acrobat 7.0 -> "C:\\Program Files\\Adobe\\Acrobat 7.0\\Acrobat\\acrobat.tlb"
// Acrobat 8.0 -> "C:\\Program Files\\Adobe\\Acrobat 8.0\\Acrobat\\acrobat.tlb"
// Acrobat 9.0 -> "C:\\Program Files\\Adobe\\Acrobat 9.0\\Acrobat\\acrobat.tlb"
#import "C:\\Program Files\\Adobe\\Acrobat 4.0\\Acrobat\\acrobat.tlb"\
    rename_namespace("ACROBAT"), auto_rename

// 5. Import Universal Document Converter software API:
#import "progid:udc.apiwrapper" rename_namespace("UDC")
//////////////////////////////////////////////////////////////////

void PrintAdobePDFToJPEG( CString sFilePath )
{
  UDC::IUDCPtr pUDC(__uuidof(UDC::APIWrapper));
  UDC::IUDCPrinterPtr itfPrinter = pUDC->Printers["Universal Document Converter"];
  UDC::IProfilePtr itfProfile = itfPrinter->Profile;

// Adobe Acrobat API allow to print only on the default printer
  pUDC->DefaultPrinter = "Universal Document Converter";

// Use Universal Document Converter API to change settings of converterd document

// Load profile located in folder "%APPDATA%\UDC Profiles".
// Value of %APPDATA% variable should be received using Windows API's
// SHGetSpecialFolderPath function. Or you can move default profiles
// into a folder you prefer.

  itfProfile->Load("PDF to JPEG.xml");
 
  itfProfile->OutputLocation->Mode = UDC::LM_PREDEFINED;
  itfProfile->OutputLocation->FolderPath = L"C:\\Out";

  itfProfile->PostProcessing->Mode = UDC::PP_OPEN_FOLDER;

// Run Adobe Acrobat as COM-server
  ACROBAT::CAcroAppPtr itfAdobeApp(L"AcroExch.App");
  ACROBAT::CAcroAVDocPtr itfAVDocument(L"AcroExch.AVDoc");
  ACROBAT::CAcroPDDocPtr itfPDDocument;
  int nPages;

// Open PDF document from file
  itfAVDocument->Open( (LPCTSTR)sFilePath, _T("") );
  itfPDDocument = itfAVDocument->GetPDDoc();

  nPages = itfPDDocument->GetNumPages();

// Print all pages of the document
  itfAVDocument->PrintPagesSilent(0, nPages - 1, 0, true, true);

// Close the document
  itfAVDocument->Close(true);

// Close Adobe Acrobat Writer
  itfAdobeApp->Exit();
}

Visual C#

C# PDF to JPG conversion code example

///////////////////////////////////////////////////////////////////////////////////// // This example was designed to be used in Microsoft Visual C# from // Microsoft Visual Studio version 2003 or higher. // // 1. Adobe Acrobat version 6.0 or higher should be installed and activated on your PC. // Please note that Adobe Acrobat Reader does not have COM interface // and cannot be used as COM-server! // // 2. Universal Document Converter version 5.2 or higher should be installed as well. // // 3. Add references to Adobe Acrobat X.0 Type Library and // Universal Document Converter Type Library // using the Project | Add Reference menu > COM tab. // The version number in the type library name may be different depending on // the Acrobat version installed on your computer. ///////////////////////////////////////////////////////////////////////////////////// using System; using System.IO; using UDC; using Acrobat; namespace PDFtoJPEG { class Program { static void PrintPDFtoJPEG(string PDFFilePath) { //Create a UDC object and get its interfaces IUDC objUDC = new APIWrapper(); IUDCPrinter Printer = objUDC.get_Printers("Universal Document Converter"); IProfile Profile = Printer.Profile; //Adobe Acrobat API allow to print only on the default printer objUDC.DefaultPrinter = "Universal Document Converter"; //Use Universal Document Converter API to change settings of converterd //document //Load profile located in folder "%APPDATA%\UDC Profiles". //Value of %APPDATA% variable should be received using //Environment.GetFolderPath method. //Or you can move default profiles into a folder you prefer. string AppDataPath = Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData); string ProfilePath = Path.Combine(AppDataPath, @"UDC Profiles\PDF to JPEG.xml"); Profile.Load(ProfilePath); Profile.OutputLocation.Mode = LocationModeID.LM_PREDEFINED; Profile.OutputLocation.FolderPath = @"c:\UDC Output Files"; Profile.PostProcessing.Mode = PostProcessingModeID.PP_OPEN_FOLDER; AcroApp AcroApp = new AcroAppClass(); AcroAVDoc AVDoc = new AcroAVDocClass(); //Open PDF document from file AVDoc.Open(PDFFilePath, ""); AcroPDDoc PDDoc = (AcroPDDoc)AVDoc.GetPDDoc(); int nPages = PDDoc.GetNumPages(); //Print all pages of the document int nPSLevel = 0; int bBinaryOk = 1; //true int bShrinkToFit = 1; //true AVDoc.PrintPagesSilent(0, nPages - 1, nPSLevel, bBinaryOk, bShrinkToFit); //Close the document int bNoSave = 1; AVDoc.Close(bNoSave); //Close Acrobat AcroApp.Exit(); } static void Main(string[] args) { string TestFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestFile.pdf"); PrintPDFtoJPEG(TestFilePath); } } }

Delphi

Delphi PDF to JPG conversion code example:

//////////////////////////////////////////////////////////////////////////////////// // This example was designed to be used in Delphi 7 or higher. // // 1. Adobe Acrobat version 4.0 or higher should be installed and activated on your PC. // Adobe Acrobat Reader does not have COM interface and cannot be used as COM-server // // 2. Universal Document Converter version 5.2 or higher should be installed as well // // 3. Add Universal Document Converter Type Library and // Adobe Acrobat XX.0 Type Library type libraries to the project. // XX is the Adobe Acrobat version installed on your computer. // // Delphi 7: // Use the Project | Import Type Library menu. // // Delphi 2006 or latter: // Use the Component | Import Component menu. // // Clear the Generate Component Wrapper checkbox and click the Create Unit // button (Delphi 7) or select the Create Unit option (Delphi 2006 or latter). // //////////////////////////////////////////////////////////////////////////////////// program PDFToJPEG; {$APPTYPE CONSOLE} uses SysUtils, Variants, Windows, Dialogs, ActiveX, ComObj, UDC_TLB, Acrobat_TLB; procedure PrintPDFtoJPEG(PDFFilePath: string); var objUDC: IUDC; Printer: IUDCPrinter; Profile: IProfile; AcroApp: Variant; AVDoc: Variant; PDDoc: Variant; nPages: Integer; nPSLevel, bBinaryOk, bShrinkToFit, bNoSave: Integer; begin //Create a UDC object and get its interfaces objUDC := CoAPIWrapper.Create; Printer := objUDC.get_Printers('Universal Document Converter'); Profile := Printer.Profile; //Adobe Acrobat API allow to print only on the default printer objUDC.DefaultPrinter := 'Universal Document Converter'; //Use Universal Document Converter API to change settings of converterd document //Load profile located in folder "%APPDATA%\UDC Profiles". //Value of %APPDATA% variable should be received using Windows API's // SHGetSpecialFolderPath or JCL's JclSysInfo.GetAppdataFolder function. //Or you can move default profiles into a folder you prefer. Profile.Load('PDF to JPEG.xml'); Profile.OutputLocation.Mode := LM_PREDEFINED; Profile.OutputLocation.FolderPath := 'c:\UDC Output Files'; Profile.PostProcessing.Mode := PP_OPEN_FOLDER; AcroApp := CreateOleObject('AcroExch.App'); AVDoc := AcroApp.GetActiveDoc; //Open PDF document from file AVDoc.Open(PDFFilePath, ''); PDDoc := AVDoc.GetPDDoc; nPages := PDDoc.GetNumPages; //Print all pages of the document nPSLevel := 0; bBinaryOk := 1; //true bShrinkToFit := 1; //true AVDoc.PrintPagesSilent(0, nPages - 1, nPSLevel, bBinaryOk, bShrinkToFit); //Close the document bNoSave := 1; AVDoc.Close(bNoSave); //Close Acrobat AcroApp.Exit; end; var TestFilePath: string; begin TestFilePath := ExtractFilePath(ParamStr(0)) + 'TestFile.pdf'; try CoInitialize(nil); try PrintPDFtoJPEG(TestFilePath); finally CoUninitialize; end; except on E: Exception do MessageDlg(E.ClassName + ' : ' + E.Message, mtError, [mbOK], 0); end; end.

PHP

PHP PDF to JPG conversion code example:

'----------------------------------------------------------------------
' 1) Adobe Acrobat Writer 4.0 or above should be installed and activated on your PC.
'    
' 2) Universal Document Converter 5.2 or above should also be installed.
'
' 3) Apache WEB server and PHP 4.0 or above should be installed and adjusted.
'----------------------------------------------------------------------

 <?PHP  
	
  //Create Universal Document Converter object 
	
  $objUDC = new COM("UDC.APIWrapper");
	
  //Set up Universal Document Converter 
		
  $itfPrinter = $objUDC->Printers("Universal Document Converter");
		
  $itfProfile = $itfPrinter->Profile;
		
  $itfProfile->PageSetup->ResolutionX = 300;
  $itfProfile->PageSetup->ResolutionY = 300;
  $itfProfile->PageSetup->Orientation = 0;
  $itfProfile->PageSetup->Units = 1;
  $itfProfile->PageSetup->Width = 220;
  $itfProfile->PageSetup->Height = 180;
	
  $itfProfile->FileFormat->ActualFormat = 2;
  $itfProfile->FileFormat->JPEG->ColorSpace = 24;
  $itfProfile->FileFormat->JPEG->Mode = 0;
  $itfProfile->FileFormat->JPEG->Quality = 50;
		
  $itfProfile->OutputLocation->Mode = 1;
  $itfProfile->OutputLocation->FolderPath = '&[Documents]\UDC Output Files\\';
  $itfProfile->OutputLocation->FileName = '&[DocName(0)].&[ImageType]';
  $itfProfile->OutputLocation->OverwriteExistingFile = 0;
	
  $itfProfile->Adjustments->Crop->Mode = 0;
		
  $itfProfile->PostProcessing->Mode = 0;
	
  //Create Adobe Acrobat object and open the file	
		
  $file = 'my_document.pdf';
	
  $AdobeApp = new COM("AcroExch.App");
  $AVDocument = new COM("AcroExch.AVDoc");
	
  $AVDocument->Open($file, 0);
	
  //Printing 	
	
  $AVDocument->PrintPagesSilent(0,0,0,0,1);
	
  //Close the document 
	
  $AVDocument->Close(1);
	
  //Close Adobe acrobat 
	
  $AdobeApp->Exit();
			
  echo "READY!";
 ?> 
Convert PDF to JPG

  • Mitsuharu Shibata

    Japan

    «I am very good at commanding PC, but other company employees can use a PC a little. I can set rules to the files on server like adding the date, and the name and so on. Everyone can convert documents with the same format following my rule.»