bytecook
asked on
How to add/remove/modify a custom papersize programmatically?
Hi there,
I need to add/remove/modify a custom papersize to the windows 7 / xp print server programmatically.
(The result should be accessible/shown under the print server properties after adding...)
Any ideas?
TIA- Peter
printserver.png
I need to add/remove/modify a custom papersize to the windows 7 / xp print server programmatically.
(The result should be accessible/shown under the print server properties after adding...)
Any ideas?
TIA- Peter
printserver.png
ASKER
Hello epasquier,
thank you for that info, it is in fact a user paper size, but selecting an user entry is not really aproblem.
I'm in search of ADDING a user custom papersize, and, setting the new form as default value for all printjobs... yesterday evening I found the registry entries for custom papersizes, but tbh, there should
be a better method to add a new printer form.
thank you for that info, it is in fact a user paper size, but selecting an user entry is not really aproblem.
I'm in search of ADDING a user custom papersize, and, setting the new form as default value for all printjobs... yesterday evening I found the registry entries for custom papersizes, but tbh, there should
be a better method to add a new printer form.
ASKER
@epasquier
btw, have seen that in the botttom text is DMPAPER_USER described - perhaps you're right!
cheers,
Peter
btw, have seen that in the botttom text is DMPAPER_USER described - perhaps you're right!
cheers,
Peter
you can also have a look at that very complete component TPrinterPreview
http://www.delphiarea.com/products/delphi-components/preview/
it has the ability to set the paper size at runtime according to the one you set in the component, so I guess you can find all you need in the source code (free)
it will look like this (setting of an existing papersize in the printer DEVMODE) :
http://www.efg2.com/Lab/Library/UseNet/2000/0526c.txt
here is also a code I found to add custom paper size, in C. I will try to convert it in Delphi
http://www.delphiarea.com/products/delphi-components/preview/
it has the ability to set the paper size at runtime according to the one you set in the component, so I guess you can find all you need in the source code (free)
it will look like this (setting of an existing papersize in the printer DEVMODE) :
http://www.efg2.com/Lab/Library/UseNet/2000/0526c.txt
here is also a code I found to add custom paper size, in C. I will try to convert it in Delphi
FORM_INFO_1 form1;
FORM_INFO_1 *pForm = NULL;
HANDLE hPrinter;
DWORD cByteNeeded, nReturned, cByteUsed;
SIZEL sz;
RECTL rc;
int i;
// récupération du handle sur l'imprimante
if (!OpenPrinter("HP DeskJet 1200C",&hPrinter,NULL))
return NULL;
// Récupére la quantité de mémoire à allouer
EnumForms(hPrinter, 1,
NULL,0,(LPDWORD)&cByteNeeded,(LPDWORD)&nReturned);
// allocation
pForm = (FORM_INFO_1 *)malloc(cByteNeeded);
ZeroMemory(pForm, cByteNeeded);
// remplit pForm avec l'ensemble des formats
EnumForms(hPrinter,1,(LPBYTE)pForm, cByteNeeded, (LPDWORD)&cByteUsed,
(LPDWORD)&nReturned);
// affichage du nom du format
for (i=0;i<nReturned;i++)
printf("%s\n",pForm.pName);
// désallocation
free(pForm);
// ajout d'un nouveau format
ZeroMemory(&form1, sizeof(FORM_INFO_1));
form1.Flags = FORM_USER;
form1.pName ="mon format";
sz.cx = 215900;
sz.cy = 279400;
rc.left = 0;
rc.top = 0;
rc.bottom = 279400;
rc.right = 215900;
form1.Size = sz;
form1.ImageableArea =rc;
AddForm(hPrinter,1,(LPBYTE)&form1);
// fermeture
ClosePrinter(hPrinter);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Note that in my sample application, I do not set the margin of the paper, but the AddPrinterForm procedure can handle it.
ASKER
Many thanks epasquier!
All the best,
Peter
All the best,
Peter
here is a start :
http://www.efg2.com/Lab/Library/UseNet/2000/0314.txt