0% found this document useful (0 votes)
49 views

PDF Programming

This document provides an overview of key concepts for working with PDF files using the Adobe PDF Library SDK, including: - Different SDK implementations may have varying feature sets. The document covers accessing and modifying PDF content, extraction, rendering, and printing. - PDF objects like documents, pages, annotations that are opaque in Acrobat but can be inspected in the SPDF debugger. Different object types are not interchangeable. - Atoms are used instead of literal strings for improved memory and ease of use. - File systems represented by ASFileSys for reading/writing PDF data in different storage formats. - Error handling uses DURING/HANDLER/ENDHANDLER blocks in Acrobat

Uploaded by

santhoshia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

PDF Programming

This document provides an overview of key concepts for working with PDF files using the Adobe PDF Library SDK, including: - Different SDK implementations may have varying feature sets. The document covers accessing and modifying PDF content, extraction, rendering, and printing. - PDF objects like documents, pages, annotations that are opaque in Acrobat but can be inspected in the SPDF debugger. Different object types are not interchangeable. - Atoms are used instead of literal strings for improved memory and ease of use. - File systems represented by ASFileSys for reading/writing PDF data in different storage formats. - Error handling uses DURING/HANDLER/ENDHANDLER blocks in Acrobat

Uploaded by

santhoshia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

What’s in there?

Not every implementation of the “SDK”has 100% of the same features (even between Acrobat
and PDFLibrary).

Access to everything in a PDF file Read, Add, Modify

​Content extraction
​PDF rendering

to bitmap or platform window Printing

Everything is an “object” ​CosObj

CosString, CosInteger, CosArray, CosDict PDDoc

PDPage, PDBookmark, PDAnnot AVDoc

AVWindow, AVPageView, AVTool

PDEObject

PDEText, PDEImage, PDEPath

PDF Objects

Acrobat treats the objects as opaque, while SPDF lets you view their contents in the debugger
(incl. objectID!)

All objects are NOT created equal!

PDDoc != AVDoc != CosObj

Although Acrobat allows you to use them interchangeably, SPDF does not and in fact will
generate compile time errors

PDDoc == CPDDoc, CosObj == CCosObj

But there are API calls to go between them ​• ​PDDocGetCosObj()


ASAtoms

Rather than working with literal strings all the time, many SDK calls take ASAtoms.

Think of them as a list of name/values pairs which are keyed by strings.

improved memory management & ease of use

As such, many developers use a single set of global ASAtom variables.

• ​SPDF even includes macros for doing this

​ASAtomFromString()
​ASAtomGetString()
​ASAtomExistsForString()

Fun with File Systems

ASFileSys

A base “class” the represents a way for the SDK to read & write the data of a PDF file. (a fancy
Stream)

​Acrobat provides only file-based ones


​SPDF also provides memory, FTP & HTTP

ASPathName

ASFileSysCreatePathName (const ASFileSys fileSys, ASAtom pathSpecType, const void*


pathSpec, const void* mustBeZero);

ASPathFromPlatformPath(void* platformPath)

Error Handling

DURING/HANDLER/ENDHANDLER In Acrobat itself, these map to

something akin to setjmp/longjmp


• ​Trying to mix them with C++ exceptions can be a problem.

• ​You can’t nest them!

SPDF actually defines them as try/catch

blocks

ERRORCODE

More on Error Handling

Unfortunately, Acrobat does NOT always “throw”. Sometimes you have to use other methods

foo == NULL, PDxxxIsValid(), etc. CosNull != NULL

If want a null CosObject, you can call CosNewNull() to get one. BUT that should be treated as a
valid object and NOT as NULL.

Error Handling Sample

DURING

theASPathName = ASPathFromPlatformPath( inPDF ) ; // Create the ASPathName thePDDoc =


PDDocOpen( theASPathName, NULL, NULL, true ) ; // Open the PDDoc if ( thePDDoc ==
(PDDoc)NULL ) {

fprintf( gOutputFile, "# Unable to open PDF file - %s\n", inPDF ) ;

ASRaise ( ASFileError( fileErrOpenFailed ) ) ; }

HANDLER

theError = ERRORCODE ;

if ( theASPathName != NULL ) {

ASFileSysReleasePath( NULL, theASPathName ) ;

theASPathName = ( ASPathName )NULL ; }


ASGetErrorString( theError, theAcrobatMessage, sizeof( theAcrobatMessage ) ) ; fprintf( stderr,
"# Error: %s\n", theAcrobatMessage ) ;

return ;

END_HANDLER

You might also like