[Doc2pdf]PDf is saved in C:\WINDOWS\system32

If you are a C/C++/C# developer and have any questions about using our products from your application here is the place to post them.
Post Reply
pmeems
Posts: 11
Joined: Mon Jul 23 2007
Location: The Netherlands

[Doc2pdf]PDf is saved in C:\WINDOWS\system32

Post by pmeems »

I'm trying to convert a MS Word document to a PDF file. It seems to be working only the PDF is saved in C:\WINDOWS\system32 and I don't know why :cry:

Here's my code. It's a windows console in VS2005 in c#:
My main.cs:

Code: Select all

    class Program
    {
        static void Main(string[] args)
        {
            string docName = "C:\\Test\\Oracle\\FillInWord\\Template.doc";
            string pdfName = "C:\\Test\\Oracle\\FillInWord\\pdfs\\Amyuni.pdf";
            string defaultDirectory = System.IO.Path.GetDirectoryName(pdfName) + "\\";
            Amyuni amyuni = new Amyuni();
            //Go your gang:
            amyuni.DefaultDirectory = defaultDirectory;
            amyuni.doc2pdf(docName, pdfName);

            //Cleanup:
            amyuni = null;
            GC.Collect();
        }
    }
My converter class:

Code: Select all

    class Amyuni
    {
        private CDIntf.CDIntfControl cdiNet = null;
        private string _defaultDirectory = "C:/";

        public string DefaultDirectory
        {
            get { return _defaultDirectory; }
            set { _defaultDirectory = value; }
        }
        
        /// <summary>
        /// Constructor
        /// </summary>
        public Amyuni()
        {
            try
            {
                cdiNet = new CDIntf.CDIntfControl();
                cdiNet.DriverInit(Declarations.PrinterName);
                // Enable the printer before each printout for the Developer version
                cdiNet.EnablePrinter(Declarations.LicensedTo, Declarations.ActivationCode);                
                // Set the Printer as Default, this is needed only if you can not print to a specific printer
                cdiNet.SetDefaultPrinter();

                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return;
            }
        }

        public Boolean doc2pdf(string filename, string pdfFile)
        {
            try
            {
                cdiNet.DefaultDirectory = _defaultDirectory;
                cdiNet.FileNameOptions = Declarations.NoPrompt + Declarations.UseFileName;
                cdiNet.DefaultFileName = System.IO.Path.GetFileName(pdfFile);
                cdiNet.BatchConvert(filename);
                 
                return true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(cdiNet.GetLastErrorMsg());
                Console.WriteLine(ex.ToString());
                return false;
            }
        }

        /// <summary>
        /// Destructor
        /// </summary>
        ~Amyuni()
        {
            try
            {
                cdiNet.RestoreDefaultPrinter();
                cdiNet.FileNameOptions = 0;
                return;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return;
            }
        }
    }
When I check

Code: Select all

cdiNet.DefaultDirectory
just before

Code: Select all

cdiNet.BatchConvert(filename)
it says: "C:\\Test\\Oracle\\FillInWord\\pdfs\\" as expected.

No errors are trown, GetLastErrorMsg says successful.

Any help would really be appreciated.

Paul
The Netherlands
pmeems
Posts: 11
Joined: Mon Jul 23 2007
Location: The Netherlands

Solution

Post by pmeems »

I've figured it out.

If you don't use the

Code: Select all

cdiNet.DefaultDirectory
but parse the complete filename with paths in

Code: Select all

cdiNet.DefaultFileName = pdfFile;
the pdf is created where it should be.

I hope it's useful to someone else. Took be all day to figure out :evil:

Paul
Post Reply