关于objective—c如何让JPG文件转化成PDF形式
2015-06-29 13:22
405 查看
这个是一页纸有时候会有两个图。也可以一张图,一张图相对就非常简单了,就不用写了,也可以加我的
QQ :1342438493
//
// ViewController.m
// PDF
//
// Created by lixi on 15/6/29.
// Copyright (c) 2015年 lx. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
NSString *filePath = [homePath stringByAppendingString:@"/Documents/test.pdf"];
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *homePath = NSHomeDirectory();
[self genratePDF:filePath];
}
// 生成PDF
- (void)genratePDF:(NSString *)filePath {
// path :PDF 文件路径
// bounds:PDF 尺寸, CGRectZero 是一个默认尺寸 (8.5 BY 11.0),(612 by 792 points)
// userInfo:PDF 文件属性
UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
for (int i=0; i<6; i++) {
if (i%2 == 0) {
// 开始新页面
UIGraphicsBeginPDFPage(); // 执行N次,PDF就是N页
}
NSString *imageNamed = [NSString stringWithFormat:@"%d_full.JPG",i];
UIImage *image = [UIImage imageNamed:imageNamed];
// i = 0 , y = 0;
// i = 0 , y = 0,
// 宽度不变,每一副的高度,只占页面的一般
[image drawInRect:CGRectMake(0, (i % 2) * 396.f, 612.f, 396.f)];
}
UIGraphicsEndPDFContext();
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
QQ :1342438493
//
// ViewController.m
//
// Created by lixi on 15/6/29.
// Copyright (c) 2015年 lx. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
NSString *filePath = [homePath stringByAppendingString:@"/Documents/test.pdf"];
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *homePath = NSHomeDirectory();
[self genratePDF:filePath];
}
// 生成PDF
- (void)genratePDF:(NSString *)filePath {
// path :PDF 文件路径
// bounds:PDF 尺寸, CGRectZero 是一个默认尺寸 (8.5 BY 11.0),(612 by 792 points)
// userInfo:PDF 文件属性
UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
for (int i=0; i<6; i++) {
if (i%2 == 0) {
// 开始新页面
UIGraphicsBeginPDFPage(); // 执行N次,PDF就是N页
}
NSString *imageNamed = [NSString stringWithFormat:@"%d_full.JPG",i];
UIImage *image = [UIImage imageNamed:imageNamed];
// i = 0 , y = 0;
// i = 0 , y = 0,
// 宽度不变,每一副的高度,只占页面的一般
[image drawInRect:CGRectMake(0, (i % 2) * 396.f, 612.f, 396.f)];
}
UIGraphicsEndPDFContext();
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- Qt源码分析之QObject(转自CSDN,作者oowgsoo)
- [Objective-C] 理解 Objective-C 的 ARC
- java平台下arcobjects的开发
- [Objective-C] iOS 开发中建议使用自动引用计数(ARC)
- [Objective-C] 从“引用计数”过渡到“自动引用计数”(ARC)
- 使用Xcode HeaderDoc和Doxygen文档化你的Objective-C和Swift代码
- poj 3241 Object Clustering 曼哈顿最小生成树
- [Objective-C] Objective-C中的id
- 从 C++ 到 Objective-C 的快速指南
- IOS --Object-C 四种保存数据的方式
- .NET平台开源项目速览(2)Compare .NET Objects对象比较组件
- object reference in Java
- 重踏学习Java路上_Day11(Object)
- IDNFeedParser 一个简单易用的Rss解析库(Objective-C)
- freemarker.core.InvalidReferenceException: Expression stackObject.value.get(propertyName).toString() is undefined
- CALayer-简介(一)
- java学习之旅40--面向对象_13_继承_Object类用法_toString和equals方法_重写toString
- Objective-C 快速入门--基础(三)
- Objective-C 快速入门--基础(三)
- IOS编程第四版第二章:Objective-C