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.

 CGPDFDocumentRef MyGetPDFDocumentRef (const char *filename)
{
CFStringRef path;
CFURLRef url;
CGPDFDocumentRef document;
size_t count; path = CFStringCreateWithCString (NULL, filename,
kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path, //
kCFURLPOSIXPathStyle, );
CFRelease (path);
document = CGPDFDocumentCreateWithURL (url);//
CFRelease(url);
count = CGPDFDocumentGetNumberOfPages (document);//
if (count == ) {
printf("`%s' needs at least one page!", filename);
return NULL;
}
return document;
}

  Drawing a PDF page:

 void MyDisplayPDFPage (CGContextRef myContext,
size_t pageNumber,
const char *filename)
{
CGPDFDocumentRef document;
CGPDFPageRef page; document = MyGetPDFDocumentRef (filename);//
page = CGPDFDocumentGetPage (document, pageNumber);//
CGContextDrawPDFPage (myContext, page);//
CGPDFDocumentRelease (document);//
}

  

最新文章

  1. Linux网路编程系列-网络I/O模型
  2. 移动端基于HTML模板和JSON数据的JavaScript交互
  3. 关于sql 的convert 格式设置
  4. D - Charm Bracelet 背包问题
  5. O-C相关-06:对象与对象的关系
  6. Understanding JavaScript Function Invocation and "this"
  7. sizeof与strlen的区别 浅谈
  8. CentOS系统中出现错误--SSH:connect to host centos-py port 22: Connection refused
  9. --------------Hibernate学习(四) 多对一映射 和 一对多映射
  10. 更好的小票打印体验,huanent.printer2.0发布
  11. Python reverse()方法--list
  12. Win10系统如何安装Linux Mint
  13. poj2279——Mr. Young's Picture Permutations
  14. Autowired byType 与 byName 策略
  15. 20170706wdVBA正则表达式提取题目
  16. 题目1003:A+B
  17. M端计算rem方法
  18. 搞清tomcat中的编解码
  19. Ssm框架常见报错
  20. 10-10Linux的文件操作函数以及所需头文件

热门文章

  1. 阿里云 搭建Git服务器
  2. CentOS6.5 下Haproxy服务的安装与配置
  3. GNU Radio: Multiple USRP configurations 配置多个USRP设备
  4. C#使用OpcNetApi.dll和OpcNetApi.Com.dll操作OPC
  5. 1021 docker搭建mysql、网络模式、grid
  6. JavaScript(二)-精简
  7. pythonNet day03
  8. js 取元素相对页面的高度和宽度
  9. 2.spring整合ehcache 注解实现查询缓存,并实现实时缓存更新或删除
  10. 【python 】装饰器 (多个参数的函数,带参数的装饰器)【转】