Planet PDF Forum Archive

Planet PDF ForumWowsers! This is page is old, head to the LIVE Planet PDF Forum. It features more than 10 conferences, covering everything from beginner to in-depth developer and pre-press discussions. If you wish to continue... one & two archive covers 1999-2011 (160,000 pages).

New Forum | Previous | Next | (P-PDF) Developers

Topic: PDDrawCosObjToWindow, etc.
Conf: (P-PDF) Developers, Msg: 132198
From: drolevar
Date: 5/4/2005 08:07 PM

I need to draw an image from a PDF document onto a window. As I know, the right function for this is PDDrawCosObjToWindow. I followed the hints and constructed a form XObject. The function does not raise an exception, but gives no output. Maybe I'm wrong with the matrix?
Can anyone advise me?
Below I give the code I used.

/*Begin Preparing Resource Dictionary*/
CosObj ResDict = CosNewDict(g_document, false ,5);
CosObj XObjDict = CosNewDict(g_document, false,1);
CosObj cosProcSet = CosNewArray(g_document, false, 3);
CosArrayPut(cosProcSet, 0, CosNewName(g_document, false, ASAtomFromString("PDF")));
CosArrayPut(cosProcSet, 1, CosNewName(g_document, false, ASAtomFromString("Text")));
CosArrayPut(cosProcSet, 2, CosNewName(g_document, false, ASAtomFromString("ImageC")));

CosDictPut(ResDict,ASAtomFromString("XObject"), XObjDict);
CosDictPut(ResDict,ASAtomFromString("ProcSet"), cosProcSet);

/*End Preparing Resource Dictionary OK*/

CosObj FormType = CosNewInteger(g_document, false, 1);
CosObj Filter = CosNewName(g_document, false, ASAtomFromString("FlateDecode"));
CosObj Type = CosNewName(g_document, false, ASAtomFromString("XObject"));
CosObj Subtype = CosNewName(g_document, false, ASAtomFromString("Form"));
CosObj CosAttribute = CosNewDict(g_document, false,7);

/*Begin Creating BBOX*/
CosObj cosBBox = CosNewArray(g_document, false, 4);
ASFixedRect bboxRec;
memset(&bboxRec, 0, sizeof(bboxRec));

bboxRec.left = ASInt32ToFixed(0);
bboxRec.bottom = ASInt32ToFixed(0);
bboxRec.right = ASInt32ToFixed(1000); = ASInt32ToFixed(1000);

CosArrayPut(cosBBox, 0, CosNewFixed(g_document, false, bboxRec.left));
CosArrayPut(cosBBox, 1, CosNewFixed(g_document, false, bboxRec.bottom));
CosArrayPut(cosBBox, 2, CosNewFixed(g_document, false, bboxRec.right));
CosArrayPut(cosBBox, 3, CosNewFixed(g_document, false,;
/*End Creating BBOX

/*Begin Creating Matrix*/
CosObj cosMatrix = CosNewArray(g_document, false, 6);
CosArrayPut(cosMatrix, 0, CosNewInteger(g_document, false, 1));
CosArrayPut(cosMatrix, 1, CosNewInteger(g_document, false, 0));
CosArrayPut(cosMatrix, 2, CosNewInteger(g_document, false, 0));
CosArrayPut(cosMatrix, 3, CosNewInteger(g_document, false, 1));
CosArrayPut(cosMatrix, 4, CosNewInteger(g_document, false, 0));
CosArrayPut(cosMatrix, 5, CosNewInteger(g_document, false, 0));
/*End Creating BBOX*/
CosDictPut(CosAttribute, ASAtomFromString("BBox"), cosBBox);
CosDictPut(CosAttribute, ASAtomFromString("Matrix"), cosMatrix);
CosDictPut(CosAttribute, ASAtomFromString("FormType"), FormType);
CosDictPut(CosAttribute, ASAtomFromString("Filter"), Filter);
CosDictPut(CosAttribute, ASAtomFromString("Type"), Type);
CosDictPut(CosAttribute, ASAtomFromString("Subtype"), Subtype);
CosDictPut(CosAttribute, ASAtomFromString("Resources"), ResDict);

char buff[50];
sprintf(buff,"q 1 0 0 1 0 0 /Im0 Do Q");
ASStm OpenedStream = ASMemStmRdOpen(buff, strlen(buff));

CosObj cosImgStrm = CosNewStream(g_document, true, OpenedStream, 0, false, CosAttribute, Filter, -1);
// I suppose it should be the user space to device space transformation matrix
ASFixedMatrix m = {7281, 0, 0, -7281, -65529, 5766552};

PDDrawCosObjToWindow(cosImgStrm, NULL, dc, 0, &m, NULL, NULL, NULL);

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.