From: Michal H. <ms...@gm...> - 2009-07-23 08:26:56
|
On Wed, Jul 22, 2009 at 08:13:13PM +0000, Jozef Misutka wrote: > > Hi Jozo, > > how do I add a simple text to the page? I have tried to follow > > operatorAddTextLine script function and my current code: > > > > > > void addText(shared_ptr page, double x, double y, std::string &text) > > { > > // copy of operatorAddTextLine script function with > > // font: PDFEDIT_F1 > > // color: #000000 > > std::string fontName = "PDFEDIT_F1"; > > double fontSize = 10; > > shared_ptr q(new UnknownCompositePdfOperator("q", "Q")); > > shared_ptr BT(new UnknownCompositePdfOperator("q", "Q")); > > you meant BT,ET probably Yeah, copy&paste error. > > > PdfOperator::Operands fontOperands; CName rather than CString here: > > fontOperands.push_back(shared_ptr(CStringFactory::getInstance(fontName)) ); > > fontOperands.push_back(shared_ptr(CRealFactory::getInstance(fontSize))); > > q->push_back(BT,q); > > BT->push_back(createOperator("Tf", fontOperands), getLastOperator(BT)); > > PdfOperator::Operands posOperands; > > posOperands.push_back(shared_ptr(CRealFactory::getInstance(x))); > > posOperands.push_back(shared_ptr(CRealFactory::getInstance(y))); > > BT->push_back(createOperator("Td", posOperands), getLastOperator(BT)); > > PdfOperator::Operands textOperands; there should be textOperands.push_back here: > > posOperands.push_back(shared_ptr(CStringFactory::getInstance(text))); > > BT->push_back(createOperator("Tj", textOperands), getLastOperator(BT)); > > PdfOperator::Operands emptyOperands; > > BT->push_back(createOperator("ET", emptyOperands), getLastOperator(BT)); > > q->push_back(createOperator("Q", emptyOperands), getLastOperator(q)); > > std::deque> stack; > > stack.push_back(q); > > page->addContentStreamToFront(stack); > > } > > > > int main() > > { > > shared_ptr pdf = getPdf(file); > > if (pdfedit_core_dev_init(&argc, &argv)) > > { > > // not able to initialize pdfedit-core-dev > > return 1; > > } > > > > shared_ptr pdf = open_file(argv[1]); > > std::string text="WEEEEEEEEEEEEE"; > > addText(pdf->getPage(1), 10, 10, text); > > pdf->save(); > > return 0; > > } > > > > The code is compilable but I am getting: > > 2:UTILS:stateupdater.cc:checkAndFixOperator:1218: Bad 0-th operand type [String] 0x10 > > terminate called after throwing an instance of 'ElementBadTypeException' > > what(): Content stream operator has incorrect operand type. has bad type > > Aborted > > check the KNOWN_OPERATORS in the same file and you will find what is > expected. check also gui and scripts how is it done properly. Thanks, that helped. Is this the only way how to add a _simple_ string to the document? It seems really hard to write and it took me more than hour to even find out what is necessary (I was looking into scripting). We should definitely create some helper function here. > > i cannot run it now and moreover, i am leaving in few minutes. will be > available in few days. > > /jozo > > > > > which happens at "BT->push_back(createOperator("Tf", fontOperands), getLastOperator(BT));" > > > > What am I doing wrong? > > > > Thanks > > -- > > Michal Hocko > > _________________________________________________________________ > Bing? brings you maps, menus, and reviews organized in one place. Try it now. > http://www.bing.com/search?q=restaurants&form=MLOGEN&publ=WLHMTAG&crea=TXT_MLOGEN_Local_Local_Restaurants_1x1 -- Michal Hocko |