🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.acrobat.sdk
Article #211

Export annotations to FDF file

#211
From: Alexander Zuban
Date: Thu, 19 Mar 2009 09:10
126 lines
5062 bytes
Hello,

We develop our Acrobat plug-in which is export annotations from the
document to file. We faced with the problem, that when annotation is
open in popup editor, export function not saves it correctly. As a
workaround we try to detect if there are any open annotations and then
ask user to close them before proceed, but this also not work, because
when user open annotation with context menu, then application return
it's state correctly, but when popup was opened with double click,
then annotation state is not recognized as opened. I attached to the
current case a code snippet which is scan document for the annotations
and check state of the annotation and annotation popup. After that it
exports annotations to file. Please could you advice are there any
solution for this problem? We noticed that Adobe close all open
annotations before export to data file, are there the same think
available for plug-In ( PDTextAnnotSetOpen is not work)?

Are somebody faced with the simular problem and have a solution for
it?

{{{
void SaveFDFFile ()
{
	ASFileSys fileSys = ASGetDefaultFileSys();  // No support for foreign
file systems
	ASPathName volatile fdfPathName = NULL;
	AVDoc avDoc = AVAppGetActiveDoc();
	PDDoc  pdDoc = AVDocGetPDDoc (avDoc);
	bool g_hasOpenPopup = false;

	//check annotations
	DURING
	//get document information
	ASInt32 lastPage = PDDocGetNumPages(pdDoc) - 1;

	PDPage pdPage;
	ASInt32 annotCount;
	PDAnnot annotation;
	//check each page of the document
	for (ASInt32 i=0; i<=lastPage; i++) {
		pdPage = PDDocAcquirePage(pdDoc, i);
		annotCount = PDPageGetNumAnnots(pdPage);

		//check each annotation on the page
		for (ASInt32 j=0; j<annotCount; j++) {
			annotation = PDPageGetAnnot(pdPage, j);
			if(PDAnnotIsValid(annotation)) {
				CosObj dict = PDAnnotGetCosObj(annotation);
				if(PDTextAnnotIsOpen(annotation)){
					g_hasOpenPopup = true;	//never get here when open with double
click
				}
				//check using popup property
				if(CosDictKnown(dict, ASAtomFromString("Popup"))){
					CosObj popup = CosDictGet(dict, ASAtomFromString("Popup"));
					if(PDTextAnnotIsOpen(popup)){
						g_hasOpenPopup = true;		//never get here when open with double
click
					}

				}
			}
		}
		PDPageRelease (pdPage);
	}

	HANDLER
		char buf[255];
    AVAlertNote(ASGetErrorString(ERRORCODE, buf, 254));
	END_HANDLER

	//export
    ASInt32 exportCount;
	PDDocWillExportAnnotCallback exportCallback;
    exportCallback = ASCallbackCreateProto
(PDDocWillExportAnnotCallback, ExportFilter);
    CosDoc fdfDoc = PDDocExportNotes(pdDoc, NULL, NULL, NULL, NULL,
exportCallback, &exportCount);
	ASCallbackDestroy(exportCallback);


    //save annotations
	fdfPathName = ASFileSysCreatePathName (fileSys, ASAtomFromString
("Cstring"),"test.fdf", 0);
	ASInt32 errorCode;
	ASFile volatile fdfFile = NULL;
	CosDocSaveParamsRec params;

	// Initialize save params
	memset (&params, 0, sizeof(CosDocSaveParamsRec));
	params.size = sizeof(CosDocSaveParamsRec);
	params.header = "%FDF-1.2";

	DURING
		if (fdfDoc == NULL) {
			// if there were no annotations, create a blank document
			fdfDoc = CosDocCreate(0);
		}
		// Create/Open the file
		errorCode = ASFileSysOpenFile (fileSys, fdfPathName, ASFILE_CREATE |
ASFILE_WRITE, (ASFile*)&fdfFile);

		// If we succeeded, save the doc to the file
		if (errorCode == 0) {
			CosDocSaveToFile (fdfDoc, fdfFile, cosSaveFullSave, &params);
			CosDocClose (fdfDoc);
			ASFileClose (fdfFile);
		} else {
			AVAlertNote("Error in saving the fdf file!");
			ASRaise (ASFileError(fileErrOpenFailed));
		}
		HANDLER
			if (fdfFile){
				ASFileClose (fdfFile);
			}
			RERAISE();
	END_HANDLER

		if (fdfPathName){
			ASFileSysReleasePath (fileSys, fdfPathName);
	}
}

}}}

Thank you in advance!
Technical Details
Message-ID: <cc022451-9d0a-4bf8-835b-89ad74301c64@o11g2000yql.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!o11g2000yql.googlegroups.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10177e,5d7e8ac1bb4a86a4,start
X-Google-Attributes: gid10177e,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!o11g2000yql.googlegroups.com!not-for-mail
From: Alexander Zuban <alexander.zuban@gmail.com>
Newsgroups: adobe.acrobat.sdk
Subject: Export annotations to FDF file
Date: Thu, 19 Mar 2009 02:10:41 -0700 (PDT)
Organization: http://groups.google.com
Lines: 126
Message-ID: <cc022451-9d0a-4bf8-835b-89ad74301c64@o11g2000yql.googlegroups.com>
NNTP-Posting-Host: 83.243.68.5
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1237453841 13309 127.0.0.1 (19 Mar 2009 09:10:41 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 19 Mar 2009 09:10:41 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: o11g2000yql.googlegroups.com; posting-host=83.243.68.5; 
 posting-account=uq2SQgoAAACWVuYrznO6Bs7gagdnYSUr
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) 
 AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.48 Safari/525.19,gzip(gfe),gzip(gfe)