Copy link to clipboard
Copied
I am trying to get an image into an appearance stream. I have the image as an XObject in a form and have created a PDEForm. the STAMPR sample was my base project.. What I am doing is in snippets below. the else case if I am not testing bmp is to do an altered form of what's in the sampe, which works fine. the last thing it does is explained and shown after the first snippets.
if (pOptions->CreateAsStamps)
{
annot = PDPageAddNewAnnot(pdPage, -1, ASAtomFromString("Stamp"), &pdLocation);
}
else
{
annot = PDPageAddNewAnnot(pdPage, -1, Stamper_K, &pdLocation);
}
PDTextAnnotSetContents(annot, CurrentTickItem->Desc.c_str(), strlen(CurrentTickItem->Desc.c_str()));
cAnnotObj = PDAnnotGetCosObj(annot);
cdoc = PDDocGetCosDoc(PDPageGetDoc(pdPage));
...
cAPDictObj = CosNewDict(cdoc, false, 1L);
cNullObj = CosNewNull();
if (bTestBmp)
{
CosObj cosBmp = CreateBmpForm(CurrentTickItem->GethBmp());
CosDictPut(cAPDictObj, FaceNormal_K, cosBmp);
CosDictPutKeyString(cAnnotObj, Appearance_KStr, cAPDictObj);
}
the else case works and puts in a character with a user defined font. not portable and there are other issues, so I am trying to do a bitmap repesentation instead.
else
{
const char* sSource = CurrentTickItem->FontName.c_str();
char* sDest = sFontName;
do
{
while (*sSource == ' ')
++sSource;
} while (*sDest++ = *sSource++);
// Read in the stream for the appearance key.
memset(&buf, 0, sizeof(buf));
strcat(buf, "BT /");
strcat(buf, sFontName);
char fontSizeStr[16];
sprintf(fontSizeStr, " %.1f", CurrentTickItem->FontSize * 2.25);
strcat(buf, fontSizeStr);
strcat(buf, " Tf 0 0 TD ");
if (CurrentRoleItem != NULL)
{
char acColor[16];
itoa(CurrentRoleItem->RoleColor, acColor, 10);
CosObj oRoleColor = CosNewString(cdoc, false, acColor, strlen(acColor));
CosDictPutKeyString(cAnnotObj, "RoleColor", oRoleColor);
// they are win32 api colors, notweb colors. it's 0x0bbggrr
std::size_t blue = (CurrentRoleItem->RoleColor & 0xff0000) >> 16;
std::size_t green = (CurrentRoleItem->RoleColor & 0x00ff00) >> 8;
std::size_t red = (CurrentRoleItem->RoleColor & 0x0000ff);
float fRed = 0;
if (red > 0) fRed = red / 255.0;
float fGreen = 0;
if (green > 0) fGreen = green / 255.0;
float fBlue = 0;
if (blue > 0) fBlue = blue / 255.0;
char rgbStr[16];
sprintf(rgbStr, "%.1f %.1f %.1f rg ", fRed, fGreen, fBlue);
OutputDebugString(rgbStr);
strcat(buf, rgbStr);
}
strcat(buf, "(");
strcat(buf, CurrentTickItem->TickChar.c_str());
strcat(buf, ")Tj ET ");
// strcat(buf, "BT /STAMPR 24 Tf 10 40 TD ( abcdefg)Tj ET q 10 w 0 1 0 RG 5 5 90 90 re S Q");
s = (ASUns32)strlen(buf);
stm = ASMemStmRdOpen(buf, s);
attributesDict = CosNewDict(cdoc, false, 5);
LengthEntry = CosNewInteger(cdoc, false, s);
CosDictPutKeyString(attributesDict, Length_KStr, LengthEntry);
cStmObj = CosNewStream(cdoc, true, stm, 0, true, attributesDict, cNullObj, s);
cStmDictObj = CosStreamDict(cStmObj);
CosDictPutKeyString(cStmDictObj, "Type", CosNewNameFromString(cdoc, false, "XObject"));
CosDictPutKeyString(cStmDictObj, "Subtype", CosNewNameFromString(cdoc, false, "Form"));
CosDictPutKeyString(cStmDictObj, "FormType", CosNewInteger(cdoc, false, 1L));
//long lBoxTop = (long)((float)abs(rect->bottom - rect->top) * yPagePointsPerPixel);
//long lBoxRight = (long)((float)abs(rect->right - rect->left) * xPagePointsPerPixel);
long lBoxTop = (long)abs(rect->bottom - rect->top);
long lBoxRight = (long)abs(rect->right - rect->left);
cBBoxObj = CosNewArray(cdoc, false, 4L);
CosArrayInsert(cBBoxObj, 0L, CosNewInteger(cdoc, false, 0L)); // left
CosArrayInsert(cBBoxObj, 1L, CosNewInteger(cdoc, false, lBoxTop)); // top
CosArrayInsert(cBBoxObj, 2L, CosNewInteger(cdoc, false, lBoxRight)); // right
CosArrayInsert(cBBoxObj, 3L, CosNewInteger(cdoc, false, 0L)); // bottom
CosDictPutKeyString(cStmDictObj, "BBox", cBBoxObj);
// Create Resource dictionary for XObject.
cResObj = CosNewDict(cdoc, false, 5L);
// Add Font resource to Resources dictionary.
fontResObj = CosNewDict(cdoc, true, 1L);
fontResObj2 = CosNewDict(cdoc, true, 5L);
cObj = CosNewNameFromString(cdoc, false, "Font");
CosDictPutKeyString(fontResObj2, "Type", cObj);
cObj = CosNewNameFromString(cdoc, false, "TrueType");
CosDictPutKeyString(fontResObj2, "Subtype", cObj);
cObj = CosNewNameFromString(cdoc, false, CurrentTickItem->FontName.c_str());
CosDictPutKeyString(fontResObj2, "Name", cObj);
cObj = CosNewNameFromString(cdoc, false, sFontName);
CosDictPutKeyString(fontResObj2, "BaseFont", cObj);
//cBBoxObj = CosNewArray(cdoc, false, 4L);
//CosArrayInsert(cBBoxObj, 0L, CosNewInteger(cdoc, false, 0L)); // left
//CosArrayInsert(cBBoxObj, 1L, CosNewInteger(cdoc, false, 0L)); // top
//CosArrayInsert(cBBoxObj, 2L, CosNewInteger(cdoc, false, 0L)); // right
//CosArrayInsert(cBBoxObj, 3L, CosNewInteger(cdoc, false, 0L)); // bottom
//CosDictPutKeyString(fontResObj2, "FontBBox", cBBoxObj);
cObj = CosNewNameFromString(cdoc, false, "[-8 -280 995 855]");
CosDictPutKeyString(fontResObj2, "FontBBox", cObj);
CosDictPutKeyString(fontResObj, sFontName, fontResObj2);
CosDictPutKeyString(cResObj, "Font", fontResObj);
// Set up ProcSet Resources.
cProcSetObj = CosNewArray(cdoc, false, 2L);
CosArrayPut(cProcSetObj, 0L, CosNewNameFromString(cdoc, false, "PDF"));
CosArrayPut(cProcSetObj, 1L, CosNewNameFromString(cdoc, false, "Text"));
CosDictPutKeyString(cResObj, "ProcSet", cProcSetObj);
// Put Resources dictionary in XObject's stream dictionary.
CosDictPutKeyString(cStmDictObj, "Resources", cResObj);
// Set the stream object (now a Forms XObject) as the normal (N) key
// and add to the appearance (AP) key.
CosDictPut(cAPDictObj, FaceNormal_K, cStmObj);
CosDictPutKeyString(cAnnotObj, Appearance_KStr, cAPDictObj);
}
Copy link to clipboard
Copied
Well, you've shared the code, but what next? What actually happens? What did you want to happen instead?
Rather than forcing us to step through the code for hours, or make our own test plug-in, you might consider sharing a very, very simple PDF which is the result of this code.
Update: I noticed one issue. You can't do this: CosNewNameFromString(cdoc, false, "[-8 -280 995 855]")
To create an array you have to make a Cos array and put the elements into it.
Copy link to clipboard
Copied
odd; that's just stuff left from the STAMPR sample. It works.
Copy link to clipboard
Copied
When asking for free help, it's best to provide simple (short) and concise explanations. Provide only the code which is necessary for the issue. And describe what is and is not happening.