/users/mac/library/developer/coresimulator/devices/38bb3233-7551-4dbe-a3d9-58934568818d/data/containers/data/ application/b4866c5a-b68e-437f-a787-8c83fc7d13d2/documents/
Add PDF files to the above emulator documents file Test.pdf
Call:
[Self createJPGsFromPDF:test.pdf];
-(void) Createjpgsfrompdf: (NSString *) frompdfname
{
if (Frompdfname = = Nil | | [Frompdfname isequaltostring:@ ""]) {
Return
}
Nsarray *paths = Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES);
NSString *documentsdir = [Paths objectatindex:0];
NSString *docpath = [Documentsdir stringbyappendingpathcomponent:frompdfname];
Nsurl *frompdfurl = [Nsurl Fileurlwithpath:docpath];
Cgpdfdocumentref Frompdfdoc = Cgpdfdocumentcreatewithurl ((cfurlref) frompdfurl);
Get Total Pages
float pages = cgpdfdocumentgetnumberofpages (Frompdfdoc);
Create Folder for store under "documents/"
Nserror *error = nil;
Nsfilemanager *filemanager = [[Nsfilemanager alloc] init];
NSString *folderpath = [Documentsdir stringbyappendingpathcomponent:[frompdfname stringbydeletingpathextension];
[FileManager createdirectoryatpath:folderpath withintermediatedirectories:yes Attributes:nil error:&error];
int i = 1;
for (i = 1; I <= pages; i++) {
Cgpdfpageref PageRef = Cgpdfdocumentgetpage (Frompdfdoc, i);
Cgpdfpageretain (PAGEREF);
Determine the size of the PDF page
CGRect pagerect = Cgpdfpagegetboxrect (PageRef, Kcgpdfmediabox);
Renders its content.
Uigraphicsbeginimagecontext (pagerect.size);
Cgcontextref Imgcontext = Uigraphicsgetcurrentcontext ();
Cgcontextsavegstate (Imgcontext);
CGCONTEXTTRANSLATECTM (Imgcontext, 0.0, pageRect.size.height);
CGCONTEXTSCALECTM (Imgcontext, 1.0,-1.0);
Cgcontextsetinterpolationquality (Imgcontext, Kcginterpolationdefault);
Cgcontextsetrenderingintent (Imgcontext, Kcgrenderingintentdefault);
Cgcontextdrawpdfpage (Imgcontext, PAGEREF);
Cgcontextrestoregstate (Imgcontext);
PDF Page to Image
UIImage *tempimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
Release Current Source page
Cgpdfpagerelease (PAGEREF);
Store IMG
NSString *imgname = [NSString stringwithformat:@ "frompdfname_%d.jpg", I];
NSString *imgpath = [FolderPath stringbyappendingpathcomponent:imgname];
[UIImageJPEGRepresentation (Tempimage, 1.0) Writetofile:imgpath Atomically:yes];
}
Cgpdfdocumentrelease (Frompdfdoc);
}
PDF to JPG