Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
APDFL sample app which reproduces Acrobat's Document Properties Initial View tab.
// Project: DocDescription - Sample app which reproduces Acrobat's Document Properties Initial View tab.
#ifndef MAC_ENV
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include "PDFInit.h"
#include "CosCalls.h"
#include "CorCalls.h"
#include "ASCalls.h"
#include "ASExtraCalls.h"
#include "PDCalls.h"
#include "PagePDECntCalls.h"
#include "PDMetadataCalls.h"
#include "MyPDFLibUtils.h"
#ifdef MAC_ENV
#include "MacUtils.h"
void MainProc(int argc, char **argv)
PDDoc pdDoc;
int i = 0;
if (argc > 1)
pdDoc = MyPDDocOpen(argv[1]);
fprintf(stdout, "Navigation Tab: ");
PDPageMode pgMode = PDDocGetPageMode(pdDoc);
switch (pgMode)
case PDDontCare: /* fprintf(stdout, "Default\n"); break;*/
case PDUseNone: fprintf(stdout, "Page Only\n"); break;
case PDUseBookmarks: fprintf(stdout, "Bookmarks Panel and Page\n"); break;
case PDUseAttachments: fprintf(stdout, "Attachments Panel and Page\n"); break;
case PDUseOC:fprintf(stdout, "Layers Panel and Page\n"); break;
case PDUseThumbs: fprintf(stdout, "Pages Panel and Page\n"); break;
default: fprintf(stdout, "***unhandled %d\n", pgMode);
fprintf(stdout, "Page Layout: ");
PDLayoutMode layoutMode = PDDocGetLayoutMode(pdDoc);
switch (layoutMode)
case PDLayoutDontCare: fprintf(stdout, "Default\n"); break;
case PDLayoutSinglePage: fprintf(stdout, "Single Page\n"); break;
case PDLayoutOneColumn: fprintf(stdout, "Single Page Continuous\n"); break;
case PDLayoutTwoColumnLeft:fprintf(stdout, "Two-Up Continuous (Facing)\n"); break;
case PDLayoutTwoColumnRight:fprintf(stdout, "Two-Up Continuous (Cover Page)\n"); break;
case PDLayoutTwoPageLeft:fprintf(stdout, "Two-Up (Facing)\n"); break;
case PDLayoutTwoPageRight: fprintf(stdout, "Two-Up (Cover Page)\n"); break;
default: fprintf(stdout, "***unhandled %d\n", layoutMode);
fprintf(stdout, "Magnification: ");
ASInt32 pageNum=0;
ASAtom goTo = ASAtomFromString("GoTo");
ASAtom fit = ASAtomFromString("Fit");
ASAtom fitH = ASAtomFromString("FitH");
ASAtom fitV = ASAtomFromString("FitV");
ASAtom fitBH = ASAtomFromString("FitBH");
ASAtom fitXYZ = ASAtomFromString("XYZ");
PDAction act = PDDocGetOpenAction(pdDoc);
if (PDActionIsValid(act))
ASAtom subType = PDActionGetSubtype(act);
if (subType == goTo)
PDViewDestination dest = PDActionGetDest(act);
if (PDViewDestIsValid(dest))
ASAtom fitType;
ASFixedRect destRect;
ASFixed zoom;
PDViewDestGetAttr(dest, &pageNum, &fitType, &destRect, &zoom);
if (fitType == fit)
fprintf(stdout, "Fit Page\n");
else if (fitType == fitH)
fprintf(stdout, "Fit Width\n");
else if (fitType == fitV)
fprintf(stdout, "Fit Height\n");
else if (fitType == fitBH)
fprintf(stdout, "Fit Visible\n");
else if (fitType == fitXYZ && zoom != fixedNegativeInfinity && zoom != fixedZero)
fprintf(stdout, "%2d%%", (int)(ASFixedToFloat(zoom) * 100.0));
else if (fitType == fitXYZ)
fprintf(stdout, "Default\n");
fprintf(stdout, "Default\n");
ASText openPageLbl = ASTextNew();
ASText endPageLbl = ASTextNew();
ASText numPageCount = ASTextNew();
int numPages = PDDocGetNumPages(pdDoc);
PDDocGetLabelForPageNumEx(pdDoc, pageNum, openPageLbl);
char * openPageStr = (char *)ASTextGetUnicodeCopy(openPageLbl, kUTF8);
PDDocGetLabelForPageNumEx(pdDoc, numPages - 1, endPageLbl);
char * endPageStr = (char *)ASTextGetUnicodeCopy(endPageLbl, kUTF8);
#define LEN 32
char pagesStr[LEN];
sprintf(pagesStr,"%d", numPages);
if (strcmp(pagesStr, endPageStr) != 0)
sprintf(pagesStr, " (%d)", numPages);
numPageCount = ASTextFromPDText(pagesStr);
ASTextCat(endPageLbl, numPageCount);
endPageStr = (char *)ASTextGetUnicodeCopy(endPageLbl, kUTF8);
fprintf(stdout, "Open To Page: %s of %s\n", openPageStr, endPageStr);
ASBool bFitWindow = false;
ASBool bCenterWindow = false;
ASBool bDisplayDocTitle = false;
ASBool bHideMenubar = false;
ASBool bHideToolbar = false;
ASBool bHideWindowUI = false;
CosDoc cosPDFDoc = PDDocGetCosDoc(pdDoc);
CosObj DocRoot = CosDocGetRoot(cosPDFDoc);
CosObj cosViewPrefs = CosDictGet(DocRoot, ASAtomFromString("ViewerPreferences"));
if (CosObjGetType(cosViewPrefs) == CosDict)
CosObj cosPref = CosDictGet(cosViewPrefs, ASAtomFromString("FitWindow"));
if (CosObjGetType(cosPref) == CosBoolean)
bFitWindow = CosBooleanValue(cosPref);
cosPref = CosDictGet(cosViewPrefs, ASAtomFromString("CenterWindow"));
if (CosObjGetType(cosPref) == CosBoolean)
bCenterWindow = CosBooleanValue(cosPref);
cosPref = CosDictGet(cosViewPrefs, ASAtomFromString("DisplayDocTitle"));
if (CosObjGetType(cosPref) == CosBoolean)
bDisplayDocTitle = CosBooleanValue(cosPref);
cosPref = CosDictGet(cosViewPrefs, ASAtomFromString("HideMenubar"));
if (CosObjGetType(cosPref) == CosBoolean)
bHideMenubar = CosBooleanValue(cosPref);
cosPref = CosDictGet(cosViewPrefs, ASAtomFromString("HideToolbar"));
if (CosObjGetType(cosPref) == CosBoolean)
bHideToolbar = CosBooleanValue(cosPref);
cosPref = CosDictGet(cosViewPrefs, ASAtomFromString("HideWindowUI"));
if (CosObjGetType(cosPref) == CosBoolean)
bHideWindowUI = CosBooleanValue(cosPref);
fprintf(stdout, "Resize window to initial page: %s\n", bFitWindow?"Yes":"No");
fprintf(stdout, "Center window on screen: %s\n", bCenterWindow ? "Yes" : "No");
fprintf(stdout, "Open in Full Screen Mode: %s\n", PDDocGetFullScreen(pdDoc) ? "Yes" : "No");
fprintf(stdout, "Show: %s\n", bDisplayDocTitle ? "Document Title" : "File Name");
fprintf(stdout, "Hide Menubar: %s\n", (bHideMenubar && !(bHideToolbar &&bHideWindowUI)) ? "Yes" : "No");
fprintf(stdout, "Hide Toolbars: %s\n", bHideToolbar ? "Yes" : "No");
fprintf(stdout, "Hide Window controls: %s\n", bHideWindowUI ? "Yes" : "No");
char buf[512];
ASGetErrorString(ERRORCODE, buf, sizeof(buf));
fprintf(stderr, "Error code: 0x%lx, Error Message: %s\n", ERRORCODE, buf);
#include "MyPDFLibApp.cpp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment