Print Page | Close Window

Printer Properties - settings

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2722
Printed Date: 31 May 25 at 10:06AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Printer Properties - settings
Posted By: ibigon
Subject: Printer Properties - settings
Date Posted: 01 Sep 13 at 12:55PM
Hi,

is there any API to show the printers default properties dialog in DLL version?

I tried:
GetPrinterDevModeFromString
SetPrinterDevModeFromString

None of them showed the the standard properties dialog. I can show it with the win system call:
DocumentProperties with flag DM_IN_PROMPT

but how can I then pass the filled DEVMODE struct to QuickPDF lib?

Is there any conversion from DEVMODE to a correctly formatted string for SetPrinterDevModeFromString

Thanks,
Ian





Replies:
Posted By: AndrewC
Date Posted: 12 Sep 13 at 11:15AM
Ian,

Which programming language are you using ?

In C#, VB.NET it just needs to be a byte[] the same length as the DEVMODE structure.

In Delphi it is an AnsiString.

In other languages you need to call CreateBuffer, AddToBuffer and ReleaseBuffer functions to create the required string.

Andrew.






Posted By: ibigon
Date Posted: 19 Sep 13 at 10:58PM
Hi, Thanks for your help.

I am using c++.
So finally I was able to correctly cast the std::string to DEVMODE and vice versa, but unfortunatelly the QPL SetPrinterDevModeFromString function is not working for me, and the PrintPages and PrintDocument functions prints always with default printer settings.

Here is my pseudo code:

std::string lOrigDevStr = GetPrinterDevModeToString(lSelPrinter); //get the default DEVMODE via QPL
LPDEVMODE lDevModeP; //declare and allocate memory for the lDevModeP data ...
//open printer, etc.

 DocumentProperties(hWnd,  hPrinter,  lSelPrinter,  lDevModeP,  NULL,  DM_OUT_BUFFER|DM_IN_PROMPT); /*Show the Printer Properties Dialog and get the the modified DEVMODE into lDevModeP output buffer */

std::string lModifiedDevStr (lDevModeP, lReqSize); //it is converted well to std::string
SetPrinterDevModeFromString(lModifiedDevStr ); //return value is 1, unfortunately undocumented

std::string lNewDevStr = GetPrinterDevModeToString(lSelPrinter);

... the read lNewDevStr is equal to initial lOrigDevStr, but it should be equal to lModifiedDevStr! The SetPrinterDevModeFromString function does not really changes the printer properties for me. Any help would be appreciated,
Thanks,
Ian















Posted By: ibigon
Date Posted: 20 Sep 13 at 10:10AM
Guys,

finally I was able to fix the problem. I did not call the "NewCustomPrinter" function before calling "SetPrinterDevModeFromString" - that was the problem. After this fix the printer accepts  the passed DEVMODE.

Unfortunatelly the documentation is very poor, and does not mention this fact.

The function GetPrinterDevModeToString is buggy, while it returns the default DEVMODE for my custom printer instead of the modified one.

std::wstring lMyPrinter = NewCustomPrinter(lSelPrinter);
int lRetVal = SetPrinterDevModeFromString(lMyDevModeStr);
std::string lTmpDevStr = GetPrinterDevModeToString(lMyPrinter);

BUG: lTmptDevStr is not equal to lMyDevModeStr, but the printer prints with using lMyDevModeStr

Thanks,
Ian



Posted By: AndrewC
Date Posted: 20 Sep 13 at 10:38AM
Ian,

Which version of Quick PDF Library are you using. 9.15 and 9.16 should work reasonably well with DEVMODE.

I will make sure we review the documentation and add some sample code.  

I suspect it is not a bug but is based on how the code is implemented.

The GetPrinterDevModeToString function returns the currently active DEVMODE string for the custom printer.  Calling SetPrinterDevModeFromString doesn't actually update the DEVMODE until the actual call to PrintDocument.  SetPrinterDevModeFromString will save the string to a temporary buffer until the call to PrintDocument.  Again some better documentation would help here.

I would need to review the code full to determine why it is working this way and determine if it makes sense to update the DEVMODE straight away or not.  There must be some reason it was done this way in the first place.

Andrew.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk