LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I print a PDF flile from my software?

I want print a PDF document from my software. How can I do?
Tanks!!!

Stefano
0 Kudos
Message 1 of 10
(5,383 Views)

You could try: OpenDocumentInDefaultViewer(), in the programmer's toolbox. Then just print from within Acrobat.

JR

0 Kudos
Message 2 of 10
(5,372 Views)

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

0 Kudos
Message 3 of 10
(5,371 Views)
Try ShellExecute function to print or open file with default windows program

//!add shellapi.lib to your project!

//{ShellExecute is from Windows shell API}
#include "windows.h"
#include "shellapi.h"
//#include <utility.h>
#include <userint.h>


/*
Action:
"edit"           Opens an editor. If lpFile is not a document file, the function will fail.
"explore"    The function explores the folder specified by lpFile.  
"open"         The function opens the file specified by the lpFile parameter. The file can be an executable file or a document file. It can also be a
                     folder.
"print"   The function prints the document file specified by lpFile. If lpFile is not a document file, the function will fail.
"properties" Displays the file or folder's properties.

(0) NULL - Defaultni akce/Open
*/

//example: Run_ShellExecute("file.pdf","print","c:\\");

int Run_ShellExecute(char *FileName,char *Action,char *DefaultProgramDirectory)
{
 ShellExecute(0/*handle*/, Action, FileName, NULL, DefaultProgramDirectory, SW_SHOWNORMAL);
 return 0;
}

Message 4 of 10
(5,330 Views)
Thank you for your information!!!
I solved my problem with the following instructions:

       SetPrintAttribute (ATTR_PRINTER_NAME, "PDFCreator");  
       PrintPanel (panelHandle_4, "", 1, VAL_FULL_PANEL, 1);

Obviously I installed PDFCreator. It was simple!!!
However thank you very much!!!
0 Kudos
Message 5 of 10
(5,298 Views)

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

0 Kudos
Message 6 of 10
(4,210 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 7 of 10
(4,203 Views)

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

0 Kudos
Message 8 of 10
(4,199 Views)

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! Smiley Mad



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 9 of 10
(4,194 Views)

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
 

0 Kudos
Message 10 of 10
(4,179 Views)