[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I convert all type of documents in PS format? Document may be excel, word, autocad drawing, image etc.

Posted on 2009-02-20
13
Medium Priority
?
382 Views
Last Modified: 2012-05-06
How can I convert all type of documents in PS format? Document may be excel, word, autocad drawing, image etc.
0
Comment
Question by:Amitava_Mukherjee
  • 8
  • 5
13 Comments
 
LVL 22

Expert Comment

by:pivar
ID: 23692892
Hi,

AFAIK you'll have to use a Postscript printer driver to print your documents to a ps file. You would need viewers for the different kinds of documents to print them.

In C# (from http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx)
            Process myProcess = new Process();
           
            try
            {
                // Get the path that stores user documents.
                string myDocumentsPath =
                    Environment.GetFolderPath(Environment.SpecialFolder.Personal);

                myProcess.StartInfo.FileName = myDocumentsPath + "\\MyFile.doc";
                myProcess.StartInfo.Verb = "Print";
                myProcess.StartInfo.CreateNoWindow = true;
                myProcess.Start();

/peter

0
 

Author Comment

by:Amitava_Mukherjee
ID: 23698650
Yes, this code works for printing any document to a ps printer, but for PS file conversion the file should be printed as "print to file" option, and one output filename may be given. There is no option for that code snippet. So practically i can not use that code for ps file conversion. This is a very good code to print any file to attached printer by code. Any suggestion?
0
 

Author Comment

by:Amitava_Mukherjee
ID: 23698676
I tried to install the PS printer to File port but a dialog box pop up at time of printing, which can not be manipulated programmetrically, please help.
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
LVL 22

Expert Comment

by:pivar
ID: 23698861
If you want an universal solution I think you must use printing. In my simple example I was thinking you should use the default printer as print to file. But as you say this mean you have to choose filename each time. I'm not writing from windows now, so I can't check this. But here's how you could can configure a printer port to point to a specific file http://www.frogmorecs.com/arts/print-to-file.html
And here's a link to a c# project to do this http://www.codeproject.com/KB/cs/PrinterAdmin.aspx
0
 

Author Comment

by:Amitava_Mukherjee
ID: 23699052
"http://www.codeproject.com/KB/cs/PrinterAdmin.aspx".
It seems to be OK as per the code description. What I want to print any file to ps by any PS printer and probably it is doing exactly that. But unfortunately the code which is downloaded can not run may be for incomplete upload. Can you please suggest any other link or code snippet?
0
 
LVL 22

Expert Comment

by:pivar
ID: 23699091
I have no problem downloading the source. I attach the projects cs file.
using System;
using System.IO;
using System.Collections;
using PRNADMINLib;
 
namespace PrinterExample
{
    /// <summary>
    /// Example program will set the system default to print to a file.
    /// The command line will take a printer name, a file name, and a driver name
    /// to be used when a new printer is created.  If the specified printer or 
    /// port do not exist, then they will be created.
    /// </summary>
    public class PrinterExample
    {
        // Default Configuration
        private static string portfileName = "C:\\postscript.ps";
        private static string printerName = "TESTPRINTER";
        private static string newPrinterDriver = "HP DeskJet 1200C/PS";
 
        // Empty string object to specify local system in COM calls
        private static object oServerName = ""; // local system
 
        // Main program
        public static void Main(string[] args)
        {
            // Check arguments and set portfile name
            if (args.Length > 3)
            {
                Console.WriteLine("Usage: PrinterExample.exe [printer [filename [driver]]]");
                return;
            }
 
            if (args.Length > 0) printerName = args[0];
            if (args.Length > 1) portfileName = args[1];
            if (args.Length > 2) newPrinterDriver = args[2];
 
            // Check existence of portfile folder
            FileInfo portfileinfo = new FileInfo(portfileName);            
            DirectoryInfo portFolder = portfileinfo.Directory;
            if (!portFolder.Exists)
            {
                Console.WriteLine("Error: Portfile folder " + 
                    portFolder + " does not exist.");
                return;
            }
 
            // Get the normalized pathname
            portfileName = portfileinfo.FullName;
 
            // Get a reference to the printer subsystem
            PRNADMINLib.PrintMaster pMaster = new PRNADMINLib.PrintMasterClass();
 
            // Check existence of port
            PRNADMINLib.Port pPort = null;
            PRNADMINLib.PortCollection portColl = 
                (PRNADMINLib.PortCollection)pMaster.get_Ports(ref oServerName);
            IEnumerator portEnumerator = portColl.GetEnumerator();
            portEnumerator.Reset();
            while (portEnumerator.MoveNext())
            {
                PRNADMINLib.Port portCurrent = portEnumerator.Current as PRNADMINLib.Port;
                if (portCurrent.PortName == portfileName)
                {
                    pPort = portCurrent;
                    break;
                }
            }
 
            // Get reference to port or create it if it does not exist
            if (pPort == null)
            {
                pPort = new PRNADMINLib.PortClass();
                pPort.PortName = portfileName;
                pPort.PortType = 3;  // Simple local port
                pMaster.PortAdd(pPort);
            }
 
            // Check existence of printer
            PRNADMINLib.Printer pPrinter = null;
            PRNADMINLib.PrinterCollection prnColl = 
                (PRNADMINLib.PrinterCollection)pMaster.get_Printers(ref oServerName);
            IEnumerator prnEnumerator = prnColl.GetEnumerator();
            prnEnumerator.Reset();
            while (prnEnumerator.MoveNext())
            {
                PRNADMINLib.Printer prnCurrent = 
                    prnEnumerator.Current as PRNADMINLib.Printer;
                if (prnCurrent.PrinterName == printerName)
                {
                    pPrinter = prnCurrent;
                    break;
                }
            }
 
            // Get reference to printer and create it if it does not exist
            if (pPrinter == null)
            {
                // To add printer, name, driver, and port are required
                pPrinter = new PRNADMINLib.PrinterClass();
                pPrinter.PrinterName = printerName;
                pPrinter.DriverName = newPrinterDriver;
                pPrinter.PortName = pPort.PortName;
                pMaster.PrinterAdd(pPrinter);
            }
            else
            {
                // Make sure port is set on existing printer
                if (pPrinter.PortName != pPort.PortName)
                {
                    pPrinter.PortName = pPort.PortName;
                }
                // Driver cannot be re-set on existing printer
                if (args.Length == 3 && newPrinterDriver != pPrinter.DriverName)
                {
                    Console.WriteLine("Warning: Driver remains set to " + pPrinter.DriverName);
                }
                pMaster.PrinterSet(pPrinter);
            }
            
            // Set printer as system default
            pMaster.DefaultPrinter = pPrinter.PrinterName;
 
            // Print test page
            pMaster.PrintTestPage("", pPrinter.PrinterName);
 
            // Let us know what happened...
            Console.WriteLine("Results for " + printerName + ":");
            Console.WriteLine("    Port set to " + portfileName);
            Console.WriteLine("    Using driver \"" + pPrinter.DriverName + "\"");
            Console.WriteLine("    " + printerName + " set to default printer.");
 
 
        }
    }
}

Open in new window

0
 

Author Comment

by:Amitava_Mukherjee
ID: 23699180
If I use "WinDows XP" is there any problem for PRNADMINLib?
0
 
LVL 22

Expert Comment

by:pivar
ID: 23699887
I haven't tried, but yes I do believe so. Apparently it won't work with Vista though.
0
 

Author Comment

by:Amitava_Mukherjee
ID: 23709399
sorry, after running the code i understand this cpde creates a port to print a file but i want to print programmetrically any type of document to ps format. it is not serving the purpose.
0
 
LVL 22

Accepted Solution

by:
pivar earned 1500 total points
ID: 23709488
Yes, if you want a general solution to convert different documentformat to PS. My solution is to programmatically create a printer port to print to a specified filename and change the defaut printer to a PS printing driver printing to this port. Then print by the Process class (with the verb "print" to use the registered application to print). I'm sorry if I wasn't clear about this.

Of course you could look for third party products that can convert one or more specific documentformats. But AFAIK if you want a general way to do this, this is the way to do it.  

0
 

Author Comment

by:Amitava_Mukherjee
ID: 23709955
Yes as per your suggestion I am trying to do that. It seems a perfect solution for me till now :-). Give me some time to test this concept. Thanx
0
 

Author Comment

by:Amitava_Mukherjee
ID: 23813664
I think you give me the best solution. Thank you very much buddy.
0
 

Author Closing Comment

by:Amitava_Mukherjee
ID: 31549221
excellent solution
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month18 days, 9 hours left to enroll

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question