Skip to main content
Known Participant
June 4, 2019
Answered

How to decode file after extracting it from annotation

  • June 4, 2019
  • 2 replies
  • 2029 views

I have the following code for extracting 3d data ( file ) from my annotation , but as the result I have encoded ( compressed ) file , how I can get the decoded file ( not compressed ) ?

I've tried cosOpenFiltered and cosOpenRaw and it doesn't work

char* ptr1 = new char[2800000];

                        ASFile asGLTFFile = NULL;

                        CosObj stm = PDAnnotGetCosObj(annot);

                       

                        CosObj stm3d = CosDictGetKeyString(stm,"3DD");

                      

                        ASStm streamopen = CosStreamOpenStm(stm3d,cosOpenUnfiltered);

                      

                        ASTArraySize lenghth = CosStreamLength(stm3d);

                        ASTCount a = ASStmRead(ptr1,1,lenghth,streamopen);

                       

#if WIN_PLATFORM

                        const char* GLTFStringName = "C:\\setDefaultCamera.gltf";

#else

                        const char* GLTFStringName = "/Users/Shared/file1.gltf";

#endif

                        BuildFile(GLTFStringName);

                   

#ifdef    WIN_PLATFORM

                        const char* strPathFlag = "Cstring";

#else

                        const char* strPathFlag = "POSIXPath";

#endif

                       

                        ASPathName GLTFPathName = ASFileSysCreatePathName (ASGetDefaultFileSys(),

                                                              ASAtomFromString(strPathFlag), GLTFStringName, 0);

                        ASInt32 BRet = ASFileSysOpenFile(ASGetDefaultFileSys(), GLTFPathName, ASFILE_WRITE, &asGLTFFile);

     

                        ASFileSysReleasePath (ASGetDefaultFileSys(), GLTFPathName);

                            ASTArraySize Bret = ASFileWrite(asGLTFFile,ptr1,lenghth);

                                ASStmClose(streamopen);

                                ASFileClose(asGLTFFile);

This topic has been closed for replies.
Correct answer lrosenth

And how I can get the uncompressed length , I really can't get this , If I'm trying to read and write the entire stream , I have the document reading error (20 )

                        ASFile asGLTFFile = NULL;

// getting whole stream

                        CosObj stm = PDAnnotGetCosObj(annot);

                        CosObj stm3d = CosDictGetKeyString(stm,"3DD");

                      

                        ASStm streamopen = CosStreamOpenStm(stm,cosOpenFiltered);

                        ASTArraySize lenghth = CosStreamLength(stm);

                       

                       char* pBuff = (char*)ASmalloc(lenghth);

                        ASTCount a = ASStmRead(pBuff,1,lenghth,streamopen);

                       

#if WIN_PLATFORM

                        const char* GLTFStringName = "C:\\setDefaultCamera.gltf";

#else

                        const char* GLTFStringName = "/Users/Shared/file1.gltf";

#endif

                        BuildFile(GLTFStringName);

                   

#ifdef    WIN_PLATFORM

                        const char* strPathFlag = "Cstring";

#else

                        const char* strPathFlag = "POSIXPath";

#endif

                       

                        ASPathName GLTFPathName = ASFileSysCreatePathName (ASGetDefaultFileSys(),

                                                              ASAtomFromString(strPathFlag), GLTFStringName, 0);

                        ASInt32 BRet = ASFileSysOpenFile64(ASGetDefaultFileSys(), GLTFPathName, ASFILE_READ|ASFILE_WRITE, &asGLTFFile);

                      

                        ASFileSysReleasePath (ASGetDefaultFileSys(), GLTFPathName);

                       

                        if ((BRet == 0) && (asGLTFFile != NULL))

                        {

                            ASTArraySize Bret = ASFileWrite(asGLTFFile,pBuff,strlen(pBuff));

                           

                            if(Bret!=0)

                            {

                                ASStmClose(streamopen);

                                ASFileClose(asGLTFFile);

                               

                            }

                            else

                            {

                                AVAlertNote("Error in writting");

                            }

                           

                        }


Keep reading until you run out of data….

char buffer[9999];

ASInt32 readItems, totalRead = 0;

do {

readItems = Read(buffer, sizeof(buffer));

outBuffer.insert(outBuffer.end(), buffer, buffer + readItems);

totalRead += readItems;

} while(readItems > 0);

2 replies

Known Participant
June 4, 2019

I've tried but it still doesn't work, as the result I have compressed file when I use cosOpenFiltered , for example I have the source file 2.8 megabytes , then I add this file to pdf with the help of annotation , as the result after saving pdf with 3d annotation , I have the pdf file that is 1.9 mb ( with compressed file ) ,then im extract file from annotation , and my new file ( from Annot ) is also 1.9 mb , when source file is 2.8mb , I've tried cosOpenFilter cosOpenUnfiltered and it doesn't work

lrosenth
Adobe Employee
Adobe Employee
June 4, 2019

cosOpenFiltered – that tells the SDK to do any decompression on the stream.

Known Participant
June 4, 2019

Maybe I should write whole stream ? Not only under 3dd key ?

lrosenth
Adobe Employee
Adobe Employee
June 4, 2019

You are getting the COMPRESSED length and using that.

Yes, you need to write the entire stream…