PDFUtils.m 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. //
  2. // PDFUtils.m
  3. // AntsContract
  4. //
  5. // Created by Ray on 12/20/16.
  6. // Copyright © 2016 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "PDFUtils.h"
  9. #import "PDFPage.h"
  10. #import "ImageDrawable.h"
  11. #import "TextDrawable.h"
  12. #import "RectDrawable.h"
  13. @implementation PDFUtils
  14. +(NSString*) addSignature :(UIImage*) img to:(NSMutableDictionary*)signatureData subType:(NSString*)subtype
  15. {
  16. if(true)
  17. {
  18. NSString* newfile=[self saveTempSignature:UIImagePNGRepresentation(img)];
  19. int newidx = [signatureData[subtype][@"count"] intValue];
  20. // [@"file"]= newfile;
  21. NSMutableDictionary* item = [[NSMutableDictionary alloc] init];
  22. item[@"file"]=newfile;
  23. NSMutableDictionary* subjson =signatureData[subtype];
  24. if(subjson==nil)
  25. subjson = [[NSMutableDictionary alloc] init];
  26. subjson[[NSString stringWithFormat:@"item_%d",newidx]] = item;
  27. subjson[@"count"]=[NSNumber numberWithInt:newidx+1];
  28. signatureData[subtype]=subjson;
  29. return newfile;
  30. }
  31. }
  32. +(NSString *) saveTempSignature:(NSData *) image
  33. {
  34. NSString* tempDir = NSTemporaryDirectory();
  35. NSString *saveFileName=[NSString stringWithFormat:@"%@.png",[[NSUUID UUID ] UUIDString] ] ;
  36. NSString *newFilePath=[tempDir stringByAppendingPathComponent:saveFileName];
  37. bool bsuccess=[image writeToFile:newFilePath atomically:YES];
  38. if(bsuccess)
  39. {
  40. return newFilePath;
  41. }
  42. else
  43. {
  44. return nil;
  45. }
  46. }
  47. +(NSMutableDictionary*) loadControl:(NSString*)templateName
  48. {
  49. NSString *path = [[NSBundle mainBundle] pathForResource:templateName ofType:nil];
  50. NSData *data = [NSData dataWithContentsOfFile:path];
  51. NSMutableDictionary *ret = [[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil] mutableCopy];
  52. return ret;
  53. }
  54. +(CGPDFDocumentRef)OpenPDF:(NSString*) file
  55. {
  56. //获取路径
  57. /*
  58. NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//坐标
  59. NSString *saveDirectory=[paths objectAtIndex:0];
  60. NSString *saveFileName=@"myPDF.pdf";
  61. NSString *newFilePath=[saveDirectory stringByAppendingPathComponent:saveFileName];
  62. */
  63. NSString *default_path = [[NSBundle mainBundle] pathForResource:file ofType:nil];
  64. const char *filename=[default_path UTF8String];
  65. NSLog(@"%@",default_path);
  66. //关联上下文的对象
  67. // CGContextRef pdfContext;
  68. // CFStringRef path;
  69. //
  70. // CFURLRef url;
  71. //
  72. // path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
  73. //
  74. // url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
  75. // CFRelease(path);
  76. CGPDFDocumentRef document;
  77. CFURLRef pdfURL = (__bridge CFURLRef)[NSURL fileURLWithPath:default_path];
  78. // CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(pdfURL);
  79. document = CGPDFDocumentCreateWithURL (pdfURL);
  80. // CFRelease(url);
  81. // size_t totalpage = CGPDFDocumentGetNumberOfPages (document);
  82. //
  83. // if (totalpage == 0) {
  84. // printf("[%s] needs at least one page!\n", [@"myPDF.pdf" UTF8String] );
  85. // return NULL;
  86. // } else {
  87. // printf("[%ld] pages loaded in this PDF!\n", totalpage);
  88. //
  89. //
  90. // /*8
  91. // for (NSInteger pageNumber = 1; pageNumber <= count; pageNumber++)
  92. // {
  93. // CGPDFPageRef pageRef = CGPDFDocumentGetPage(document, pageNumber);
  94. //
  95. // CGPDFDictionaryRef pageDictionaryFromPage = CGPDFPageGetDictionary(pageRef);
  96. //
  97. // if (pageDictionaryFromPage == pageDictionaryFromDestArray) // Found it
  98. // {
  99. // targetPageNumber = pageNumber; break;
  100. // }
  101. //
  102. //
  103. // }*/
  104. // }
  105. // CGPDFPageRef page= CGPDFDocumentGetPage(document, 0);
  106. // CGContextDrawPDFPage(<#CGContextRef _Nullable c#>, <#CGPDFPageRef _Nullable page#>)
  107. return document;
  108. }
  109. +(CGRect)WindowRect2PDFRect:(CGRect)rect pdf_rect:(CGRect)pdf_rect window_size:(CGSize)window_size
  110. {
  111. CGRect pdf_expand;
  112. float offset_x = 0;
  113. float offset_y = 0;
  114. float scale =1;
  115. if(pdf_rect.size.height>=pdf_rect.size.width)
  116. {
  117. pdf_expand = CGRectMake(0, 0, pdf_rect.size.height*window_size.width/window_size.height, pdf_rect.size.height);
  118. offset_x = (pdf_expand.size.width-pdf_rect.size.width)/2;
  119. scale = pdf_rect.size.height/window_size.height;
  120. }
  121. else
  122. {
  123. pdf_expand = CGRectMake(0, 0, pdf_rect.size.width, pdf_rect.size.width*window_size.height/window_size.width);
  124. offset_y = (pdf_expand.size.height-pdf_rect.size.height)/2;
  125. scale = pdf_rect.size.width/window_size.width;
  126. }
  127. float x=rect.origin.x*scale-offset_x;
  128. float y=rect.origin.y*scale-offset_y;
  129. float width = rect.size.width*scale;
  130. float height = rect.size.height*scale;
  131. return CGRectMake(x, y, width, height);
  132. }
  133. +(NSString*)SavePDF:(NSMutableDictionary*) controlTemplate source:(CGPDFDocumentRef )document window_rect:(CGRect)window_rect
  134. {
  135. //获取路径
  136. NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//坐标
  137. NSString *saveDirectory=[paths objectAtIndex:0];
  138. NSString *saveFileName=[NSString stringWithFormat:@"%@.pdf",[[NSUUID UUID ] UUIDString] ] ;;
  139. NSString *newFilePath=[saveDirectory stringByAppendingPathComponent:saveFileName];
  140. const char *filename=[newFilePath UTF8String];
  141. NSLog(@"%@",newFilePath);
  142. //设置页面大小 Letter纸
  143. //CGPDFDocumentGetMediaBox(document,1);
  144. // CGPDFDictionaryRef pdf_dict= CGPDFDocumentGetInfo(document);
  145. //关联上下文的对象
  146. CFStringRef path;
  147. CFURLRef url;
  148. path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
  149. url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
  150. CFRelease(path);
  151. // CGPDFCONTEXTCREATE
  152. CGContextRef pdfContext;
  153. CGRect docsize = CGRectMake(0, 0, 612, 1008);
  154. // NSDictionary *PDFAttributes =
  155. // [NSDictionary dictionaryWithObjectsAndKeys:
  156. // @"usai2010", (NSString *)kCGPDFContextOwnerPassword,
  157. // kCFBooleanTrue, (NSString *)kCGPDFContextAllowsPrinting,
  158. // kCFBooleanFalse, (NSString *)kCGPDFContextAllowsCopying,
  159. // nil];
  160. // // Create a descriptor.
  161. // CFDictionaryRef cfpdfAttributes =(__bridge_retained CFDictionaryRef)PDFAttributes;
  162. // CFBridgingRelease(cfpdfAttributes);
  163. CFMutableDictionaryRef myDictionary = NULL;
  164. myDictionary= CFDictionaryCreateMutable(NULL,
  165. 0,
  166. &kCFTypeDictionaryKeyCallBacks,
  167. &kCFTypeDictionaryValueCallBacks);
  168. // CFDictionarySetValue(myDictionary,
  169. // kCGPDFContextTitle,
  170. // CFSTR("Photo from iPrivate Album"));
  171. // CFDictionarySetValue(myDictionary,
  172. // kCGPDFContextCreator,
  173. // CFSTR("iPrivate Album"));
  174. // //设置文档名称
  175. // CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
  176. // //设置创建者
  177. // CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
  178. //设置文档尺寸
  179. CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, CFSTR("usai2010"));
  180. // CFDictionarySetValue(myDictionary, kCGPDFContextUserPassword, CFSTR("usai2010"));
  181. CFDictionarySetValue(myDictionary, kCGPDFContextAllowsPrinting, kCFBooleanTrue);
  182. CFDictionarySetValue(myDictionary, kCGPDFContextAllowsCopying, kCFBooleanFalse);
  183. //
  184. pdfContext=CGPDFContextCreateWithURL(url, &docsize,nil);
  185. CFRelease(myDictionary);
  186. CFRelease(url);
  187. size_t page_count=CGPDFDocumentGetNumberOfPages(document);
  188. for(int i=1;i<=page_count;i++)
  189. {
  190. int p = (i+4)%5+1;
  191. NSMutableDictionary* page_control=controlTemplate[[NSString stringWithFormat:@"page_%d",p-1]];
  192. CGPDFPageRef page= CGPDFDocumentGetPage (document , p);
  193. // CGPDFPageRef page1= CGPDFDocumentGetPage (document , i);
  194. CGRect papersize=CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
  195. CGContextBeginPage(pdfContext, &papersize);
  196. PDFPage* pdfPage = [[PDFPage alloc] init:nil size:papersize];
  197. [pdfPage DirectDraw:pdfContext page:page];
  198. for(int j=0;j<[page_control[@"count"] intValue];j++)
  199. {
  200. NSMutableDictionary* control=page_control[[NSString stringWithFormat:@"control_%d",j]];
  201. PDFDrawable * control_drawable = nil;
  202. CGRect control_rect = CGRectMake([control[@"pos_x"] floatValue], [control[@"pos_y"] floatValue], [control[@"width"] floatValue], [control[@"height"] floatValue]);
  203. NSString* control_type = control[@"type"];
  204. if([control_type isEqualToString:@"Signature"]||[control_type isEqualToString:@"Image"])
  205. {
  206. NSString* value = control[@"value"];
  207. if(value.length==0)
  208. continue;
  209. control_drawable=[[ImageDrawable alloc] init:[self WindowRect2PDFRect:control_rect pdf_rect:papersize window_size:window_rect.size] source_type:@"local" source:value hAlign:@"center" vAlign:@"middle"];
  210. }
  211. else if([control_type isEqualToString:@"TextView"]||[control_type isEqualToString:@"Label"]||[control_type isEqualToString:@"DatePicker"])
  212. {
  213. continue;
  214. NSString* value = control[@"value"];
  215. if(value.length==0)
  216. continue;
  217. NSString* size = control[@"size"];
  218. if(size.length==0)
  219. size=@"10";
  220. NSString* textAlignment=control[@"textAlignment"];
  221. if(textAlignment.length==0)
  222. textAlignment = @"Left";
  223. double margin_left = [control[@"margin_left"] doubleValue];
  224. control_drawable=[[TextDrawable alloc] init:[self WindowRect2PDFRect:control_rect pdf_rect:papersize window_size:window_rect.size] source_type:@"const" source:value textAlignment:textAlignment vAlign:@"middle" size:size];
  225. [control_drawable setMargin_left:margin_left];
  226. }
  227. else if([control_type isEqualToString:@"Check"])
  228. {
  229. NSArray* value = control[@"value"];
  230. if(value.count==0)
  231. continue;
  232. NSArray* cadedate = control[@"cadedate"];
  233. float marker_size = [control[@"marker_size"] floatValue];
  234. for(int c=0;c<value.count;c++)
  235. {
  236. NSArray* marker=cadedate[[value[c] intValue]];
  237. if(marker.count>=3)
  238. {
  239. continue;
  240. NSString* value = marker[0][0];
  241. if(value.length==0)
  242. continue;
  243. NSString* size = control[@"size"];
  244. if(size.length==0)
  245. size=@"10";
  246. control_drawable=[[TextDrawable alloc] init:[self WindowRect2PDFRect:control_rect pdf_rect:papersize window_size:window_rect.size] source_type:@"const" source:value textAlignment:@"Center" vAlign:@"middle" size:size];
  247. }
  248. else
  249. {
  250. continue;
  251. CGRect marker_rect= CGRectMake([marker[1][0] floatValue] ,[marker[1][1] floatValue], marker_size, marker_size);
  252. PDFDrawable * marker_drawable = [[RectDrawable alloc] init:[self WindowRect2PDFRect:marker_rect pdf_rect:papersize window_size:window_rect.size] color:@"0x000000"];
  253. if(marker_drawable)
  254. [pdfPage DirectDraw:pdfContext drawable:marker_drawable];
  255. }
  256. }
  257. // NSString* size = control[@"size"];
  258. // if(size.length==0)
  259. // size=@"10";
  260. //
  261. // control_drawable=[[TextDrawable alloc] init:[self WindowRect2PDFRect:control_rect pdf_rect:papersize window_size:window_rect.size] source_type:@"const" source:value textAlignment:@"center" vAlign:@"middle" size:size];
  262. }
  263. if(control_drawable)
  264. [pdfPage DirectDraw:pdfContext drawable:control_drawable];
  265. }
  266. // NSMutableDictionary* tline1= [LineDrawable createlineTemplate:1 from:CGPointMake(20, 20) to:CGPointMake(500,500)];
  267. // LineDrawable* line1=nil;
  268. // line1= [[LineDrawable alloc] init:tline1];
  269. //
  270. // [pdfPage DirectDraw:pdfContext drawable:line1];
  271. // NSRange range = NSMakeRange(0,9999);
  272. // [line1 Draw:pdfContext dataSource:nil ParentRect:papersize startX:0 startY:0 flipHeight:0 range:range];
  273. CGContextEndPage(pdfContext);
  274. // CGPDFPageRelease(page);
  275. // [pdfPage Draw:pdfContext dataSource:nil];
  276. // [self drawPage:pdfContext template:page size:papersize dataSource:data];
  277. // CFBridgingRelease(page);
  278. }
  279. CGContextRelease(pdfContext);
  280. // CFRelease(cfpdfAttributes);
  281. // //开始画pdf
  282. //
  283. // // NSString *temtext=[[NSString alloc]init];
  284. // //
  285. // // const char *text=(char *)[temtext UTF8String];
  286. // //
  287. // // int width;
  288. // //
  289. // // int height;
  290. // //
  291. //
  292. // // [self newpage:pdfContext size:papersize];
  293. //
  294. //
  295. //
  296. // CGContextRelease(pdfContext);
  297. return newFilePath;
  298. }
  299. //{
  300. //
  301. // //获取路径
  302. //
  303. // NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//坐标
  304. //
  305. // NSString *saveDirectory=[paths objectAtIndex:0];
  306. //
  307. // NSString *saveFileName=[NSString stringWithFormat:@"%@.pdf",[[NSUUID UUID ] UUIDString] ] ;;
  308. //
  309. // NSString *newFilePath=[saveDirectory stringByAppendingPathComponent:saveFileName];
  310. //
  311. // const char *filename=[newFilePath UTF8String];
  312. //
  313. // NSLog(@"%@",newFilePath);
  314. // //设置页面大小 Letter纸
  315. //
  316. // //CGPDFDocumentGetMediaBox(document,1);
  317. // // CGPDFDictionaryRef pdf_dict= CGPDFDocumentGetInfo(document);
  318. //
  319. //
  320. //
  321. //
  322. //
  323. // //关联上下文的对象
  324. //
  325. //
  326. //
  327. // CFStringRef path;
  328. //
  329. // CFURLRef url;
  330. //
  331. // path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
  332. //
  333. // url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
  334. //
  335. // CFRelease(path);
  336. // // CGPDFCONTEXTCREATE
  337. //
  338. //
  339. // CGContextRef pdfContext;
  340. // CGRect docsize = CGRectMake(0, 0, 100, 100);
  341. //
  342. //
  343. //// if(name.length==0)
  344. //// {
  345. //// name=@"Helvetica";
  346. //// // name=@"DejaVu Sans";
  347. //// }
  348. //// if(size==0)
  349. //// {
  350. //// size=10;
  351. //// }
  352. //// NSString* style = @"Regular";
  353. //// if(bold)
  354. //// style=@"Bold";
  355. ////
  356. //// //name=@"Courier";
  357. //
  358. //// NSDictionary *PDFAttributes =
  359. //// [NSDictionary dictionaryWithObjectsAndKeys:
  360. //// @"usai2010", (NSString *)kCGPDFContextOwnerPassword,
  361. //// kCFBooleanTrue, (NSString *)kCGPDFContextAllowsPrinting,
  362. //// kCFBooleanFalse, (NSString *)kCGPDFContextAllowsCopying,
  363. //// nil];
  364. //// // Create a descriptor.
  365. //// CFDictionaryRef cfpdfAttributes =(__bridge CFDictionaryRef)(PDFAttributes);
  366. ////
  367. ////
  368. //// // CFBridgingRelease(cfpdfAttributes);
  369. //// pdfContext=CGPDFContextCreateWithURL(url, &docsize,cfpdfAttributes);
  370. //
  371. //
  372. //
  373. // CFMutableDictionaryRef myDictionary = NULL;
  374. // //文档信息字典
  375. //// myDictionary = CFDictionaryCreateMutable(NULL, 0,
  376. //// &kCFTypeDictionaryKeyCallBacks,
  377. //// &kCFTypeDictionaryValueCallBacks);
  378. ////
  379. ////// CFStringRef password = (__bridge CFStringRef)@"usai2010";
  380. ////// CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, password);
  381. ////
  382. //// CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
  383. ////
  384. //////
  385. //// CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, CFSTR("usai2010"));
  386. //////
  387. ////
  388. //// CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
  389. //// CFDictionarySetValue(myDictionary, kCGPDFContextAllowsPrinting, kCFBooleanTrue);
  390. //// CFDictionarySetValue(myDictionary, kCGPDFContextAllowsCopying, kCFBooleanFalse);
  391. //
  392. // //创建文档
  393. // pdfContext = CGPDFContextCreateWithURL (url, &docsize, NULL);
  394. //
  395. //
  396. //
  397. // size_t page_count=CGPDFDocumentGetNumberOfPages(document);
  398. // for(int i=1;i<=page_count;i++)
  399. // {
  400. // NSMutableDictionary* page_control=controlTemplate[[NSString stringWithFormat:@"page_%d",i-1]];
  401. // CGPDFPageRef page= CGPDFDocumentGetPage (document , i);
  402. //
  403. // CGRect papersize=CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
  404. //
  405. //
  406. //
  407. // CGContextBeginPage(pdfContext, &papersize);
  408. //
  409. // PDFPage* pdfPage = [[PDFPage alloc] init:nil size:papersize];
  410. //
  411. // [pdfPage DirectDraw:pdfContext page:page];
  412. //
  413. //
  414. // for(int j=0;j<[page_control[@"count"] intValue];j++)
  415. // {
  416. // NSMutableDictionary* control=page_control[[NSString stringWithFormat:@"control_%d",j]];
  417. //
  418. // PDFDrawable * control_drawable = nil;
  419. // CGRect control_rect = CGRectMake([control[@"pos_x"] floatValue], [control[@"pos_y"] floatValue], [control[@"width"] floatValue], [control[@"height"] floatValue]);
  420. //
  421. //
  422. // NSString* control_type = control[@"type"];
  423. // if([control_type isEqualToString:@"Signature"]||[control_type isEqualToString:@"Image"])
  424. // {
  425. //
  426. // NSString* value = control[@"value"];
  427. // if(value.length==0)
  428. // continue;
  429. //
  430. //
  431. // control_drawable=[[ImageDrawable alloc] init:[self WindowRect2PDFRect:control_rect pdf_rect:papersize window_size:window_rect.size] source_type:@"local" source:value hAlign:@"center" vAlign:@"middle"];
  432. // }
  433. // else if([control_type isEqualToString:@"TextView"]||[control_type isEqualToString:@"Label"]||[control_type isEqualToString:@"DatePicker"])
  434. // {
  435. //
  436. // NSString* value = control[@"value"];
  437. // if(value.length==0)
  438. // continue;
  439. // NSString* size = control[@"size"];
  440. // if(size.length==0)
  441. // size=@"10";
  442. // NSString* textAlignment=control[@"textAlignment"];
  443. // if(textAlignment.length==0)
  444. // textAlignment = @"Center";
  445. // double margin_left = [control[@"margin_left"] doubleValue];
  446. //
  447. //
  448. // control_drawable=[[TextDrawable alloc] init:[self WindowRect2PDFRect:control_rect pdf_rect:papersize window_size:window_rect.size] source_type:@"const" source:value textAlignment:textAlignment vAlign:@"middle" size:size];
  449. //
  450. // [control_drawable setMargin_left:margin_left];
  451. // }
  452. // else if([control_type isEqualToString:@"Check"])
  453. // {
  454. // NSArray* value = control[@"value"];
  455. // if(value.count==0)
  456. // continue;
  457. // NSArray* cadedate = control[@"cadedate"];
  458. // float marker_size = [control[@"marker_size"] floatValue];
  459. //
  460. // for(int c=0;c<value.count;c++)
  461. // {
  462. // NSArray* marker=cadedate[[value[c] intValue]];
  463. // if(marker.count>=3)
  464. // {
  465. // NSString* value = marker[0][0];
  466. // if(value.length==0)
  467. // continue;
  468. // NSString* size = control[@"size"];
  469. // if(size.length==0)
  470. // size=@"10";
  471. //
  472. // control_drawable=[[TextDrawable alloc] init:[self WindowRect2PDFRect:control_rect pdf_rect:papersize window_size:window_rect.size] source_type:@"const" source:value textAlignment:@"Center" vAlign:@"middle" size:size];
  473. // }
  474. // else
  475. // {
  476. // CGRect marker_rect= CGRectMake([marker[1][0] floatValue] ,[marker[1][1] floatValue], marker_size, marker_size);
  477. // PDFDrawable * marker_drawable = [[RectDrawable alloc] init:[self WindowRect2PDFRect:marker_rect pdf_rect:papersize window_size:window_rect.size] color:@"0x000000"];
  478. // if(marker_drawable)
  479. // [pdfPage DirectDraw:pdfContext drawable:marker_drawable];
  480. // }
  481. //
  482. // }
  483. //
  484. //// NSString* size = control[@"size"];
  485. //// if(size.length==0)
  486. //// size=@"10";
  487. ////
  488. //// control_drawable=[[TextDrawable alloc] init:[self WindowRect2PDFRect:control_rect pdf_rect:papersize window_size:window_rect.size] source_type:@"const" source:value textAlignment:@"center" vAlign:@"middle" size:size];
  489. // }
  490. // if(control_drawable)
  491. //// for(int l=0;l<100;l++)
  492. // [pdfPage DirectDraw:pdfContext drawable:control_drawable];
  493. //
  494. //
  495. //
  496. // }
  497. //// NSMutableDictionary* tline1= [LineDrawable createlineTemplate:1 from:CGPointMake(20, 20) to:CGPointMake(500,500)];
  498. //// LineDrawable* line1=nil;
  499. //// line1= [[LineDrawable alloc] init:tline1];
  500. ////
  501. //// [pdfPage DirectDraw:pdfContext drawable:line1];
  502. //// NSRange range = NSMakeRange(0,9999);
  503. //// [line1 Draw:pdfContext dataSource:nil ParentRect:papersize startX:0 startY:0 flipHeight:0 range:range];
  504. //
  505. // CGContextEndPage(pdfContext);
  506. //
  507. // // [pdfPage Draw:pdfContext dataSource:nil];
  508. //// [self drawPage:pdfContext template:page size:papersize dataSource:data];
  509. //
  510. //
  511. //// CFBridgingRelease(page);
  512. // }
  513. // CGContextRelease(pdfContext);
  514. // CFRelease(url);
  515. // // CFRelease(myDictionary);
  516. //
  517. //
  518. // // CFRelease(cfpdfAttributes);
  519. //// //开始画pdf
  520. ////
  521. //// // NSString *temtext=[[NSString alloc]init];
  522. //// //
  523. //// // const char *text=(char *)[temtext UTF8String];
  524. //// //
  525. //// // int width;
  526. //// //
  527. //// // int height;
  528. //// //
  529. ////
  530. //// // [self newpage:pdfContext size:papersize];
  531. ////
  532. ////
  533. ////
  534. //// CGContextRelease(pdfContext);
  535. //
  536. // return newFilePath;
  537. //
  538. //}
  539. @end