Highlighted
Absent Member.
Absent Member.
556 views

[archive] Changing default printer in Acucobol

[Migrated content. Thread originally posted on 08 April 2007]

Does anyone know if there is a way to change the WIndows default printer using Win$printer in a Acucobol program, if not, has anyone experienced calling a Windows gdi command to change the default printer (SetDefaultPrinter) ? Version 8 Adobe hangs when electing to print the PDF to a printer other than the Windows default printer. If I could change the Windows default printer prior to printing the PDF, that it would print.

I am open for suggestions.....

Alex
0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Changing default printer in Acucobol

The Windows System default printer may be changed by using the Windows API SetDefaultPrinter yes, but albeit this function is there, it is not considered good practise of a program to change this (which is part of the reason you have no support for this in WIN$PRINTER). Also, this function came with Windows 2000, and thus, if you want to use it, you must make sure your users have at least Windows 2000. If they have earlier versions, changing this is truly a mess using several api functions. It just does not make sense to me that Adobe 8 should crash if you select a different printer from there. If this is so, it is very likely this will be the outcome also when you do it from ACUCOBOL-GT. May I ask what makes you think otherwise? It appears to me that there must be something wrong with the printers on the machine.
Anyways, the SetDefaultPrinter;

*Assuming DLL loaded and you have the printername stored in WINPRINT-NAME.
INSPECT WINPRINT-NAME REPLACING TRAILING SPACES BY LOW-VALUES.
CALL "SetDefaultPrinterA" USING BY REFERENCE WINPRINT-NAME.

But, as I said, I do not recommend doing this.

Having said all this, it sounds to me, that your primary goal is just that you want to direct the print somewhere specific. Am I right? If so, you don't have to deal with much, but just set the config variable WIN-SPOOLER-PORT just prior to your OPEN statement.
Imagine this code:

*Let user select printer
...
SET ENVIRONMENT "WIN-SPOOLER-PORT" TO "C:\MyReport.pdf".
OPEN MyPrinterFile.
*Do the print
...
CLOSE MyPrinterFile.

That is all it takes.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Changing default printer in Acucobol

Thank you for the reply, you are 100 % correct, we are using a 3rd party product to create pdf's, and one of the parameters is the ability to print to a printer other than your default printer by adding the UNC address to the string, Adobe has some problems and to print you must use the Adobe viewer, under V7, and V8 of Adobe will only print to the default printer it ignores the (Acrobat.exe /t) command to print to another printer other than the default, so, not really knowing which version of adobe our end user has this has caused us some other problems.

I felt that if I had control of the printers, I could set the non-default printer at the time of actually printing the pdf as the default printer, then set back to the original default printer upon completion of the print job.

I am in the process of this this logic right now.

I will post my results.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Changing default printer in Acucobol

This sounds so much work and little control. My compliments though, for the creativity.
But, may I suggest an alternate method?
Regardless of version, if Adobe viewer is installed, so is the AcroPDF component. If you use this, you have all kinds of possibilities. Here is the documentation for the pdf ActiveX interface:
http://www.adobe.com/devnet/acrobat/
If not for printing, at least you can use this to get the installed version of Adobe. 🙂

Anyways, assuming you have the pdf definitoon file and created a working storage item like: 77 MyPDF USAGE HANDLE of AcroPDF, I would do something along this line (this is pseudo code, not guarrantee it will work, intention is to give you an idea what I think of):


DISPLAY AcroPDF Visible = 0 HANDLE IN MyPDF.
MODIFY MyPDF LoadFile("Here goes path to my file").
MODIFY MyPDF PrintWithDialog().
DESTROY MyPDF.


You can also install an event handler and respond to the events OnError, OnMessage, the latter which may tell you when the print job is successfully sent to the printer.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Changing default printer in Acucobol

That sure does look a lot easier, I will give it a try, and your correct, using this, it doesn't matter what version it is. This should also work for Thin Client.
Thank you for the help, when i out from under another problem, I try this.

Alex
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.