#pragma mark-merge PDF
-(void) mergepdf
{
nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, Nsuserdomainmask, YES);
nsstring *filepath1 = [[Paths objectatindex:0] stringbyappendingpathcomponent:@ " read the card . pdf"];
nsstring *filepath2 = [[Paths objectatindex:0] stringbyappendingpathcomponent :@ " file . pdf"];
nsarray *pdfurls = [nsarray arraywithobjects: filepath1,filepath2, nil];
[self joinpdf:P dfurls];
}
-(nsstring *) joinpdf: (nsarray *) listofpaths {
//File paths
nsstring *filename = [nsstring stringwithformat:@ " Official document %d.pdf", Arc4random_uniform(+)];
nsstring *pdfpathoutput = [[nssearchpathfordirectoriesindomains(nsdocumentdirectory, Nsuserdomainmask, YES) objectatindex:0] stringbyappendingpathcomponent : FileName];
cfurlref pdfurloutput = ( cfurlref)cfbridgingretain([nsurl fileurlwithpath :p Dfpathoutput]);
nsinteger numberofpages = 0;
//Create The output context
cgcontextref writecontext = cgpdfcontextcreatewithurl(pdfurloutput, null, null);
for (nsstring *source in listofpaths) {
cfurlref pdfurl = ( cfurlref)cfbridgingretain([[nsurl alloc] Initfileurlwithpath: source]);
//file ref
cgpdfdocumentref pdfref = cgpdfdocumentcreatewithurl((cfurlref) pdfurl);
Numberofpages = cgpdfdocumentgetnumberofpages(pdfref);
//Loop variables
cgpdfpageref page;
cgrect mediabox;
//Read the first PDF and generate the output pages
//NSLog (@ "Generating PAGES from PDF 1 (%@) ...", source);
for (int i=1; i<=numberofpages; i++) {
page = cgpdfdocumentgetpage(pdfref, i);
Mediabox = cgpdfpagegetboxrect(page, kcgpdfmediabox);
cgcontextbeginpage(Writecontext, &mediabox);
cgcontextdrawpdfpage(writecontext, page);
cgcontextendpage(writecontext);
}
cgpdfdocumentrelease(pdfref);
cfrelease(pdfurl);
}
cfrelease(pdfurloutput);
//Finalize the output file
cgpdfcontextclose(writecontext);
cgcontextrelease(writecontext);
return pdfpathoutput;
}
Ios-pdf Merging