Code Samples - Neevia docCreator

Example 7: Convert an URL / HTML file into PDF - C# Copy 

1) Add a reference in your Visual Studio project to docCreator library.
To do this:
        a. On the Project menu, click Add Reference;
        b. On the COM tab, locate docCreator Library and then click Select;
        c. Click OK in the Add References dialog box to accept your selections.

2) Add a reference in your Visual Studio project to Microsoft Internet Controls.
To do this:
        a. On the Project menu, click Add Reference;
        b. On the COM tab, locate Microsoft Internet Controls and then click Select;
        c. Click OK in the Add References dialog box to accept your selections.
 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
   SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
   IE.Visible = true;

   object RN = System.Reflection.Missing.Value;
   object URL = @"http:\\www.neevia.com";
   IE.Navigate2(ref URL, ref RN, ref RN, ref RN, ref RN);

   Neevia.docCreator DC = new Neevia.docCreator();
   DC.doSleep(100);

   while ((IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
            || (IE.Busy == true))
   {
      DC.doSleep(100);
   }

   DC.setParameter("DocumentOutputFormat", "PDF");
   DC.setParameter("DocumentOutputName", "testURL_CSHARP");
   DC.setParameter("DocumentOutputFolder", @"c:\users\public\");
   DC.setParameter("PDFAutoRotatePage", "All");

   int RVal = DC.startPrinting();
   if (RVal != 0)
   {
      MessageBox.Show("Error while creating the virtual printer!!!");
   }

   string defPrinter = DC.getDefaultPrinter();
   DC.setDefaultPrinter(DC.newPrinterName());

   IE.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
             SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
             ref RN, ref RN);

   RVal = DC.create();
   if (RVal != 0) { MessageBox.Show("Error while creating document!!!"); }

   IE.Quit();

   DC.setDefaultPrinter(defPrinter);
   RVal = DC.stopPrinting();

   IE = null;
   DC = null;

   if (RVal != 0)
   {
     MessageBox.Show("Error while deleting the virtual printer!!!");
   }
   else
   {
     MessageBox.Show("Done converting !!!");
   }