gpt4 book ai didi

iphone - 在 iphone 应用程序中从 UIScrollView 创建 PDF

转载 作者:可可西里 更新时间:2023-11-01 05:45:15 25 4
gpt4 key购买 nike

我正在从 UIView 创建 pdf 到 pdf 它工作正常但是我有 scrollView 包含我想转换为 pdf 的内容但它只显示 pdf 中的可见部分而不是整个 scrollView 内容。这是我的代码

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
NSMutableData *pdfData = [NSMutableData data];

// Get Scrollview size
CGRect scrollSize = CGRectMake(1018,76,scrollView.contentSize.width,scrollView.contentSize.height);

// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, scrollSize, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();


// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData

[aView.layer renderInContext:pdfContext];





// remove PDF rendering context
UIGraphicsEndPDFContext();

// Retrieves the document directories from the iOS device
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);

NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];

// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];
NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
}

最佳答案

这为您提供了 UIScrollView 的可见部分

CGRect visibleRect;
visibleRect.origin = scrollView.contentOffset;
visibleRect.size = scrollView.bounds.size;

float theScale = 1.0 / scale;
visibleRect.origin.x *= theScale;
visibleRect.origin.y *= theScale;
visibleRect.size.width *= theScale;
visibleRect.size.height *= theScale;

因此您可以在UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
中使用它通过参数的一些微小变化。

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

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