Implementation of PDF cases in iPhone development applications

Source: Internet
Author: User

IPhone DevelopmentApplication in progressPDFCase implementation is the content to be introduced in this article, mainly to learn about iPhone DevelopmentPDFThe content of the article is not much, mainly based on code. Let's take a look at the details.

 
 
  1. # Import <UIKit/UIKit. h>
  2. @ Class initialize testviewcontroller;
  3. @ Interface preview view: UIView {
  4. // This class encapsulates all the information drawn in PDF.
  5. Cgw.documentref pdf;
  6. // Retrieve a page from document
  7. CGPDFPageRef page;
  8. // Total number of pages
  9. Int totalPages;
  10. // Current page
  11. Int currentPage;
  12. Using testviewcontroller * using test;
  13. }
  14. @ Property (nonatomic, retain) IBOutlet implements testviewcontroller * implements test;
  15. // The initialization class of the current view. In this method, a cgw.docuemntref object is created, and the name and size of the required page of a PDF file are passed,
  16. -(Id) initWithFrame :( CGRect) frame andFileName :( NSString *) fileName;
  17. // Create a PDF object. This method is called in the initialization method.
  18. -(Cg1_documentref) createPDFFromExistFile :( NSString *) aFilePath;
  19.  
  20. -(Void) reloadView;
  21. /*
  22. Jump between pages
  23. */
  24. -(Void) goUpPage;
  25. -(Void) goDownPage;
  26. @ End
  27. //
  28. // Lateral view. m
  29. // Define viewtest
  30. //
  31. // Created by Evan Lynn on 10-6-20.
  32. // Copyright 2010 restore Age. All rights reserved.
  33. //
  34.  
  35. # Import "lateral view. h"
  36.  
  37. // # Import "Export testviewcontroller. h"
  38. @ Implementation lateral view
  39. @ Synthesize upload test;
  40. -(Id) initWithFrame :( CGRect) frame andFileName :( NSString *) fileName {
  41. If (self = [super initWithFrame: frame]) {
  42. NSString * dataPathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: fileName];
  43. Pdf = [self createPDFFromExistFile: dataPathFromApp];
  44. Self. backgroundColor = [UIColor clearColor];
  45. }
  46. Return self;
  47. }
  48. -(Cg1_documentref) createPDFFromExistFile :( NSString *) aFilePath {
  49. CFStringRef path;
  50. CFURLRef url;
  51. Cgw.documentref document;
  52. Path = CFStringCreateWithCString (NULL, [aFilePath UTF8String], kCFStringEncodingUTF8 );
  53. Url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, NO );
  54. CFRelease (path );
  55. Document = cgw.documentcreatewithurl (url );
  56. CFRelease (url );
  57. TotalPages = cgw.documentgetnumberofpages (document );
  58. CurrentPage = 1;
  59. If (totalPages = 0 ){
  60. Return NULL;
  61. }
  62. Return document;
  63. }
  64. -(Void) drawRect :( CGRect) rect {
  65. // Obtain the drawing Context
  66. CGContextRef context = UIGraphicsGetCurrentContext ();
  67. // Get a PDF page
  68. Page = cgw.documentgetpage (pdf, currentPage );
  69. /* Perform Coordinate Transformation to move 100 units to the right, and move down the current view height,
  70. This is because the coordinate system for Quartz drawing starts from the lower left corner, but the iphone view starts from the upper left corner.
  71. */
  72. CGContextTranslateCTM (context, 100.0, self. bounds. size. height );
  73. // Transform the Coordinate System
  74. CGContextScaleCTM (context, 1.0,-1 );
  75. CGContextDrawPDFPage (context, page );
  76. }
  77. -(Void) dealloc {
  78. [Super dealloc];
  79. }
  80. -(Void) reloadView {
  81. [Self setNeedsDisplay];
  82. }
  83. -(Void) goUpPage {
  84. If (currentPage <2)
  85. Return;
  86. -- CurrentPage;
  87. [Self reloadView];
  88. }
  89. -(Void) goDownPage {
  90. If (currentPage> = totalPages)
  91. Return;
  92. ++ CurrentPage;
  93. [Self reloadView];
  94. }
  95. @ End

Summary:IPhone DevelopmentApplication in progressPDFThe implementation of the case is complete. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.