Skip to content

Yet another PDF Kit for parsing and modifying PDF's. For OS X and iOS.

License

Notifications You must be signed in to change notification settings

pdfletterhead/YAPDFKit

Repository files navigation

YAPDFKit

Build Status

Yet another PDF Kit is a independent PDF Kit written in objective-c for parsing and manipulating PDF's. YAPDFKit is completely independent of Apple's PDFKit

For specific cases YAPDFKit can be of great help, but it's currently in an Alpha state.

Requirements

Platform targets

  • Usable in OS X and iOS projects
  • Oldest Mac target: Mac OS X 10.7

Functionality targets

  • Parser to create PDF Structure
  • Extract Deflated and other filtered content
  • Some essential Postscript knowledge and features
  • Modify PDF Objects directly in PDF

Example

Use these includes:

#import <Foundation/Foundation.h>
#import "YPDocument.h"

In this example we add a purple rectangle below the text of every page. See main.c for a working version of this example.

image image

NSString *file =@"/tmp/2-page-pages-export.pdf";

NSData *fileData = [NSData dataWithContentsOfFile:file];

YPDocument *document = [[YPDocument alloc] initWithData:fileData];

YPPages *pg = [[YPPages alloc] initWithDocument:document];
NSLog(@"page count: %d", [pg getPageCount]);

//All Pages unsorted
NSArray * allPages = [document getAllObjectsWithKey:@"Type" value:@"Page"];

for (YPObject* page in allPages) {

    NSString *docContentNumber = [[document getInfoForKey:@"Contents" inObject:[page getObjectNumber]] getReferenceNumber];
    YPObject * pageContentsObject = [document getObjectByNumber:docContentNumber];

    NSData *plainContent = [pageContentsObject getUncompressedStreamContentsAsData];

    NSData *data2 = [@"q /Cs1 cs 0.4 0 0.6 sc 250 600 100 100 re f q " dataUsingEncoding:NSASCIIStringEncoding];

    NSRange firstPartRange = {0,64};
    NSRange lastPartRange = {64, ([plainContent length]-64)};
    NSData *data1 = [plainContent subdataWithRange:firstPartRange];
    NSData *data3 = [plainContent subdataWithRange:lastPartRange];

    NSMutableData * newPlainContent = [data1 mutableCopy];
    [newPlainContent appendData:data2];
    [newPlainContent appendData:data3];

    [pageContentsObject setStreamContentsWithData:newPlainContent];
    [document addObjectToUpdateQueue:pageContentsObject];
}

[document updateDocumentData];
[[document modifiedPDFData] writeToFile:@"/tmp/2-page-pages-export-mod.pdf" atomically:YES];

Roadmap

Milestone 1: update page contents object

  • Return all document objects
  • Deflate content object stream
  • cleanup deflate function
  • Enable Existing Tests
  • Enable travis
  • Add some file intergration tests
  • Return all document pages
  • Return page content object
  • Add new object at file bottom
  • Add new xref table at file bottom
  • Add new trailer
  • calculate file length
  • calc object length
  • fix and check all offsets;

Milestone 2: first CocoaPod Release

  • Make podspec
  • Replace PDF prefix with YAPDF everywhere

Milestone 3: first CocoaPod Release

  • remove nsstring convertion for streams
  • add included pdf in main.c
  • cleanup file reader

Backlog

  • more examples
  • Return all page objects / per page
  • add inflate function
  • Exact Text (ProcessOutput)
  • Code Coverage
  • Rename all object attributes classes with a name including object

Motivation

This project started because we needed to remove white backgrounds from PDF's made by Applications like Apple Pages. YAPDFKit is used in the PDF Letterhead App.

image

image

Contributing

  1. Fork it ( https://github.com/[my-github-username]/YAPDFKit/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Credits

image

About

Yet another PDF Kit for parsing and modifying PDF's. For OS X and iOS.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published