相关疑难解决方法(0)

如何在iOS中将UIView转换为PDF?

关于如何在App中显示PDF有很多资源UIView.我现在正在做的是从中创建一个PDF UIViews.

例如,我有一个UIView,与像Textviews子视图,UILabels,UIImages,所以我怎么能转换成一个大的 UIView整体,包括其所有子视图和subsubviews到PDF?

我查看过Apple的iOS参考资料.但是,它只涉及将文本/图像片段写入PDF文件.

我面临的问题是我想以PDF格式写入文件的内容很多.如果我将它们逐个写入PDF,那将是一项巨大的工作.这就是我寻找写入UIViewsPDF甚至位图的方法的原因.

我已经尝试过在Stack Overflow中从其他Q/A复制的源代码.但它只给我一个带有UIView边界大小的空白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 …
Run Code Online (Sandbox Code Playgroud)

pdf core-graphics uiview uiimage ios

85
推荐指数
5
解决办法
5万
查看次数

标签 统计

core-graphics ×1

ios ×1

pdf ×1

uiimage ×1

uiview ×1