gpt4 book ai didi

iphone - 在 iPad 应用程序中从 UIView 创建 pdf 的问题

转载 作者:行者123 更新时间:2023-12-01 17:01:46 25 4
gpt4 key购买 nike

我正在我的 iPad 应用程序中从 UIView 创建一个 pdf。它的大小为 768 * 2000。当我创建 pdf 时,它会以相同的大小创建,并在一页上显示所有内容。所以当我从 iPad 打印时我遇到了问题。我正在使用以下代码创建pdf:-

-(void)drawPdf:(UIView *)previewView{   
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"Waypoint Data.pdf"];
//CGRect tempRect = CGRectMake(0, 0, 768, 1068);
CGContextRef pdfContext = [self createPDFContext:previewView.bounds path:(CFStringRef)writableDBPath];
CGContextBeginPage (pdfContext,nil); // 6

//turn PDF upsidedown

CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(0, previewView.bounds.size.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
CGContextConcatCTM(pdfContext, transform);

//Draw view into PDF
[previewView.layer renderInContext:pdfContext];
CGContextEndPage (pdfContext);// 8
CGContextRelease (pdfContext);
}

//Create empty PDF context on iPhone for later randering in it

-(CGContextRef) createPDFContext:(CGRect)inMediaBox path:(CFStringRef) path{

CGContextRef myOutContext = NULL;

CFURLRef url;

url = CFURLCreateWithFileSystemPath (NULL, // 1

path,

kCFURLPOSIXPathStyle,

false);

if (url != NULL) {

myOutContext = CGPDFContextCreateWithURL (url,// 2

&inMediaBox, NULL);
CFRelease(url);// 3
}
return myOutContext;// 4
}

谁能建议我如何减小 pdf 大小并且它有多个页面?

提前致谢。

最佳答案

请参阅“iOS 绘图和打印指南”中的示例

https://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/GeneratingPDF/GeneratingPDF.html#//apple_ref/doc/uid/TP40010156-CH10-SW1

基本上在 list 4-1 代码示例中,他们有一个 do while 循环,并注意它是如何在循环中启动一个新的 PDF 页面的:

...

// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);

...

在您当前的方法中,您只调用了一次开始页面方法之一,这就是为什么您只会有一个页面的原因。

关于iphone - 在 iPad 应用程序中从 UIView 创建 pdf 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6068034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com