Code Samples - Neevia docCreator

Example 1: How to create a simple PDF file - Delphi Copy 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
   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', 'c:\users\public\');

      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;