Adding custom paper sizes

Adding custom paper sizes

Anonymous
Not applicable
1,428 Views
8 Replies
Message 1 of 9

Adding custom paper sizes

Anonymous
Not applicable

Using Object ARX on Autocad 2012 I need to insert a custom paper size in the available media format

for a raster printer.

The I can use the canonicalMediaNameList function to obtain the complete list and print out my image.

How can I add custom format at runtime using OBJ ARX?

 

Thanks a lot

 

Flavio

0 Likes
1,429 Views
8 Replies
Replies (8)
Message 2 of 9

nick83
Advocate
Advocate

i had the same question several years ago. the official answer was "unfortunately, you can use just a list of available paper size for your device".

so, workaround is to create a paper size with parameters you need for your device. that's not an arx question, and it's quite hard to do. 

PS: my question was for autocads 2007-2009, but as i know nothing was changed till now

0 Likes
Message 3 of 9

OysteinW
Advocate
Advocate

We had to distribute a custom pc3 and pmp file with the required paper size(s) and plotter configuration with our application. We couldn't find a way to do this in code. 

 

 

0 Likes
Message 4 of 9

nick83
Advocate
Advocate

actually, this can be done by code ))).

for example:

 

#include <Winspool.h>

BOOL setPageSize(CString printerName, int widthMM, int heightMM)
{
	CString papersizeName = _T("MyCustomPage");
	HANDLE hPrinter = NULL;
	PRINTER_DEFAULTS pDef;
	ZeroMemory(&pDef, sizeof(pDef));
	pDef.DesiredAccess = PRINTER_ALL_ACCESS;
	bool bGotPrinter = OpenPrinter((LPWSTR)printerName.GetString(), &hPrinter, &pDef);
	if (!bGotPrinter || (hPrinter == NULL))
		return FALSE;

	DeleteForm(hPrinter, (LPWSTR)papersizeName.GetString()); // just for recreate
	
	FORM_INFO_1 paperInfo;
	paperInfo.Flags = 0;
	paperInfo.pName = (LPWSTR)papersizeName.GetString();
	paperInfo.Size.cx = widthMM * 1000; // size in 1000ths of millimeters
	paperInfo.Size.cy = heightMM * 1000; // size in 1000ths of millimeters
	paperInfo.ImageableArea.left = 0;
	paperInfo.ImageableArea.right = paperInfo.Size.cx;
	paperInfo.ImageableArea.top = 0;
	paperInfo.ImageableArea.bottom = paperInfo.Size.cy;
	
	return AddForm(hPrinter,1,(LPBYTE)&paperInfo);
}

 and usage:

CString printer = _T("Fax");
if (TRUE == setPageSize(printer,150,200) ) acutPrintf(_T("\nDone"));
else acutPrintf(_T("\nFailed"));

but there are some limitations. your custom size must not be larger or smaller, than device support (for example, printer A4 cant have A0 paper size)

this code must be used before you start working with autocad printer data, if you want to see "MyCustomPage" in a list of available papers for your device, or you have to refind all of the papers again after function usage.

 

 

0 Likes
Message 5 of 9

OysteinW
Advocate
Advocate

Ok, nice!

 

I got this from ADN: 

 

Dear Øystein,

 

For any other resolution which is not available in the pc3 files provided by AutoCAD, you will need to create your own pc3 file.

 

Programmatically adding a custom paper size to the pc3 file is not possible at the moment and we have a wish list item logged for it with our engineering team.

 

So we went with the custom PC3/PMP solution.

0 Likes
Message 6 of 9

nick83
Advocate
Advocate

))) official answer is a template, as usual
nevertheless, the proof of my code 🙂

printer.jpg

PS: as for me, devhelp tries to reply to your message "exactly". they don't try to UNDERSTAND a problem. ask them "i want to ..." and this will send em to the dead end. but if you tell them "guys, function ... doesn't work at all, and here are the proofs", you'll get an direct answer about workaround in several hours. so, i used to ask one question in several variants, if i see, that the discussion is walking to "dead end".

0 Likes
Message 7 of 9

Anonymous
Not applicable

Thanks a lot, I'm going ti try your solution in my software.

..and I've taken note about how to send questions tuo devHelp 😉

 

Bye

Flavio

0 Likes
Message 8 of 9

m_latz
Advisor
Advisor

Flavio,

 

if you plot/print through a windows printer, you can modify all properties you can modify interactively in windows also through the windows API's. As nick83 did in his code snippet.

 

If you print through an autocad driver, you can't use windows api.

 

But there is a toolkit from autodesk available to write your own printer driver. In the toolkit (called HEIDI) is also the source code for the printer drivers autodesk distributes with AutoCAD.

 

 You can create your own driver where you can modify the paper size on the fly.

 

I did this for a project with a customer a few years ago.

 

If you're an ADN member you can download through the ADN developer network.

 

regards

 

Markus

0 Likes
Message 9 of 9

xiaomenggg97
Explorer
Explorer
But i cant't use openprinter to open the printer in arx and it prompts that acced is denied.
0 Likes