相关疑难解决方法(0)

将PDF转换为UIImage

func drawOnPDF(path: String)
{
    // Get existing Pdf reference
    let pdf = CGPDFDocumentCreateWithURL(NSURL(fileURLWithPath: path))

    // Get page count of pdf, so we can loop through pages and draw them accordingly
    let pageCount = CGPDFDocumentGetNumberOfPages(pdf);

    // Write to file
    UIGraphicsBeginPDFContextToFile(path, CGRectZero, nil)

    // Write to data
//        var data = NSMutableData()
//        UIGraphicsBeginPDFContextToData(data, CGRectZero, nil)

    for index in 1...pageCount {
        let page = CGPDFDocumentGetPage(pdf, index)
        let pageFrame = CGPDFPageGetBoxRect(page, kCGPDFMediaBox)

        UIGraphicsBeginPDFPageWithInfo(pageFrame, nil)

        var ctx = UIGraphicsGetCurrentContext()

        // Draw existing page
        CGContextSaveGState(ctx); …
Run Code Online (Sandbox Code Playgroud)

pdf-generation ios uigraphicscontext swift

9
推荐指数
2
解决办法
7741
查看次数

从PDF中提取图像

我有一些关于从iPhone应用程序中提供的PDF文档中专门提取图像(仅图像)的疑问.

我已经浏览了苹果的文档 - 但我没有找到它.

我已经完成了从PDF文档获取图像的努力.

-(IBAction)btnTappedImages:(id)sender{

    // MyGetPDFDocumentRef is custom c method 
    // & filePath is path to pdf document.
    CGPDFDocumentRef document = MyGetPDFDocumentRef ([filePath UTF8String]);

    int pgcnt = CGPDFDocumentGetNumberOfPages( document );

    for( int i1 = 0; i1 < pgcnt; ++i1 ) {
        // 1. Open Document page 
        CGPDFPageRef pg = CGPDFDocumentGetPage (document, i1+1);
        if( !pg ) {
            NSLog(@"Couldn't open page.");
        }
        // 2. get page dictionary
        CGPDFDictionaryRef dict = CGPDFPageGetDictionary( pg );
        if( !dict ) {
            NSLog(@"Couldn't open page …
Run Code Online (Sandbox Code Playgroud)

pdf iphone xcode objective-c cfdata

3
推荐指数
1
解决办法
1万
查看次数