Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PDF_MEMORY_FILESYS 16
- BYTE lpBuffer[] = data buffer containing pdf binary
- DWORD dwDataSize = sizeof( lpBuffer );
- DWORD dwDataIndex = 0; // acts as an index pointer into buffer
- void* PDFUtilAlloc( void* pClientData, ASSize_t sizeData )
- {
- // return allocator of your choice (or malloc)
- }
- void* PDFUtilRealloc( void* pClientData, void* pAllocData, ASSize_t sizeData )
- {
- // return re-allocator of your choice (or realloc)
- }
- void PDFUtilFree( void* pClientData, void* pAllocData )
- {
- // free memory of your choice (or free)
- }
- ASSize_t PDFUtilAvail( void* pClientData )
- {
- return INT_MAX;
- }
- ASErrorCode PDFOpen( ASPathName pathName, ASFileMode mode, ASMDFile *fP )
- {
- dwDataIndex = 0;
- return 0;
- }
- ASErrorCode PDFClose( ASMDFile f )
- {
- dwDataIndex = 0;
- return 0;
- }
- ASErrorCode PDFFlush( ASMDFile f )
- {
- return 0;
- }
- ASErrorCode PDFSetPos( ASMDFile f, ASFilePos pos )
- {
- dwDataIndex = (DWORD)pos;
- return 0;
- }
- ASErrorCode PDFGetPos( ASMDFile f, ASFilePos *pos )
- {
- *pos = (ASFilePos)dwDataIndex;
- return 0;
- }
- ASErrorCode PDFSetEof( ASMDFile f, ASFilePos pos )
- {
- return 0;
- }
- ASErrorCode PDFGetEof( ASMDFile f, ASFilePos *pos )
- {
- *pos = (ASFilePos)dwDataSize;
- return 0;
- }
- ASSize_t PDFRead( void *ptr, ASSize_t size, ASSize_t count, ASMDFile f, ASErrorCode *pError )
- {
- *pError = 0;
- if ( ptr == NULL )
- return 0;
- DWORD dwRemaining = dwDataSize - dwDataIndex;
- DWORD dwReadSize = min( dwRemaining, (DWORD)( size * count ) );
- CopyMemory( ptr, &lpBuffer[ dwDataIndex ], dwReadSize );
- dwDataIndex += dwReadSize;
- return (ASSize_t)dwReadSize;
- }
- ASSize_t PDFWrite( void *ptr, ASSize_t size, ASSize_t count, ASMDFile f, ASErrorCode *pError )
- {
- *pError = 0;
- return 0;
- }
- ASErrorCode PDFRemove( ASPathName pathName )
- {
- return 0;
- }
- ASErrorCode PDFRename( ASMDFile* f, ASPathName oldPath, ASPathName newPath )
- {
- return 0;
- }
- ASBool PDFIsSameFile( ASMDFile f, ASPathName pathName, ASPathName newPathName )
- {
- return 0;
- }
- ASErrorCode PDFGetName( ASPathName pathName, char *name, ASTArraySize maxLength )
- {
- return 0;
- }
- ASPathName PDFGetTempPath( ASPathName pathName )
- {
- return (ASPathName)PDF_MEMORY_FILESYS;
- }
- ASPathName PDFCopyPathName( ASPathName pathName )
- {
- return (ASPathName)PDF_MEMORY_FILESYS;
- }
- char *PDFGetDiPathFromPath( ASPathName path, ASPathName relativeToThisPath )
- {
- return (char *)"";
- }
- ASPathName PDFGetPathFromDIPath( const char* diPath, ASPathName relativeToThisPath )
- {
- return (ASPathName)PDF_MEMORY_FILESYS;
- }
- void PDFDisposePathName( ASPathName pathName )
- {
- }
- ASAtom PDFGetFileSysName()
- {
- return NULL;
- }
- ASDiskSpace PDFGetStorageFreeSpace( ASPathName pathName )
- {
- return INT_MAX;
- }
- ASErrorCode PDFFlushVolume( ASPathName pathName )
- {
- return 0;
- }
- ASFlagBits PDFGetFileFlags( ASMDFile f )
- {
- return NULL;
- }
- ASErrorCode PDFReadAsync( ASIORequest req )
- {
- return 0;
- }
- ASErrorCode PDFWriteAsync( ASIORequest req )
- {
- return 0;
- }
- void PDFAbortAsync( ASMDFile f )
- {
- }
- ASErrorCode PDFMReadRequest( ASMDFile f, ASFile aFile, ASTFilePos *blockPairs, ASTArraySize nBlockPairs )
- {
- return 0;
- }
- ASFlagBits PDFGetStatus( ASMDFile f )
- {
- return 0;
- }
- ASErrorCode PDFYield( ASMDFile f )
- {
- return 0;
- }
- ASPathName PDFCreatePathName( ASAtom pathSpecType, const void *pathSpec, const void *mustBeZero )
- {
- return (ASPathName)PDF_MEMORY_FILESYS;
- }
- ASPathName PDFAcquireFileSysPath( ASPathName pathName, ASFileSys newFileSys )
- {
- return (ASPathName)PDF_MEMORY_FILESYS;
- }
- void PDFClearOutstandingMReads( ASMDFile f )
- {
- }
- ASErrorCode PDFGetItemProps( ASPathName pathName, ASFileSysItemProps props )
- {
- return 0;
- }
- ASFolderIterator PDFFirstFolderItem( ASPathName folderPath, ASFileSysItemProps props, ASPathName *itemPath )
- {
- return NULL;
- }
- ASBool PDFNextFolderItem( ASFolderIterator folderIter, ASFileSysItemProps props, ASPathName *itemPath )
- {
- return 0;
- }
- void PDFDestroyFolderIterator( ASFolderIterator folderIter )
- {
- }
- ASlFileMode PDFSetFileMode( ASMDFile f, ASlFileMode modeValue, ASMaskBits modeMask )
- {
- return NULL;
- }
- char* PDFGetUrlFromPath( ASPathName path )
- {
- return (char *)"";
- }
- ASPathName PDFGetParent( ASPathName path )
- {
- return NULL;
- }
- ASErrorCode PDFCreateFolder( ASPathName path )
- {
- return 0;
- }
- ASErrorCode PDFRemoveFolder( ASPathName path )
- {
- return 0;
- }
- char* PDFDisplayStringFromPath( ASPathName path )
- {
- return (char *)"";
- }
- void PDFSetTypeAndCreator( ASPathName path, ASlFileMode type, ASlFileMode creator )
- {
- }
- void PDFGetTypeAndCreator( ASPathName path, ASlFileMode *type, ASlFileMode *creator )
- {
- }
- ASMDFile PDFReopen( ASMDFile f, ASFileMode newMode, ASErrorCode *pError )
- {
- *pError = 0;
- dwDataIndex = 0;
- return NULL;
- }
- ASErrorCode PDFHardFlush( ASMDFile f )
- {
- return 0;
- }
- void* PDFGetPlatformThing( ASPathName path, ASAtom thing )
- {
- return NULL;
- }
- ASInt32 PDFGetItemPropsAsCab( ASPathName pathName, ASCab theCab )
- {
- return 0;
- }
- ASInt32 PDFCanPerformOpOnItem( ASPathName pathName, const char *op )
- {
- return 0;
- }
- ASInt32 PDFPerformOpOnItem( ASPathName pathName, const char *op, ASCab params )
- {
- return 0;
- }
- ASInt32 PDFAcquirePlatformPath( ASPathName path, ASAtom platformPathType, ASPlatformPath *platformPath )
- {
- return 0;
- }
- void PDFReleasePlatformPath( ASPlatformPath platformPath )
- {
- }
- ASErrorCode PDFGetNameAsText( ASPathName pathName, ASText name )
- {
- return 0;
- }
- ASErrorCode PDFDisplayASTextFromPath( ASPathName path, ASText displayText )
- {
- return 0;
- }
- void PDFRangeArrived( ASInt32 start, ASInt32 length, void* clientData )
- {
- }
- ASBool PDFCanSetEof( ASMDFile f, ASFilePos pos )
- {
- return 0;
- }
- ASErrorCode PDFDIPathFromPathEx( ASPathName path,ASPathName relativeToThisPath,ASText diPathText)
- {
- return 0;
- }
- ASPathName PDFPathFromDIPathEx( ASConstText diPathText,ASPathName relativeToThisPath )
- {
- return (ASPathName)PDF_MEMORY_FILESYS;
- }
- ASErrorCode PDFGetFilePosLimit( ASFilePos64 *pos )
- {
- return 0;
- }
- ASErrorCode PDFOpen64( ASPathName pathName, ASFileMode mode, ASMDFile *fP )
- {
- return PDFOpen( pathName, mode, fP );
- }
- ASErrorCode PDFSetPos64( ASMDFile f, ASFilePos64 pos )
- {
- return PDFSetPos( f, (ASFilePos)pos );
- }
- ASErrorCode PDFGetPos64( ASMDFile f, ASFilePos64 *pos )
- {
- return PDFGetPos( f, (ASFilePos*)pos );
- }
- ASErrorCode PDFSetEof64( ASMDFile f, ASFilePos64 pos )
- {
- return 0;
- }
- ASErrorCode PDFGetEof64( ASMDFile f, ASFilePos64 *pos )
- {
- return PDFGetEof( f, (ASFilePos*)pos );
- }
- ASErrorCode PDFGetNameForDisplay( ASPathName pathName, ASText nameForDisplay )
- {
- return 0;
- }
- ASDiskSpace64 PDFGetStorage64( ASPathName pathName )
- {
- return 0;
- }
- ...
- PDFLDataRec pdflData;
- ZeroMemory( &pdflData, sizeof( PDFLDataRec ) );
- pdflData.size = sizeof( PDFLDataRec );
- TKAllocatorProcs PDFUtilAllocProcs =
- {
- PDFUtilAlloc,
- PDFUtilRealloc,
- PDFUtilFree,
- PDFUtilAvail,
- NULL
- };
- // use custom allocators
- pdflData.allocator = &PDFUtilAllocProcs;
- if ( PDFLInit( &pdflData ) != 0 )
- return FALSE;
- ASFileSysRec pdfMemoryFileSys;
- ZeroMemory( &pdfMemoryFileSys, sizeof( ASFileSysRec ) );
- pdfMemoryFileSys.size = sizeof( ASFileSysRec );
- // provide callback procedures for memory file system
- pdfMemoryFileSys.open = PDFOpen;
- pdfMemoryFileSys.close = PDFClose;
- pdfMemoryFileSys.flush = PDFFlush;
- pdfMemoryFileSys.setpos = PDFSetPos;
- pdfMemoryFileSys.getpos = PDFGetPos;
- pdfMemoryFileSys.seteof = PDFSetEof;
- pdfMemoryFileSys.geteof = PDFGetEof;
- pdfMemoryFileSys.read = PDFRead;
- pdfMemoryFileSys.write = PDFWrite;
- pdfMemoryFileSys.remove = PDFRemove;
- pdfMemoryFileSys.rename = PDFRename;
- pdfMemoryFileSys.isSameFile = PDFIsSameFile;
- pdfMemoryFileSys.getName = PDFGetName;
- pdfMemoryFileSys.getTempPathName = PDFGetTempPath;
- pdfMemoryFileSys.copyPathName = PDFCopyPathName;
- pdfMemoryFileSys.diPathFromPath = PDFGetDiPathFromPath;
- pdfMemoryFileSys.pathFromDIPath = PDFGetPathFromDIPath;
- pdfMemoryFileSys.disposePathName = PDFDisposePathName;
- pdfMemoryFileSys.getFileSysName = PDFGetFileSysName;
- pdfMemoryFileSys.getStorageFreeSpace = PDFGetStorageFreeSpace;
- pdfMemoryFileSys.flushVolume = PDFFlushVolume;
- pdfMemoryFileSys.getFileFlags = PDFGetFileFlags;
- pdfMemoryFileSys.readAsync = PDFReadAsync;
- pdfMemoryFileSys.writeAsync = PDFWriteAsync;
- pdfMemoryFileSys.abortAsync = PDFAbortAsync;
- pdfMemoryFileSys.yield = PDFYield;
- pdfMemoryFileSys.mreadRequest = PDFMReadRequest;
- pdfMemoryFileSys.getStatus = PDFGetStatus;
- pdfMemoryFileSys.createPathName = PDFCreatePathName;
- pdfMemoryFileSys.acquireFileSysPath = PDFAcquireFileSysPath;
- pdfMemoryFileSys.clearOutstandingMReads = PDFClearOutstandingMReads;
- pdfMemoryFileSys.getItemProps = PDFGetItemProps;
- pdfMemoryFileSys.firstFolderItem = PDFFirstFolderItem;
- pdfMemoryFileSys.nextFolderItem = PDFNextFolderItem;
- pdfMemoryFileSys.destroyFolderIterator = PDFDestroyFolderIterator;
- pdfMemoryFileSys.setFileMode = PDFSetFileMode;
- pdfMemoryFileSys.urlFromPath = PDFGetUrlFromPath;
- pdfMemoryFileSys.getParent = PDFGetParent;
- pdfMemoryFileSys.createFolder = PDFCreateFolder;
- pdfMemoryFileSys.removeFolder = PDFRemoveFolder;
- pdfMemoryFileSys.displayStringFromPath = PDFDisplayStringFromPath;
- pdfMemoryFileSys.setTypeAndCreator = PDFSetTypeAndCreator;
- pdfMemoryFileSys.getTypeAndCreator = PDFGetTypeAndCreator;
- pdfMemoryFileSys.reopen = PDFReopen;
- pdfMemoryFileSys.hardFlush = PDFHardFlush;
- pdfMemoryFileSys.getPlatformThing = PDFGetPlatformThing;
- pdfMemoryFileSys.getItemPropsAsCab = PDFGetItemPropsAsCab;
- pdfMemoryFileSys.canPerformOpOnItem = PDFCanPerformOpOnItem;
- pdfMemoryFileSys.performOpOnItem = PDFPerformOpOnItem;
- pdfMemoryFileSys.acquirePlatformPath = PDFAcquirePlatformPath;
- pdfMemoryFileSys.releasePlatformPath = PDFReleasePlatformPath;
- pdfMemoryFileSys.getNameAsASText = PDFGetNameAsText;
- pdfMemoryFileSys.displayASTextFromPath = PDFDisplayASTextFromPath;
- pdfMemoryFileSys.rangeArrived = PDFRangeArrived;
- pdfMemoryFileSys.canSetEof = PDFCanSetEof;
- pdfMemoryFileSys.diPathFromPathEx = PDFDIPathFromPathEx;
- pdfMemoryFileSys.pathFromDIPathEx = PDFPathFromDIPathEx;
- pdfMemoryFileSys.getfileposlimit = PDFGetFilePosLimit;
- pdfMemoryFileSys.open64 = PDFOpen64;
- pdfMemoryFileSys.setpos64 = PDFSetPos64;
- pdfMemoryFileSys.getpos64 = PDFGetPos64;
- pdfMemoryFileSys.seteof64 = PDFSetEof64;
- pdfMemoryFileSys.geteof64 = PDFGetEof64;
- pdfMemoryFileSys.getNameForDisplay = PDFGetNameForDisplay;
- pdfMemoryFileSys.getStorageFreeSpace64 = PDFGetStorage64;
- DURING
- PDDoc pdDoc = PDDocOpen( (ASPathName)PDF_MEMORY_FILESYS, &pdfMemoryFileSys, NULL, true );
- if ( pdDoc != NULL )
- {
- // do stuff with pdf here
- PDDocClose( pdDoc );
- }
- HANDLER
- int nErrorCode = ERRORCODE;
- END_HANDLER
- PDFLTerm();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement