CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2009
    Location
    London
    Posts
    51

    Redirect Printer Output To Specific File

    Hi, having nightmares with PDF again......

    What I basically need to do is to set a printer in Windows to print to file and then programatically set the output file name at runtime.

    In more detail.

    I have set up a Postscript printer to print to a fixed file name.
    In my code I set this to be the default printer.
    I then print an Access report to this printer.
    Once this report has printed I am using Ghostscript to convert the resulting printer file (which is in EPS format) to PDF.

    This all works fine and has been for some time but I have now run into brick wall when this is used by multiple users using Remote Desktop because they are trying to write to the same printer output file.

    Unfortunately this system is used on a number of different sites some of which are using Access 2000/2003 so I cannot use the new PDF options in Access/Office.

    I am using the API WriteProfileString function to set the default printer.

    Any help on this problem would be greatly appreciated.

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Redirect Printer Output To Specific File

    You'd have to change the name of the output file to reflect each user
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    May 2009
    Location
    London
    Posts
    51

    Re: Redirect Printer Output To Specific File

    Dglienna: I need to know if it is possible to change the name of the printer output file from within my VB6 project. Ideally I would use a randomly generated output file name each time as the files are only required temporarily while the PDF conversion takes place. The only possibility I can see at the moment is to set the printer to output to file and then use sendkeys to force the filename accross to the printer driver when it asks for the output filename. (Not ideal!!!)

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Redirect Printer Output To Specific File

    Well, VB.Net has a FileWatcher class that might help. You could monitor that folder, and move/rename as a separate operation.

    I'd have to see the code that saves the filename.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Redirect Printer Output To Specific File

    Many printer objects do have the filename property...

    I'm sure you can pass the filename to the object ...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  6. #6
    Join Date
    May 2009
    Location
    London
    Posts
    51

    Re: Redirect Printer Output To Specific File

    Dglienna: Sorry but the problem with the multiuser environment is that multiple machines are trying to write to the same file at the same time so a file move operation would not be possible. I could check to see if the file exists first and then wait before trying to output the file but then if any of the machines fail to delete the file after conversion to PDF then the whole system would stall. I need to get the printer driver to output to a specified filename so that each machine can process files simultaneously.

    Thanks
    Last edited by Killa69; March 10th, 2011 at 07:18 PM.

  7. #7
    Join Date
    May 2009
    Location
    London
    Posts
    51

    Re: Redirect Printer Output To Specific File

    GremlinSA: Could you give me some more details, I am not actually directly accessing any printer objects, it is Microsoft Access that is sending the report to the printer driver and the printer driver is then sending the output to a file.

    Thanks

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Redirect Printer Output To Specific File

    If you tell the printer to PRINT TO FILE in it's setup, it will prompt for a filename
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    May 2009
    Location
    London
    Posts
    51

    Re: Redirect Printer Output To Specific File

    I am sorry if I have failed to explain the problem clearly, but I need my program to tell the printer which file to print to, my program uses this printer output file to generate the PDF file, so having the user enter a file name for the printer output file will not really be much use.

    In essence I need to set a default printer (which I can do) and output to a specific filename that my program will generate.

    Configuring the printer to output to file will ask for a filename (No good).
    Configuring the printer to print to a static filename (Always print to the same file) causes problems in the multiuser environment.
    My program needs to generate a unique filename each time (Like windows temporary files) and then configure the printer driver to output to this file before I generate the Access report.

    I hope this clarfies what I am trying to achieve.
    Last edited by Killa69; March 10th, 2011 at 10:29 PM.

  10. #10
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Redirect Printer Output To Specific File

    Time to re-think the design, I'd say...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured