Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. iOS
  4. How to Convert UIView to PDF format?

How to Convert UIView to PDF format?

Scheduled Pinned Locked Moved iOS
tutorialquestion
4 Posts 4 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 11597327
    wrote on last edited by
    #1

    How to Convert UIView to PDF format in objective c.

    L D U 3 Replies Last reply
    0
    • U User 11597327

      How to Convert UIView to PDF format in objective c.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      By writing some code which captures the data from the view and reformats it as PDF. Google will be the place to start your research.

      1 Reply Last reply
      0
      • U User 11597327

        How to Convert UIView to PDF format in objective c.

        D Offline
        D Offline
        Dennis E White
        wrote on last edited by
        #3

        Member 11631711 wrote:

        Convert UIView to PDF

        A large part of this will of course depend on the content of UIView and what exactly you are trying to achieve. To better help you might want to improve your question with an example of what you are doing and where you are stuck. If you just need to get started then maybe the following will help: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIKitFunctionReference/[^] You will want to look at the section for PDF Creation.

        1 Reply Last reply
        0
        • U User 11597327

          How to Convert UIView to PDF format in objective c.

          U Offline
          U Offline
          User 12392074
          wrote on last edited by
          #4

          Note that the following method creates just a bitmap of the view; it does not create actual typography

          (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
          {
          // Creates a mutable data object for updating with binary data, like a byte array
          NSMutableData *pdfData = [NSMutableData data];

          // Points the pdf converter to the mutable data object and to the UIView to be converted
          UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
          UIGraphicsBeginPDFPage();
          CGContextRef pdfContext = UIGraphicsGetCurrentContext();
          
          
          // draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
          
          \[aView.layer renderInContext:pdfContext\];
          
          // remove PDF rendering context
          UIGraphicsEndPDFContext();
          
          // Retrieves the document directories from the iOS device
          NSArray\* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
          
          NSString\* documentDirectory = \[documentDirectories objectAtIndex:0\];
          NSString\* documentDirectoryFilename = \[documentDirectory stringByAppendingPathComponent:aFilename\];
          
          // instructs the mutable data object to write its context to a file on disk
          \[pdfData writeToFile:documentDirectoryFilename atomically:YES\];
          NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
          

          }

          Also make sure you import: QuartzCore/QuartzCore.h

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups