Problems specifying paper size with PDF-XChange Driver API

PDF-XChange Drivers API (only) V4/V5
This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-XChange Printer Drivers SDK (only) - VERSION 4 & 5 - Please use the PDF-Tools SDK Forum for Library DLL assistance.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

sjrogers
User
Posts: 10
Joined: Tue Mar 03, 2015 8:38 pm

Problems specifying paper size with PDF-XChange Driver API

Post by sjrogers »

I am trying to use the PDF-XChange Drivers API SDK to create a .PDF file of a specified size. It seems like I am having some success with the paper size that the .PDF thinks it is, but not internally because the Device Context seems to still think it is 8.5 x 11 and I can only draw in that area. Here is my test code I have been using:


CoInitialize(NULL);
WCHAR str[MAX_PATH];
PXC::IPXCControlExPtr pFactory;
PXC::IPXCPrinterPtr prn;

pFactory = PXC::IPXCControlExPtr(__uuidof(PXC::CPXCControlEx));
if (pFactory == NULL)
{
wsprintfW(str, L"Thread %d: cannot create factory\n", GetCurrentThreadId());
OutputDebugString(str);
}

try
{
prn = pFactory->Printer[L"", L"PDF-XChange Sample", L"<KEY>", L"<DEVCODE>"];
}
catch (_com_error& e)
{
// dump_com_error(e);
}

WCHAR pname[MAX_PATH];
wsprintfW(pname, L"m:\\temp\\test.pdf");

DOCINFO di = {0};
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = pname;

prn->ResetDefaults();

prn->Option[L"General.Specification"] = -1;

prn->Option[L"Save.SaveType"] = L"Save";
prn->Option[L"Save.ShowSaveDialog"] = L"No";
prn->Option[L"Save.File"] = pname;
prn->Option[L"Save.WhenExists"] = L"Overwrite";
// prn->Option[L"Save.RunApp"] = L"No";

prn->Option[L"Paper.SheetSizeIndex"] = -2;
prn->Option[L"Paper.SheetWidth"] = 4000;
prn->Option[L"Paper.SheetHeight"] = 3000;

prn->Option[L"Paper.Center"] = L"No";
prn->Option[L"Paper.Fit"] = L"No";

CDC cdc;
if (!cdc.CreateDCW(L"PDF-XChange 5.0", (LPCWSTR)prn->Name, L"PDF-XChange5", NULL))
{
// unable to create dc
}

POINT point;
long stat1=cdc.Escape(GETPRINTINGOFFSET, 0, NULL, &point);
cdc.Escape(GETPHYSPAGESIZE,0,NULL,&point);

int pageX=point.x;
int pageY=point.y;

int dpiX=cdc.GetDeviceCaps(LOGPIXELSX);
int dpiY=cdc.GetDeviceCaps(LOGPIXELSY);

double pwInches = (double)pageX / (double)dpiX;
double phInches = (double)pageY / (double)dpiY;

double pw=pageX;
double ph=pageY;

CPen red(0,0,RGB(255,0,0));
CPen blue(0,10,RGB(0,0,255));
CPen *oldPen = cdc.SelectObject(&red);

if (cdc.StartDoc(&di) > 0)
{
if (cdc.StartPage() > 0)
{
int size=dpiX;
double maxx=pw;
double maxy=ph;

// Draw Grid
for (int x=0; x<maxx-dpiX; x+=dpiX)
{
for (int y=0; y<maxy - dpiY; y+=dpiY)
{
cdc.MoveTo(x,y);
cdc.LineTo(x+size,y);
cdc.LineTo(x+size,y+size);
cdc.LineTo(x,y+size);
cdc.LineTo(x,y);

double cenx = x+dpiX/2;
double ceny = y+dpiY/2;

CString temp;
temp.Format(_T("x=%d,y=%d"),x/dpiX,y/dpiY);

cdc.TextOutW(cenx,ceny,temp.GetBuffer(0),temp.GetLength());
}
}

// Draw Page Bounding box
cdc.SelectObject(&blue);
cdc.MoveTo(0,0);
cdc.LineTo(maxx,0);
cdc.LineTo(maxx,maxy);
cdc.LineTo(0,maxy);
cdc.LineTo(0,0);
cdc.SelectObject(oldPen);

cdc.EndPage();
}
else
{
// Unable to start page
}

cdc.EndDoc();
}
else
{
// Unable to start Doc
}


// cleanup
cdc.DeleteDC();

if (prn != NULL)
{
prn.Release();
}
if (pFactory != NULL)
{
pFactory.Release();
}

CoUninitialize();


This code produces the attached file test.pdf. The page is the right size, but the DC that I am drawing to still thinks it is 8.5 x 11. I would expect the grid that is drawn to cover the entire page. I have tried ignoring the DC sizes that are returned, but I still can't draw beyond the 8.5 x 11 block.

Obviously, I am missing something key here, but I have not yet been able to figure out what it is.

Any help will be greatly appreciated.
You do not have the required permissions to view the files attached to this post.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3556
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada

Re: Problems specifying paper size with PDF-XChange Driver A

Post by Ivan - Tracker Software »

You have two options:

1. Use ResetDC to specify new paper size via DEVMODE, as you would do for any other printer

2. Specify paper size via an 'Option[]':
prn->Option[L"DevMode.PapSize"] = DMPAPER_USER;
prn->Option[L"DevMode.CWidth"] = 4000;
prn->Option[L"DevMode.CHeight"] = 3000;
prn->ApplyOptions(0);
please note prn->ApplyOptions.

HTH
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
sjrogers
User
Posts: 10
Joined: Tue Mar 03, 2015 8:38 pm

Re: Problems specifying paper size with PDF-XChange Driver A

Post by sjrogers »

Ivan,

Thanks for the information. I think the: prn->ApplyOptions(0); is the line I was missing.

Also, DevMode.PapSize, DevMode.CWidth, and DevMode.CHeight are not in the documentation for the SDK (PDFXDRV5SDKMAN.pdf). I don't know if these are the same as Paper.SheetSizeIndex, Paper.SheetWidth, and Paper.SheetHeight or not.

The documentation also says that SheetWidth and SheetHeight are in 1/10ths of mm and have a valid range of 13-5080. This may be incorrect because that is only 20"x20" and I have used much larger sizes.

Another problem I had was that I set:

prn->Option[L"DevMode.CWidth"] = paperWidth * 254.0;
prn->Option[L"DevMode.CHeight"] = paperHeight * 254.0;

This, of course, did not work as it is expecting the value to be an integer
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3556
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada

Re: Problems specifying paper size with PDF-XChange Driver A

Post by Ivan - Tracker Software »

Will check the documentation.

Paper size should be specified in tenth of mm, and, you're right, it should be an integer. PDF supports paper size in range from 3pt to 200" (3/72" - 200"). So, the range should be 11 to 50800.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.