gpt4 book ai didi

iphone - 将 UIImage 转换为 PDF 文件

转载 作者:行者123 更新时间:2023-12-03 18:34:45 25 4
gpt4 key购买 nike

我正在尝试将 UIImage 保存为 PDF 文件。我怎样才能做到这一点?我如何将图像保存到 pdf 文件中,然后导出该 pdf 文件?请针对我遇到的问题提出解决方案。

谢谢。

最佳答案

你好,我发现这可行,希望能帮助到你!

-(void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];

// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();

// draws rect to the view and thus this is captured by UIGraphicsBeginPDFContextToData
[aView.layer renderInContext:UIGraphicsGetCurrentContext()];

// 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);
}

关于iphone - 将 UIImage 转换为 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2445335/

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