Neevia Technology Sites:   www.neevia.com  |  docuPub.com  |  www.neeviaPDF.com
:: Home :: Products :: Technical Support :: About Us :: Contact Us
Technical support > Neevia docCreator code samples
Example 1: How to create a simple PDF file from Delphi  Print Example 


procedure createPDF();
var
  I : Integer;
  DC : Variant;
  RVal : Integer;
  OldIndex : Integer;
  printerIndex : Integer;
begin
   DC := CreateOleObject('Neevia.docCreator');

   RVal := DC.startPrinting;
   if (RVal <> 0) then
   begin
      ShowMessage('Error while calling startPrinting method!!!');
      Exit;
   end;

   OldIndex := Printer.PrinterIndex;
   printerIndex := -1;
   Printer.Refresh;
   for I:=0 to Printer.Printers.Count-1 do
   begin
     if (CompareText(Printer.Printers.Strings[i],DC.NewPrinterName)=0) then
     begin
       printerIndex := I;
       Printer.PrinterIndex := printerIndex;
       break;
     end;
   end;

   if printerIndex=-1 then
   begin
     ShowMessage('Printer not found!!!');
     DC.stopPrinting;
     Exit;
   end
    else
   Printer.PrinterIndex := printerIndex;

   DC.setParameter('DocumentOutputFormat', 'PDF');
   DC.setParameter('DocumentOutputName', 'testDelphi');
   DC.setParameter('DocumentOutputFolder', 'd:\');

   Printer.Title := 'Hello !';
   Printer.BeginDoc;
   Printer.Canvas.Font.Name := 'Times New Roman';
   Printer.Canvas.Font.Size := 48;
   Printer.Canvas.TextOut(0,0,'Hello from Delphi!!!');
   Printer.EndDoc;

   RVal := DC.create; // Create output document
   if (RVal <> 0) then
      ShowMessage('Error while creating document!!!')
   else
      ShowMessage('Done !!!');

   Printer.PrinterIndex := OldIndex;

   RVal := DC.stopPrinting;
   if (RVal <> 0) then ShowMessage('Error while calling stopPrinting method!!!');

   DC := Unassigned;
end;



Copyright © 1999-2016 Neevia Technology. All Rights Reserved. Home | Products | Technical Support | About Us | Contact Us