10-11-2007 09:31 AM
10-11-2007 10:30 AM
You could try: OpenDocumentInDefaultViewer(), in the programmer's toolbox. Then just print from within Acrobat.
JR
10-11-2007 10:46 AM
Or, if you want an automated solution without pressing buttons in Acrobat maybe this will work: (I have not tried it!)
system ("AcroRd32.exe /p /h file_to_print.pdf");
JR
10-15-2007 05:57 AM
10-16-2007 04:28 AM
07-09-2014 01:24 AM
Your answer was very helpful to me.
But I need to print to a certain printer. ShellExecute() always prints to the default printer.
Is there any solution to that?
Regards
Andrej
07-09-2014 01:53 AM
You may benefit from this contribution of mine: Calling Win32 Print Dialogue from a CVI program
Also, I have published a document on creating your own PDF file using Haru library: you may want to examine this possibility instead of installing a PDF virtual printer and using it.
07-09-2014 02:12 AM
Thanks for your reply.
I was abel to enumarate printers and choose a printer from the list.
I was also abel to create a PDF document using HARU DLL.
And I can print the PDF document on the default printer using ShellExecute().
But I am not abel to print on an arbitrary printer selected from my printer list.
May be there is another method printing PDF documents where you can specify the printer.
I did not find anything in the documentation of ShellExecute() to specify a printer.
Regards
Andrej
07-09-2014 04:13 AM - edited 07-09-2014 04:21 AM
I use the following code to print to a specific printer: the printer name can be retrieved with any of the systems shown in my previous post
HMODULE g_hSHELL32 = NULL; SHELLEXECUTEINFO seInfo; BOOL shellExecuteSucceeded = FALSE; BOOL (WINAPI *g_pShellExecuteEx) (LPSHELLEXECUTEINFO lpExecInfo); memset(&seInfo, 0, sizeof(seInfo)); seInfo.cbSize = sizeof(seInfo); seInfo.fMask = SEE_MASK_NOCLOSEPROCESS; seInfo.lpVerb = "printto"; //strcpy (printerName, "\"PDFCreator\""); // Used to print to PDFCreator virtual printer seInfo.lpParameters = printerName; seInfo.lpFile = PDFFileName; seInfo.nShow = SW_SHOWMINNOACTIVE; seInfo.hIcon = 0; seInfo.hProcess = 0; if (!(g_hSHELL32 = LoadLibrary ("shell32.dll"))) { error = ToolErr_ErrorLoadingDLL; goto Error; } if (!(g_pShellExecuteEx = (void*)GetProcAddress (g_hSHELL32, "ShellExecuteExA"))) { error = ToolErr_FuncNotFound; goto Error; } (*g_pShellExecuteEx)(&seInfo); i = WaitForSingleObject (seInfo.hProcess, 100); do { i = WaitForSingleObject(seInfo.hProcess, 0); } while (i != WAIT_TIMEOUT); FreeLibrary (g_hSHELL32); error = 0; line = __LINE__; if ((int)seInfo.hInstApp <= 32) { switch((int)seInfo.hInstApp) { case SE_ERR_FNF: error = UIEFileWasNotFound; break; case SE_ERR_PNF: error = UIEFileWasNotFound; break; case SE_ERR_ACCESSDENIED: error = UIEAccessDenied; break; case SE_ERR_OOM: error = UIEOutOfMemory; break; case SE_ERR_DLLNOTFOUND: error = ToolErr_ErrorLoadingDLL; break; case SE_ERR_SHARE: error = UIEAccessDenied; break; case SE_ERR_ASSOCINCOMPLETE: error = ToolErr_FileAssociationNotAvailable; break; case SE_ERR_DDETIMEOUT: error = ToolErr_UnknownSystemError; break; case SE_ERR_DDEFAIL: error = ToolErr_UnknownSystemError; break; case SE_ERR_DDEBUSY: error = ToolErr_UnknownSystemError; break; case SE_ERR_NOASSOC: error = ToolErr_FileAssociationNotAvailable; break; default: error = ToolErr_UnknownSystemError; break; } } Error: // Display an error message if error < 0
It is to be said that this method relies on interaction with Adobe Reader to print, but that application does not handle it very well: first of all the nShow parameter is not honoured and the PDF flashes briefly on the screen regardless the value you set in that parameter; secondly, an instance of the reader remains active and even worse it sometimes remains in the foreground so you need to manually switch back to your app!
07-09-2014 05:35 AM
Thank you for your help.
The verb "printto" is not documented in MSDN.
Here is a more simple version of your code which I use for anybody having my problem:
char* PDFDocumentName = "any.pdf";
char* PrinterName = "myPrinter";
ShellExecute(0/*handle*/, "printto", PDFDocumentPath, PrinterName, NULL, SW_SHOWNORMAL);
Regards
Andrej