Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

SDK C++ - Getting string/stream for a CosObj

Explorer ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

 

What I am trying to do is create the apperance stream for an annotation. I have a PDEForm object as a CosObj that I have attempted to create an appearnce sttream from using  converted sample code. I have been unable to locate a sample that does exactly this from an in memory CosObj, though the Embed3DData sample comes pretty close. To debug, and possibly insert into the stream, I would like to get the stream that would be written for the CosObj. How do I do this? I have not found an API call that does this.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

966
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , May 10, 2023 May 10, 2023

It is working now without ever eplicitly creating a stream or working out the structure.

Again, I apologize if I musinderstand this:

"So you need to work out the exact structure you need, then make it one element at a time. People starting with the API often assume you can include chunks of PDF "code", but no."

but it turned out I had a coordinate computation off and the image was outside the form. What I am doing does work. You don't have to go through and generate all the elements for the stream.

...

Votes

Translate
LEGEND ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

I think you might be taking this sort of thing as a stream

<< /Type /Annot /AP << /N << 3 0 R >> >> 

(as seen inside a PDF). But that's not a stream. The stream is here

3 0 obj

<< /Length 51 >>

stream

BT /T12  12 Tf (Hello Tj ET

endstream

That's the stream object, but you don't code that in your Cos object. To make this stream you need to use CosNewStream, and what you pass to it is an ASStm whose contents are just "BT /T12  12 Tf (Hello Tj ET"


To make << /Type /Annot /AP << /N << 3 0 R >> >> 

you would use CosNewDict several times, and CosDictPut to store a reference to the stream object you already made.

So you need to work out the exact structure you need, then make it one element at a time. People starting with the API often assume you can include chunks of PDF "code", but no.

 

If you want to read the contents of an existing Cos stream object, there is an API to return an ASStm, which you can then read from.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

"People starting with the API often assume you can include chunks of PDF "code", but no."

Actually, it turns out you can. Or quite possibly I am misunderstanding what you are saying.

It occured to me that I could look at a PDF file in a text editor. I saved a completely blank one and then added one annotation with my tool using this code:

attributesDict = CosNewDict(cdoc, false, 5);

CosDictPutKeyString(attributesDict, "N", cosForm);
CosDictPutKeyString(cAnnotObj, "AP", attributesDict);

cosForm is the CosObj of a form I created from an image. The image I add to the  PDF file in another location, so I knew it was valid. I had also done some tests like CosDictKnownKeyString(cosForm, "Resources"), which returned true, to give me at least a little confidence teh CosObj for the form was valid.
Anyway, looking at the file with one annotation, there is indeed a streamed annotation with my form and image. Fortunately I have another application that should produce a working annotation stream for me to lok at. I should have thought of just using a text editor earlier before posting. I am not replying to give you a hard time; you were guenuinely trying to help and I thought you might like to have this additional information. Again, it is possible I misunderstood your reply and you already know this.

13 0 obj <</Annots 18 0 R/CropBox[0.0 0.0 612.0 792.0]/MediaBox[0.0 0.0 612.0 792.0]/Parent 9 0 R/Resources<<>>/Rotate 0/Type/Page>> endobj 14 0 obj <</BBox 20 0 R/Length 33/Resources<</ProcSet[/PDF/ImageC]/XObject<</Im0 15 0 R>>>>/Subtype/Form>>stream
q
17 0 0 31 360 180 cm
/Im0 Do
Q

endstream endobj 15 0 obj <</BitsPerComponent 8/ColorSpace/DeviceRGB/Filter/DCTDecode/Height 31/Length 876/Name/X/Subtype/Image/Type/XObject/Width 17>>stream
ÿØÿà JFIF  ` ` ÿÛ C  
  $.' ",#(7),01444'9=82<.342ÿÛ C  2!!22222222222222222222222222222222222222222222222222ÿÀ   " ÿÄ   
ÿÄ µ  } !1AQa"q2‘¡#B±ÁRÑð$3br‚
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ   
ÿÄ µ  w !1AQaq"2B‘¡±Á #3RðbrÑ
$4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ   ? ÷ú(®sƾ-·ð~‚ׯžêVò­-—¬²ƒè:Ÿñ"´£Fuª*tÕÛ¡.¶–PÇ 'š+ðG„§ÓÌž ñ‹¯_ ÓJÜýOHÓÐÁÇÓ ¢¯N:Ž—5ºô¿[yyõ&-µsCVñ[h~"ÓôýCOhìu <˜5—r 1Â:àm$ð9 þƍj|uñëÄwHGÑ$kM5OI&ç—Üg¡ÿ w¸5ÜëúŸˆô;­*ù7Cp…s€JÌ=Áæ—BÑ­|=¡ÙéVjÑ„,{±÷'$ýk®ž** ÓV¨×/•ºµæöô¿qJ-»tþ¿¯‘£EWšYÿÙ
endstream endobj 16 0 obj <</Filter/FlateDecode/First 17/Length 181/N 3/Type/ObjStm>>stream
hÞt˱‚0…áW¹0HoK …Ü4»¬ˆ¤¨‰¾½ð .çä>*¦ íŸ@·BÛç9ÁmDƒ,«ÆQúY›Uûj´y€šA-ã0Áq˜«M@ÊëF.@ù΋‚T³uƺõ¿8'g¿Î²JqŽâ€ÜCôÒí:Êy‹ba*R 1†È¶Nd˜Ê¤'·÷Ý}_†µoií슢Cˆ°°ÿ 0 ¹<K
endstream endobj

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

Unfortunately the encoding of the file produced by the other application makes a comparison difficult at best.

 

13 0 obj <</Annots 20 0 R/CropBox [0 0 612 792]/MediaBox [0 0 612 792]/Parent 9 0 R/Resources <<>>/Rotate 0/Type /Page>> endobj 14 0 obj <</Filter /FlateDecode/First 20/Length 156/N 4/Type /ObjStm>> stream
xœ=ŽË
Â0De–ººI£ÕB)ø@
–Ú…Vº$RiÓ…oÒJw朹ƒa…%ÃÉ ¸HSÚ5½uàtÐmç<ÀPÐYNgùý(Ð¥wF[Õe™76¾!D¹l•Wã‘ÓÎ(̶FÚ7rùRóÝãÁE @·{$loLMWб)›GDtÒÏn2GQÿ'„Nÿÿ4Ï5m
endstream endobj 18 0 obj <</BBox [24.5088 757.318 31.8496 776.685]/Filter /FlateDecode/Length 72/Resources 5 0 R/Subtype /Form>> stream
xœÓw3P0TIãu
á5T0 ¢t^CC=Csc×ÐBÏÀÈÐHÁÈDÏÔÀÂBÁÜÔRÏÔÌH!$—W#[S!$‹×5„ ìÎ$
endstream endobj

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

LATEST

It is working now without ever eplicitly creating a stream or working out the structure.

Again, I apologize if I musinderstand this:

"So you need to work out the exact structure you need, then make it one element at a time. People starting with the API often assume you can include chunks of PDF "code", but no."

but it turned out I had a coordinate computation off and the image was outside the form. What I am doing does work. You don't have to go through and generate all the elements for the stream. In fact, you don't need to create a stream at all to generate an appearance stream for an annotation. Just create a dictionary, add the CosObj for the form with the "N" key and the add that dictionary to the annotaion's dictionary with the "AP" key. That's all that's needed and it generates all the streamed objects for you.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines