"Printer Installation Failed" message when tryin to automate

The Amyuni PDF Converter is our Printer Driver that enables you to convert any documents to PDF format. If you have any questions about installing and using the Amyuni PDF Converter please post them here.
Post Reply
KarlRhodes
Posts: 2
Joined: Fri Feb 24 2012

"Printer Installation Failed" message when tryin to automate

Post by KarlRhodes » Fri Feb 24 2012

We've recently bought a copy of the developer version of the Amyuni PDF Converter as we need to save/print files to PDF format without having to install the software on each client machine that uses our application (C# Winforms).

We have followed the instructions showing how to use the driver using this method, but when we call PDFDriverInit we get the error "Printer Installation Failed". At no point has the printer been manually installed. I also have no way of knowing if there are any other errors as I cannot get past the "PDFDriverInit" line.

The code we are using is shown here, and "mySheet" is a Microsoft Excel Worksheet...

Code: Select all

try
{
	Guid printerLock = new Guid();
	printerLock = Guid.NewGuid();

	CDIntfEx.CDIntfExClass pdfPrinter = new CDIntfExClass();

	pdfPrinter.PDFDriverInit("TempAmyuniPDFPrinter");
	pdfPrinter.Lock(printerLock.ToString());
	pdfPrinter.EnablePrinter(_licenceName, _licenseCode);
	pdfPrinter.SetDefaultConfig();
	pdfPrinter.FileNameOptions = 3;

	pdfPrinter.DefaultFileName = fileName;
	pdfPrinter.SetDefaultPrinter();

	mySheet.PrintOutEx(Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing, Missing);

	if (pdfPrinter.TestLock(printerLock.ToString()) == 0)
	{
		pdfPrinter.Unlock(printerLock.ToString(), 0);
	}
	pdfPrinter.RestoreDefaultPrinter();
	pdfPrinter.DriverEnd();
}
catch (Exception ex)
{
	WriteEvent(ex.Message);
	MessageBox.Show(ex.Message);
}
As suggested in numerous other posts, we have included all the relevant install files in the root of our application, and the reference to the CDintf.dll points to the file, which is also in the root of our application.

Can someone confirm that the printer does NOT need to be manually installed prior to using it in this way?

Also, if someone has this method of working with this printer, and wouldn't mind sharing some sample code I would be very grateful.

Karl

KarlRhodes
Posts: 2
Joined: Fri Feb 24 2012

Re: "Printer Installation Failed" message when tryin to automate

Post by KarlRhodes » Fri Feb 24 2012

Update...

We have now attempted to install the printer programmatically when our application starts using the code below...

Code: Select all

private void InstallPrinter()
{
	if (!installedPrinters.Contains("TempAmyuniPDFPrinter"))
	{
		Process p = new Process();

		p.StartInfo.FileName = "install.exe";
		p.StartInfo.Arguments = "-s \"TempAmyuniPDFPrinter\" -n \"" + _licenceName + "\" -c \"" + _licenseCode + "\"";
		p.StartInfo.Verb = "runas";

		p.Start();
		p.WaitForExit();
	}
}


This seems to fix out issue, but has presented us with another.

When the application closes, the printer is uninstalled and removed from the list of printers. This means the printer is installed everytime the application starts. Not so much of an issue, apart from we get a UAC window asking us if we want to allow the application to make system changes everytime, and if we click the "more details" link in the UAC window, the licencing information is shown to the user.

This potentially means that the application could fail when printing to PDF if the printer fails to install for some reason, and as printing the PDF's is an important element to our application, this could be an issue.

Does anyone know if there is a work around for this?

Jose
Amyuni Team
Posts: 549
Joined: Tue Oct 01 2002
Contact:

Re: "Printer Installation Failed" message when tryin to automate

Post by Jose » Thu Mar 22 2012

Hello,

I believe that the process you are using may become problematic for you.

The PDFDriverInit() function will install the Amyuni PDF Converter printer on a user’s system each time is called and the printer will be removed when the object is destroyed (end of your application) or when calling DriverEnd.

Typically the PDFDriverInit() function needs to be called at the beginning of your application (and not each time you print) and DriverEnd should be called at the end of your application (and not when printing ends).

If users doesn't have administrative or power rights to add and remove a printer from their system PDFDriverInit() will fail.

In this case you can install the printer on your system using Install.exe (Install.exe should be run by an administrator) and inside your application you replace PDFDriverInit by DriverInit (the printer will remain on the system even when the application ends).

The DriverInit() function will take as parameter a string containing the printer name as it appears in your printers' folder.

Thanks
Get PDF Suite, the expert .NET developer toolkit for PDF conversion, creation and editing - www.amyuni.com/pdfsuite

Post Reply