iPDFdev Tips & Tricks for PDF development

IFXPDFFactory – part 11 – Document information and viewer preferences

February 24th, 2015

The document information stores metadata about the document. The viewer preferences specify how the PDF file should be displayed in the viewer.

The document information is set using the IFXPDFDocumentInformation class. The following properties are available:

NSString* title - the document's title
NSString* author - the name of the person that created the document
NSString* subject - the subject of the document
NSString* keywords - keywords associated with the document
NSString* creator - if the document was converted to PDF from another format, the name of the application that created the original document from which it was converted.
NSString* producer - the name of the application that created the PDF file
NSDate* creationDate - the date and time when the document was created
NSDate* modifyDate - the date and time when the document was most recently modified

The viewer preferences are set using the IFXPDFViewerPreferences class. These properties are available:

BOOL hideToolbar - flag specifying whether to hide the viewer application’s tool bars when the document is active
BOOL hideMenubar - flag specifying whether to hide the viewer application’s menu bar when the document is active
BOOL hideWindowUI - flag specifying whether to hide user interface elements in the document’s window, leaving only the document's contents displayed
BOOL fitWindow - flag specifying whether to resize the document's window to fit the size of the first displayed page.
BOOL centerWindow - flag specifying whether to position the document's window in the center of the screen
BOOL displayDocumentTitle - flag specifying whether the window's title bar should display the document title taken from the Title property of the document information
IFXPDFDisplayMode nonFullScreenPageMode - the document's page mode, specifying how to display the document on exiting full-screen mode. Possible values:
- IFXPDFDisplayModeUseNone - neither document outline nor thumbnail images visible
- IFXPDFDisplayModeUseOutlines - document outline visible
- IFXPDFDisplayModeUseThumbs - thumbnail images visible
IFXPDFPrintScalingMode printScaling - the page scaling option to be selected when a print dialog is displayed for this document. Possible values:
- IFXPDFPrintScalingModeNone - the print dialog should reflect no page scaling
- IFXPDFPrintScalingModeAppDefault - the application should use the current print scaling
IFXPDFDuplexPrintingMode duplexPrinting - the paper handling option to use when printing the file from the print dialog. Possible values:
- IFXPDFDuplexPrintingModeNone - no duplex printing
- IFXPDFDuplexPrintingModeSimplex - print single-sided
- IFXPDFDuplexPrintingModeDuplexFlipShortEdge - duplex and flip on the short edge of the sheet
- IFXPDFDuplexPrintingModeDuplexFlipLongEdge - duplex and flip on the long edge of the sheet
BOOL pickTrayByPdfSize - flag specifying whether the PDF page size is used to select the input paper tray
IFXPDFNumberArray* printPageRange - the page numbers used to initialize the print dialog box when the file is printed. The first page of the PDF file is denoted by 1. Each pair consists of the first and last pages in the sub-range
int numberOfCopies - the number of copies to be printed when the print dialog is opened for this file

The properties in the viewer preferences are more like guidelines for the viewer. A viewer application can choose what properties to support and what not.

IFXPDFDocument* doc = [[IFXPDFDocument alloc] init];
IFXPDFDocumentInformation* docInfo = [[IFXPDFDocumentInformation alloc] init];
docInfo.author = @"Sorin Nistor";
docInfo.creator = @"iPDFdev.com";
docInfo.producer = @"IFXPDFFactory for iOS";
docInfo.subject = @"Test for Document Information and Viewer Preferences";
docInfo.keywords = @"pdf, document information, viewer preferences";
docInfo.title = @"IFXPDFFactory - Document Information and Viewer Preferences";
doc.documentInformation = docInfo;
IFXPDFViewerPreferences* viewerPreferences = [[IFXPDFViewerPreferences alloc] init];
viewerPreferences.hideMenubar = TRUE;
viewerPreferences.hideToolbar = TRUE;
viewerPreferences.hideWindowUI = TRUE;
viewerPreferences.displayDocumentTitle = TRUE;
viewerPreferences.fitWindow = TRUE;
viewerPreferences.centerWindow = TRUE;
viewerPreferences.nonFullScreenPageMode = IFXPDFDisplayModeUseOutlines;
viewerPreferences.printScaling = IFXPDFPrintScalingModeAppDefault;
viewerPreferences.duplexPrinting = IFXPDFDuplexPrintingModeSimplex;
double printPageRange[2] = { 1, 10 };
viewerPreferences.printPageRange = [IFXPDFNumberArray arrayWithNumbers:printPageRange length:2];
viewerPreferences.numberOfCopies = 3;
doc.viewerPreferences = viewerPreferences;
IFXPDFBrush* blackBrush = [IFXPDFBrush brushWithColor:[IFXPDFRgbColor blackColor]];
IFXPDFFont* titleFont = [[IFXPDFFont alloc] init];
titleFont.fontFace = IFXPDFHelveticaBoldFontFace;
titleFont.size = 16;
IFXPDFPage* page = [IFXPDFPage emptyPage];
[pdfDocument.pages addPage:page];
[page.graphics drawText:@"PDF file with document information and viewer preferences"
               withFont:titleFont brush:blackBrush atX:20 y:50]; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFile = [documentsDirectory stringByAppendingPathComponent:@"DocumentInformationAndViewerPreferences.pdf"];
[doc writeToFile:pdfFile];
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.