Word OLE (Delphi PDF) - SDK sample

Download Sample
Download size: 42.0KB
[Format: ZIP]
Note: To be able to use the samples you must install novaPDF SDK as samples work only with it. Download it here: nova PDF SDK.

The Word OLE (Delphi PDF) sample is a simple Windows console application that converts a MS Word document (C:\Test.doc) to PDF using Word OLE automation.

Sample Code:

program WordOLEDelphi; 

 

uses
ActiveX,
Printers,
ComObj,
SysUtils,
Dialogs,
novaOptions,
novapiLIB_TLB; 

const 

//name of novaPDF Printer
PRINTER_NAME    = 'novaPDF Pro v5'; 

//Print profile name
PROFILE_NAME    = 'Test OLE Delphi Profile';
PROFILE_IS_PUBLIC = 0; 

var
hr : HRESULT;
pNova : INovaPdfOptions;
strDefaultProfile : WideString;
Word : VARIANT;
NewDoc : VARIANT;
bPublicProfile: Integer; 

begin 

//initialize COM
hr := ActiveX.CoInitialize(nil);
if (FAILED (hr)) then begin
  System.Writeln('Failed to initialize COM');
  exit;
end; 

//create one NovaPdfOptions instance
pNova := nil;
hr := ActiveX.CoCreateInstance(
            CLASS_NovaPdfOptions, //CLSID_CNovaPdfSource,
            nil,
            CLSCTX_INPROC_SERVER,
            IID_INovaPdfOptions,
            pNova);
if (FAILED(hr))   then begin
  System.Writeln('Failed to create novaPDF COM object');
  exit;
end; 

//initialize NovaPdfOptions and pass printer name
//if you have an application license for novaPDF SDK,
//pass both the registration name and the license key to the Initialize2() function
//hr := pNova.Initialize2( PRINTER_NAME, '<registration name>', '<license key>');
hr := pNova.Initialize2( PRINTER_NAME, '', '', '' ); 

if (SUCCEEDED(hr)) then begin 

  pNova.SetDefaultPrinter();
 // now the default printer is novaPDF printer but the Printer object is not updated
  // here is a workaround to update the Printer object with the default printer
  // you only need this code if you check later on the Printer.PrinterIndex to find out the default printer
  //Printer.GetPrinter(Device, Driver, Port, DevMode);
  //Printer.SetPrinter(PRINTER_NAME, Driver, Port, 0); 

  // set optional PDF settings
  // create a temporary profile for the current print job,
  // in order to not modify the default profile settings
  pNova.AddProfile2(PROFILE_NAME, PROFILE_IS_PUBLIC);
  // set PDF document Title
  pNova.SetOptionString2(NOVAPDF_INFO_TITLE,
                         'Hello World Delphi Sample', PROFILE_NAME, PROFILE_IS_PUBLIC);
  // set resulting file name
  pNova.SetOptionString2(NOVAPDF_SAVE_FOLDER, 'C:\', PROFILE_NAME, PROFILE_IS_PUBLIC);
  //do not show prompt dialog
  pNova.SetOptionLong2(NOVAPDF_SAVE_PROMPT, 0, PROFILE_NAME, PROFILE_IS_PUBLIC);
  //if file exists, override
  pNova.SetOptionLong2(NOVAPDF_SAVE_CONFLICT_STRATEGY,
                       FILE_CONFLICT_STRATEGY_OVERWRITE,
                       PROFILE_NAME, PROFILE_IS_PUBLIC);
  //open document in PDF viewer
  pNova.SetOptionLong2(NOVAPDF_ACTION_OPEN_DOCUMENT, 1, PROFILE_NAME, PROFILE_IS_PUBLIC);
  // set active profile
  strDefaultProfile := '';
  pNova.GetActiveProfile2(strDefaultProfile, bPublicProfile);
  pNova.SetActiveProfile2(PROFILE_NAME, PROFILE_IS_PUBLIC); 

  //Print Word Document
  try
    pNova.InitializeOLEUsage('Word.Application');
    Word := CreateOleObject('Word.Application');
    Word.DisplayAlerts := 0;
    pNova.LicenseOLEServer();
    NewDoc:= Word.Documents.Open('C:\Test.doc', False, True);
    NewDoc.PrintOut(False);
    NewDoc.Close(False);
    Word.Quit(False);
  except
    on E: Exception do
      ShowMessage(E.Message);
  end; 

  //restore default profile
  pNova.SetActiveProfile2(strDefaultProfile, bPublicProfile);
  pNova.DeleteProfile2(PROFILE_NAME, PROFILE_IS_PUBLIC);
  //restore default printer
  pNova.RestoreDefaultPrinter();
end else begin
  System.Writeln('Failed to initialize novaPDF Printer');
end; 

ActiveX.CoUninitialize(); 

end.

© 2002-2008 Softland. All Rights Reserved.
PDF Creator novaPDF
Create PDF for your paperless office
home Home   contact usContact us   partnershipsPartnerships   bookmarkBookmark   Site updated: 14-August-2008
Downloads Download Now

Download, install and use novaPDF. Latest version: 5.4 build 270

Download PDF creator
promotionsSpecial Offers

Current discounts:
- up to 25% for Desktop Editions
- up to 25% for Server Editions
- 20% Academic Discount
- up to 16% for Developer Tools

buyBuy Now
Professional edition $39.95
(Save $10)
Standard edition $29.95
(Save $10)
Lite edition $19.95
(Save $5)
Buy Now
newsLatest News

novaPDF 5.4 released
February 11, 2008

What’s new (read more):
 » Added Copy Text/Image Watermarks dialog
 » Added "Lookup Address" option when sending emails
 » Corrected rotated and vertical texts conversion
 » Corrected conversion from WordArt, MS Word backgrounds and MS Visio drawings
 » Uninstaller deletes now the driver files

sdkDeveloper Tools

novaPDF SDK is a software development toolkit that can be used by software developers and programmers to add the ability to create PDF files in their applications.
novaPDF OEM is a PDF solution that programmers can use to generate PDF files that will be post-processed by their applications. […]

Reviews & User QuotesPDF Creator Reviews
"novaPDF is a really neat tool. Basically, it’s a PDF printer driver that prints to a PDF file instead of paper.
See more reviews about nova PDF
[…] novaPDF is a great product that works without forcing the user to configure anything. The convenience alone is worth the money." […]
Jason Pullara, Editor
Currently supported languagesLanguages

News:
- Norwegian language added.

Help us translate novaPDF and we will give you licenses for novaPDF Professional and mention you on the Languages page. […]

awardsAwards

novaPDF received the Editor’s Pick from Soft32, a major download site:

PDF creator reviews

See the Awards page for more ratings.

NewsletterKnowledgebase articles

Latest articles on how to:
 » Create PDF files
 » Convert JPG to PDF
 » Convert Powerpoint to PDF
 » Convert Publisher to PDF
 » Convert web pages to PDF
Full article list in the knowledgebase.