Headers and footers
Foxit PDF SDK for iOS adds headers and footers via Core SDK at six positions (top-left, top-center, top-right, bottom-left, bottom-center, bottom-right) with optional page numbers and dates.
Core classes
| Class | Description |
|---|---|
FSHeaderFooter | Configuration: font, size, color, margins, page range, content |
FSHeaderFooterContent | Text at six positions |
FSHeaderFooterContentGenerator | Build strings from text, date, and page number |
FSHeaderFooter properties
| Property | Description |
|---|---|
font | Font |
text_size | Font size |
text_color | Text color (0xRRGGBB) |
page_range | Page range (FSPageNumberRange) |
page_margin | Margins |
start_page_number | Starting page number |
content | Six-position content (FSHeaderFooterContent) |
has_text_shrinked | Shrink text to fit |
has_fixedsize_for_print | Fixed size when printing |
is_to_embed_font | Embed font |
is_underline | Underline |
Example: add headers and footers
objc
#import <FoxitRDK/FSPDFObjC.h>
FSPDFDoc *doc = [[FSPDFDoc alloc] initWithPath:@"path/to/Sample.pdf"];
[doc load:nil];
// Page number string
FSHeaderFooterContentGenerator *generator = [[FSHeaderFooterContentGenerator alloc] init];
[generator addString:@"第 "];
[generator addPageNumber:FSHeaderFooterContentGeneratorPageNumberFormatFirst];
[generator addString:@" 页"];
NSString *pageNumberStr = [generator generateContent];
// Date string
FSHeaderFooterContentGenerator *dateGen = [[FSHeaderFooterContentGenerator alloc] init];
[dateGen addDate:FSHeaderFooterContentGeneratorDateFormatTypeFirst];
NSString *dateStr = [dateGen generateContent];
// Six positions
FSHeaderFooterContent *content = [[FSHeaderFooterContent alloc] init];
content.header_left_content = @"福昕文档";
content.header_center_content = @"";
content.header_right_content = dateStr;
content.footer_left_content = @"";
content.footer_center_content = pageNumberStr;
content.footer_right_content = @"机密";
// Page range
FSPageNumberRange *pageRange = [[FSPageNumberRange alloc]
initWithStart_number:0
end_number:[doc getPageCount] - 1
filter:FSRangeFilterAll];
// Margins (left, bottom, right, top)
FSRectF *margin = [[FSRectF alloc] initWithLeft1:72 bottom1:36 right1:72 top1:36];
FSHeaderFooter *headerFooter = [[FSHeaderFooter alloc] init];
headerFooter.font = [[FSFont alloc] initWithStandard_id:FSFontStdIDHelvetica];
headerFooter.text_size = 10.0f;
headerFooter.text_color = 0x000000;
headerFooter.page_range = pageRange;
headerFooter.page_margin = margin;
headerFooter.start_page_number = 1;
headerFooter.content = content;
headerFooter.is_to_embed_font = NO;
headerFooter.is_underline = NO;
[doc addHeaderFooter:headerFooter];
[doc saveAs:@"path/to/output.pdf" saveFlags:FSPDFDocSaveFlagNormal];Other operations
objc
// Check for headers/footers
BOOL hasHF = [doc hasHeaderFooter];
// Editable instance
FSHeaderFooter *existingHF = [doc getEditableHeaderFooter];
// Update
[doc updateHeaderFooter:existingHF];
// Remove all
[doc removeAllHeaderFooters];API reference
See the API reference for FSHeaderFooter, FSHeaderFooterContent, and FSHeaderFooterContentGenerator.