Is it possible to combine multiple pdf files into a single pdf file programmatically in iphone?

前端 未结 3 1697
借酒劲吻你
借酒劲吻你 2020-12-08 23:52

Is it possible to combine multiple pdf files into a single pdf file programmatically in iphone.I have created individual pages from different parts of my program and now nee

3条回答
  •  隐瞒了意图╮
    2020-12-09 00:44

    Yes you can do that. Please follow the below code

    //Open a pdf context for the single file
    UIGraphicsBeginPDFContextToFile(oldFile, paperSize, nil);
    
    //Run a loop to the number of pages you want
    for (pageNumber = 1; pageNumber <= count; pageNumber++)
    {
    //Open a pdf page context
    UIGraphicsBeginPDFPageWithInfo(paperSize, nil);
    
    //Get graphics context to draw the page
    CGContextRef currentContext = UIGraphicsGetCurrentContext();
    
    //Flip and scale context to draw the pdf correctly
    CGContextTranslateCTM(currentContext, 0, paperSize.size.height);
    CGContextScaleCTM(currentContext, 1.0, -1.0); 
    
    //Get document access of the pdf from which you want a page
    CGPDFDocumentRef newDocument = CGPDFDocumentCreateWithURL ((CFURLRef) newUrl);
    
    //Get the page you want
    CGPDFPageRef newPage = CGPDFDocumentGetPage (newDocument, pageNumber);
    
    //Drawing the page
    CGContextDrawPDFPage (currentContext, newPage);
    
    //Clean up
    newPage = nil;       
    CGPDFDocumentRelease(newDocument);
    newDocument = nil;
    newUrl = nil;
    
    }
    
    UIGraphicsEndPDFContext();
    

    So you have to write necessary condition of taking appropriate pages from appropriate pdf before draw the page. You have created a pdf from multiple sources!

提交回复
热议问题