PDF Document Creation, Viewing, and Transforming

  Quartz provides the data type CGPDFDocumentRef to represent a PDF document. You create a CGPDFDocument object using either the function CGPDFDocumentCreateWithProvider or the function CGPDFDocumentCreateWithURL. After you create a CGPDFDocument object, you can draw it to a graphics context.

  Following code shows how to create a CGPDFDocument object and obtain the number of pages in the document. by

CGPDFDocumentGetNumberOfPages function. A detailed explanation for each numbered line of code appears following the listing.

 1 CGPDFDocumentRef MyGetPDFDocumentRef (const char *filename)
 2 {
 3     CFStringRef path;
 4     CFURLRef url;
 5     CGPDFDocumentRef document;
 6     size_t count;
 7  
 8     path = CFStringCreateWithCString (NULL, filename,
 9                          kCFStringEncodingUTF8);
10     url = CFURLCreateWithFileSystemPath (NULL, path, // 1
11                         kCFURLPOSIXPathStyle, 0);
12     CFRelease (path);
13     document = CGPDFDocumentCreateWithURL (url);// 2
14     CFRelease(url);
15     count = CGPDFDocumentGetNumberOfPages (document);// 3
16     if (count == 0) {
17         printf("`%s' needs at least one page!", filename);
18         return NULL;
19     }
20     return document;
21 }
View Code

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-12-05
  • 2021-09-20
  • 2022-12-23
  • 2022-01-31
猜你喜欢
  • 2021-05-24
  • 2021-07-12
  • 2021-11-22
  • 2022-12-23
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案