Giter Club home page Giter Club logo

magpdfgenerator's Introduction

MAGPdfGenerator

MAGPdfGenerator is an utility which provides the ability to convert UIView's representation to a PDF document. The UIView may be created from XIB file and use Autolayouts that makes a convenient way to draw the PDF's content. The PDF document will automatically be divided by pages so you can create a long table view and draw it in the PDF document without additional preparation. The generator can also automatically print page numbers in the bottom of each of the pages.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

MAGPdfGenerator works on iOS 8+.

Installation

MAGPdfGenerator is available through CocoaPods. To install it, simply add the following line to your Podfile and run pod install:

pod 'MAGPdfGenerator'

Usage

Before you can use the generator you should create an instance of UIView containing the layout for the future PDF document. The default pdf page size is {612, 792}, and the printable area has a size {580, 730}, so you should locate internal views in the size equal to the size of the printable area to avoid elements out of the page. You can use XIB file for that purposes and then instantiate the view with something like this:

YourPdfViewClass *yourPdfViewInstance = [[NSBundle mainBundle] loadNibNamed:
    NSStringFromClass([YourPdfViewClass class]) owner:nil options:nil].firstObject;

After it is instantiated you can create and use an instance of MAGPdfRenderer

MAGPdfRenderer *renderer = [[MAGPdfRenderer alloc] init];
NSURL *pdfURL = [renderer drawView:yourPdfViewInstance inPDFwithFileName:pdfName];

pdfURL will contain the URL of the pdf file that was rendered by the utility.

To be sure that some of your blocks in the pdf will not be wrapped to the next page you can specify them with the method noWrapViewsForPdfRenderer: of MAGPdfRendererDelegate

- (IBAction)generatePDFbuttonTapped:(id)sender {
    MAGPdfRenderer *renderer = [[MAGPdfRenderer alloc] init];
    renderer.delegate = self;
    NSURL *pdfURL = [renderer drawView:self.yourPdfViewInstance inPDFwithFileName:pdfName];
}

- (NSArray<UIView *> *)noWrapViewsForPdfRenderer:(MAGPdfRenderer *)pdfRenderer {
    return self.yourPdfViewInstance.noWrapViews;
}

Author

Konstantin Mamaev, [email protected]

License

MAGPdfGenerator is available under the MIT license. See the LICENSE file for more info.

magpdfgenerator's People

Contributors

fedulvtubudul avatar geoffmartinskyward avatar kostassite avatar

Watchers

James Cloos avatar Nicholas Elliott avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.