|
@@ -14,6 +14,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
@implementation PDFUtils
|
|
@implementation PDFUtils
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
+(NSString*) addSignature :(UIImage*) img to:(NSMutableDictionary*)signatureData subType:(NSString*)subtype
|
|
+(NSString*) addSignature :(UIImage*) img to:(NSMutableDictionary*)signatureData subType:(NSString*)subtype
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -94,43 +96,49 @@
|
|
|
|
|
|
|
|
// CGContextRef pdfContext;
|
|
// CGContextRef pdfContext;
|
|
|
|
|
|
|
|
- CFStringRef path;
|
|
|
|
|
|
|
+// CFStringRef path;
|
|
|
|
|
+//
|
|
|
|
|
+// CFURLRef url;
|
|
|
|
|
+//
|
|
|
|
|
+// path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
|
|
|
|
|
+//
|
|
|
|
|
+// url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
|
|
|
|
|
|
|
|
- CFURLRef url;
|
|
|
|
|
|
|
|
|
|
- path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
|
|
|
|
|
|
|
+// CFRelease(path);
|
|
|
|
|
+ CGPDFDocumentRef document;
|
|
|
|
|
|
|
|
- url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
|
|
|
|
|
|
|
|
|
|
|
|
+ CFURLRef pdfURL = (__bridge CFURLRef)[NSURL fileURLWithPath:default_path];
|
|
|
|
|
|
|
|
- CFRelease(path);
|
|
|
|
|
- CGPDFDocumentRef document;
|
|
|
|
|
- document = CGPDFDocumentCreateWithURL (url);
|
|
|
|
|
- CFRelease(url);
|
|
|
|
|
- size_t totalpage = CGPDFDocumentGetNumberOfPages (document);
|
|
|
|
|
-
|
|
|
|
|
- if (totalpage == 0) {
|
|
|
|
|
- printf("[%s] needs at least one page!\n", [@"myPDF.pdf" UTF8String] );
|
|
|
|
|
- return NULL;
|
|
|
|
|
- } else {
|
|
|
|
|
- printf("[%ld] pages loaded in this PDF!\n", totalpage);
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /*8
|
|
|
|
|
- for (NSInteger pageNumber = 1; pageNumber <= count; pageNumber++)
|
|
|
|
|
- {
|
|
|
|
|
- CGPDFPageRef pageRef = CGPDFDocumentGetPage(document, pageNumber);
|
|
|
|
|
-
|
|
|
|
|
- CGPDFDictionaryRef pageDictionaryFromPage = CGPDFPageGetDictionary(pageRef);
|
|
|
|
|
-
|
|
|
|
|
- if (pageDictionaryFromPage == pageDictionaryFromDestArray) // Found it
|
|
|
|
|
- {
|
|
|
|
|
- targetPageNumber = pageNumber; break;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- }*/
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL(pdfURL);
|
|
|
|
|
+
|
|
|
|
|
+ document = CGPDFDocumentCreateWithURL (pdfURL);
|
|
|
|
|
+// CFRelease(url);
|
|
|
|
|
+// size_t totalpage = CGPDFDocumentGetNumberOfPages (document);
|
|
|
|
|
+//
|
|
|
|
|
+// if (totalpage == 0) {
|
|
|
|
|
+// printf("[%s] needs at least one page!\n", [@"myPDF.pdf" UTF8String] );
|
|
|
|
|
+// return NULL;
|
|
|
|
|
+// } else {
|
|
|
|
|
+// printf("[%ld] pages loaded in this PDF!\n", totalpage);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// /*8
|
|
|
|
|
+// for (NSInteger pageNumber = 1; pageNumber <= count; pageNumber++)
|
|
|
|
|
+// {
|
|
|
|
|
+// CGPDFPageRef pageRef = CGPDFDocumentGetPage(document, pageNumber);
|
|
|
|
|
+//
|
|
|
|
|
+// CGPDFDictionaryRef pageDictionaryFromPage = CGPDFPageGetDictionary(pageRef);
|
|
|
|
|
+//
|
|
|
|
|
+// if (pageDictionaryFromPage == pageDictionaryFromDestArray) // Found it
|
|
|
|
|
+// {
|
|
|
|
|
+// targetPageNumber = pageNumber; break;
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// }*/
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
// CGPDFPageRef page= CGPDFDocumentGetPage(document, 0);
|
|
// CGPDFPageRef page= CGPDFDocumentGetPage(document, 0);
|
|
|
// CGContextDrawPDFPage(<#CGContextRef _Nullable c#>, <#CGPDFPageRef _Nullable page#>)
|
|
// CGContextDrawPDFPage(<#CGContextRef _Nullable c#>, <#CGPDFPageRef _Nullable page#>)
|
|
@@ -167,7 +175,70 @@
|
|
|
return CGRectMake(x, y, width, height);
|
|
return CGRectMake(x, y, width, height);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
++(void) leak_test:(NSMutableDictionary*) controlTemplate source:(CGPDFDocumentRef* )document window_rect:(CGRect)window_rect
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //获取路径
|
|
|
|
|
+
|
|
|
|
|
+ NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//坐标
|
|
|
|
|
+
|
|
|
|
|
+ NSString *saveDirectory=[paths objectAtIndex:0];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *saveFileName=[NSString stringWithFormat:@"%@.pdf",[[NSUUID UUID ] UUIDString] ] ;;
|
|
|
|
|
+
|
|
|
|
|
+ NSString *newFilePath=[saveDirectory stringByAppendingPathComponent:saveFileName];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ const char *filename=[newFilePath UTF8String];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ CFStringRef path;
|
|
|
|
|
+
|
|
|
|
|
+ CFURLRef url;
|
|
|
|
|
+
|
|
|
|
|
+ path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
|
|
|
|
|
+
|
|
|
|
|
+ url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
|
|
|
|
|
+
|
|
|
|
|
+ CFBridgingRelease(path);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ CGContextRef pdfContext;
|
|
|
|
|
+ CGRect docsize = CGRectMake(0, 0, 612, 1008);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ CFMutableDictionaryRef myDictionary = NULL;
|
|
|
|
|
+ myDictionary= CFDictionaryCreateMutable(NULL,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ &kCFTypeDictionaryKeyCallBacks,
|
|
|
|
|
+ &kCFTypeDictionaryValueCallBacks);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //如果注释掉这行就不会有问题
|
|
|
|
|
+// CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, CFSTR("12345"));
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ CFDictionarySetValue(myDictionary, kCGPDFContextAllowsPrinting, kCFBooleanTrue);
|
|
|
|
|
+ CFDictionarySetValue(myDictionary, kCGPDFContextAllowsCopying, kCFBooleanFalse);
|
|
|
|
|
+
|
|
|
|
|
+ pdfContext=CGPDFContextCreateWithURL(url, &docsize,myDictionary);
|
|
|
|
|
+
|
|
|
|
|
+ CFRelease(myDictionary);
|
|
|
|
|
+ CFBridgingRelease(url);
|
|
|
|
|
+ CGPDFContextClose(pdfContext);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ CGContextRelease(pdfContext);
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
+(NSString*)SavePDF:(NSMutableDictionary*) controlTemplate source:(CGPDFDocumentRef )document window_rect:(CGRect)window_rect
|
|
+(NSString*)SavePDF:(NSMutableDictionary*) controlTemplate source:(CGPDFDocumentRef )document window_rect:(CGRect)window_rect
|
|
|
{
|
|
{
|
|
|
|
|
|
|
@@ -187,10 +258,10 @@
|
|
|
//设置页面大小 Letter纸
|
|
//设置页面大小 Letter纸
|
|
|
|
|
|
|
|
//CGPDFDocumentGetMediaBox(document,1);
|
|
//CGPDFDocumentGetMediaBox(document,1);
|
|
|
- CGPDFDictionaryRef pdf_dict= CGPDFDocumentGetInfo(document);
|
|
|
|
|
|
|
+ // CGPDFDictionaryRef pdf_dict= CGPDFDocumentGetInfo(document);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//关联上下文的对象
|
|
//关联上下文的对象
|
|
@@ -208,49 +279,64 @@
|
|
|
CFBridgingRelease(path);
|
|
CFBridgingRelease(path);
|
|
|
// CGPDFCONTEXTCREATE
|
|
// CGPDFCONTEXTCREATE
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
CGContextRef pdfContext;
|
|
CGContextRef pdfContext;
|
|
|
- CGRect docsize = CGRectMake(0, 0, 100, 100);
|
|
|
|
|
|
|
+ CGRect docsize = CGRectMake(0, 0, 612, 1008);
|
|
|
|
|
|
|
|
|
|
|
|
|
-// if(name.length==0)
|
|
|
|
|
-// {
|
|
|
|
|
-// name=@"Helvetica";
|
|
|
|
|
-// // name=@"DejaVu Sans";
|
|
|
|
|
-// }
|
|
|
|
|
-// if(size==0)
|
|
|
|
|
-// {
|
|
|
|
|
-// size=10;
|
|
|
|
|
-// }
|
|
|
|
|
-// NSString* style = @"Regular";
|
|
|
|
|
-// if(bold)
|
|
|
|
|
-// style=@"Bold";
|
|
|
|
|
-//
|
|
|
|
|
-// //name=@"Courier";
|
|
|
|
|
-
|
|
|
|
|
- NSDictionary *PDFAttributes =
|
|
|
|
|
- [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
|
- @"usai2010", (NSString *)kCGPDFContextOwnerPassword,
|
|
|
|
|
- kCFBooleanTrue, (NSString *)kCGPDFContextAllowsPrinting,
|
|
|
|
|
- kCFBooleanFalse, (NSString *)kCGPDFContextAllowsCopying,
|
|
|
|
|
- nil];
|
|
|
|
|
- // Create a descriptor.
|
|
|
|
|
- CFDictionaryRef cfpdfAttributes =(__bridge CFDictionaryRef)(PDFAttributes);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ // NSDictionary *PDFAttributes =
|
|
|
|
|
+ // [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
|
+ // @"usai2010", (NSString *)kCGPDFContextOwnerPassword,
|
|
|
|
|
+ // kCFBooleanTrue, (NSString *)kCGPDFContextAllowsPrinting,
|
|
|
|
|
+ // kCFBooleanFalse, (NSString *)kCGPDFContextAllowsCopying,
|
|
|
|
|
+ // nil];
|
|
|
|
|
+ // // Create a descriptor.
|
|
|
|
|
+ // CFDictionaryRef cfpdfAttributes =(__bridge_retained CFDictionaryRef)PDFAttributes;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // CFBridgingRelease(cfpdfAttributes);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ CFMutableDictionaryRef myDictionary = NULL;
|
|
|
|
|
+ myDictionary= CFDictionaryCreateMutable(NULL,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ &kCFTypeDictionaryKeyCallBacks,
|
|
|
|
|
+ &kCFTypeDictionaryValueCallBacks);
|
|
|
|
|
+ // CFDictionarySetValue(myDictionary,
|
|
|
|
|
+ // kCGPDFContextTitle,
|
|
|
|
|
+ // CFSTR("Photo from iPrivate Album"));
|
|
|
|
|
+ // CFDictionarySetValue(myDictionary,
|
|
|
|
|
+ // kCGPDFContextCreator,
|
|
|
|
|
+ // CFSTR("iPrivate Album"));
|
|
|
|
|
+
|
|
|
|
|
+ // //设置文档名称
|
|
|
|
|
+ // CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
|
|
|
|
|
+ // //设置创建者
|
|
|
|
|
+ // CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
|
|
|
|
|
+ //设置文档尺寸
|
|
|
|
|
+ CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, CFSTR("usai2010"));
|
|
|
|
|
+ CFDictionarySetValue(myDictionary, kCGPDFContextAllowsPrinting, kCFBooleanTrue);
|
|
|
|
|
+ CFDictionarySetValue(myDictionary, kCGPDFContextAllowsCopying, kCFBooleanFalse);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ pdfContext=CGPDFContextCreateWithURL(url, &docsize,NULL);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- // CFBridgingRelease(cfpdfAttributes);
|
|
|
|
|
- pdfContext=CGPDFContextCreateWithURL(url, &docsize,cfpdfAttributes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t page_count=CGPDFDocumentGetNumberOfPages(document);
|
|
size_t page_count=CGPDFDocumentGetNumberOfPages(document);
|
|
|
for(int i=1;i<=page_count;i++)
|
|
for(int i=1;i<=page_count;i++)
|
|
|
{
|
|
{
|
|
|
- NSMutableDictionary* page_control=controlTemplate[[NSString stringWithFormat:@"page_%d",i-1]];
|
|
|
|
|
- CGPDFPageRef page= CGPDFDocumentGetPage (document , i);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ int p = (i+4)%5+1;
|
|
|
|
|
+ NSMutableDictionary* page_control=controlTemplate[[NSString stringWithFormat:@"page_%d",p-1]];
|
|
|
|
|
+ CGPDFPageRef page= CGPDFDocumentGetPage (document , p);
|
|
|
|
|
+ // CGPDFPageRef page1= CGPDFDocumentGetPage (document , i);
|
|
|
CGRect papersize=CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
|
|
CGRect papersize=CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
CGContextBeginPage(pdfContext, &papersize);
|
|
CGContextBeginPage(pdfContext, &papersize);
|
|
@@ -267,10 +353,11 @@
|
|
|
PDFDrawable * control_drawable = nil;
|
|
PDFDrawable * control_drawable = nil;
|
|
|
CGRect control_rect = CGRectMake([control[@"pos_x"] floatValue], [control[@"pos_y"] floatValue], [control[@"width"] floatValue], [control[@"height"] floatValue]);
|
|
CGRect control_rect = CGRectMake([control[@"pos_x"] floatValue], [control[@"pos_y"] floatValue], [control[@"width"] floatValue], [control[@"height"] floatValue]);
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
NSString* control_type = control[@"type"];
|
|
NSString* control_type = control[@"type"];
|
|
|
if([control_type isEqualToString:@"Signature"]||[control_type isEqualToString:@"Image"])
|
|
if([control_type isEqualToString:@"Signature"]||[control_type isEqualToString:@"Image"])
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
NSString* value = control[@"value"];
|
|
NSString* value = control[@"value"];
|
|
|
if(value.length==0)
|
|
if(value.length==0)
|
|
|
continue;
|
|
continue;
|
|
@@ -280,14 +367,23 @@
|
|
|
}
|
|
}
|
|
|
else if([control_type isEqualToString:@"TextView"]||[control_type isEqualToString:@"Label"]||[control_type isEqualToString:@"DatePicker"])
|
|
else if([control_type isEqualToString:@"TextView"]||[control_type isEqualToString:@"Label"]||[control_type isEqualToString:@"DatePicker"])
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
NSString* value = control[@"value"];
|
|
NSString* value = control[@"value"];
|
|
|
if(value.length==0)
|
|
if(value.length==0)
|
|
|
continue;
|
|
continue;
|
|
|
NSString* size = control[@"size"];
|
|
NSString* size = control[@"size"];
|
|
|
if(size.length==0)
|
|
if(size.length==0)
|
|
|
size=@"10";
|
|
size=@"10";
|
|
|
|
|
+ NSString* textAlignment=control[@"textAlignment"];
|
|
|
|
|
+ if(textAlignment.length==0)
|
|
|
|
|
+ textAlignment = @"Middle";
|
|
|
|
|
+ double margin_left = [control[@"margin_left"] doubleValue];
|
|
|
|
|
|
|
|
- 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];
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ 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];
|
|
|
|
|
+
|
|
|
|
|
+ [control_drawable setMargin_left:margin_left];
|
|
|
}
|
|
}
|
|
|
else if([control_type isEqualToString:@"Check"])
|
|
else if([control_type isEqualToString:@"Check"])
|
|
|
{
|
|
{
|
|
@@ -296,7 +392,7 @@
|
|
|
continue;
|
|
continue;
|
|
|
NSArray* cadedate = control[@"cadedate"];
|
|
NSArray* cadedate = control[@"cadedate"];
|
|
|
float marker_size = [control[@"marker_size"] floatValue];
|
|
float marker_size = [control[@"marker_size"] floatValue];
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
for(int c=0;c<value.count;c++)
|
|
for(int c=0;c<value.count;c++)
|
|
|
{
|
|
{
|
|
|
NSArray* marker=cadedate[[value[c] intValue]];
|
|
NSArray* marker=cadedate[[value[c] intValue]];
|
|
@@ -309,7 +405,7 @@
|
|
|
if(size.length==0)
|
|
if(size.length==0)
|
|
|
size=@"10";
|
|
size=@"10";
|
|
|
|
|
|
|
|
- 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];
|
|
|
|
|
|
|
+ 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];
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -318,59 +414,305 @@
|
|
|
if(marker_drawable)
|
|
if(marker_drawable)
|
|
|
[pdfPage DirectDraw:pdfContext drawable:marker_drawable];
|
|
[pdfPage DirectDraw:pdfContext drawable:marker_drawable];
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// NSString* size = control[@"size"];
|
|
|
|
|
-// if(size.length==0)
|
|
|
|
|
-// size=@"10";
|
|
|
|
|
-//
|
|
|
|
|
-// 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];
|
|
|
|
|
|
|
+ // NSString* size = control[@"size"];
|
|
|
|
|
+ // if(size.length==0)
|
|
|
|
|
+ // size=@"10";
|
|
|
|
|
+ //
|
|
|
|
|
+ // 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];
|
|
|
}
|
|
}
|
|
|
if(control_drawable)
|
|
if(control_drawable)
|
|
|
- [pdfPage DirectDraw:pdfContext drawable:control_drawable];
|
|
|
|
|
|
|
+// for(int l=0;l<1000;l++)
|
|
|
|
|
+ [pdfPage DirectDraw:pdfContext drawable:control_drawable];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-// NSMutableDictionary* tline1= [LineDrawable createlineTemplate:1 from:CGPointMake(20, 20) to:CGPointMake(500,500)];
|
|
|
|
|
-// LineDrawable* line1=nil;
|
|
|
|
|
-// line1= [[LineDrawable alloc] init:tline1];
|
|
|
|
|
-//
|
|
|
|
|
-// [pdfPage DirectDraw:pdfContext drawable:line1];
|
|
|
|
|
-// NSRange range = NSMakeRange(0,9999);
|
|
|
|
|
-// [line1 Draw:pdfContext dataSource:nil ParentRect:papersize startX:0 startY:0 flipHeight:0 range:range];
|
|
|
|
|
|
|
+ // NSMutableDictionary* tline1= [LineDrawable createlineTemplate:1 from:CGPointMake(20, 20) to:CGPointMake(500,500)];
|
|
|
|
|
+ // LineDrawable* line1=nil;
|
|
|
|
|
+ // line1= [[LineDrawable alloc] init:tline1];
|
|
|
|
|
+ //
|
|
|
|
|
+ // [pdfPage DirectDraw:pdfContext drawable:line1];
|
|
|
|
|
+ // NSRange range = NSMakeRange(0,9999);
|
|
|
|
|
+ // [line1 Draw:pdfContext dataSource:nil ParentRect:papersize startX:0 startY:0 flipHeight:0 range:range];
|
|
|
|
|
|
|
|
- CGContextEndPage(pdfContext);
|
|
|
|
|
-
|
|
|
|
|
- // [pdfPage Draw:pdfContext dataSource:nil];
|
|
|
|
|
-// [self drawPage:pdfContext template:page size:papersize dataSource:data];
|
|
|
|
|
|
|
+ CGContextEndPage(pdfContext);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // CGPDFPageRelease(page);
|
|
|
|
|
|
|
|
|
|
+ // [pdfPage Draw:pdfContext dataSource:nil];
|
|
|
|
|
+ // [self drawPage:pdfContext template:page size:papersize dataSource:data];
|
|
|
|
|
|
|
|
-// CFBridgingRelease(page);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // CFBridgingRelease(page);
|
|
|
}
|
|
}
|
|
|
CGContextRelease(pdfContext);
|
|
CGContextRelease(pdfContext);
|
|
|
|
|
+ CFRelease(myDictionary);
|
|
|
CFBridgingRelease(url);
|
|
CFBridgingRelease(url);
|
|
|
- // CFRelease(cfpdfAttributes);
|
|
|
|
|
-// //开始画pdf
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // CFRelease(cfpdfAttributes);
|
|
|
|
|
+ // //开始画pdf
|
|
|
|
|
+ //
|
|
|
|
|
+ // // NSString *temtext=[[NSString alloc]init];
|
|
|
|
|
+ // //
|
|
|
|
|
+ // // const char *text=(char *)[temtext UTF8String];
|
|
|
|
|
+ // //
|
|
|
|
|
+ // // int width;
|
|
|
|
|
+ // //
|
|
|
|
|
+ // // int height;
|
|
|
|
|
+ // //
|
|
|
|
|
+ //
|
|
|
|
|
+ // // [self newpage:pdfContext size:papersize];
|
|
|
|
|
+ //
|
|
|
|
|
+ //
|
|
|
|
|
+ //
|
|
|
|
|
+ // CGContextRelease(pdfContext);
|
|
|
|
|
+
|
|
|
|
|
+ return newFilePath;
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+//{
|
|
|
|
|
+//
|
|
|
|
|
+// //获取路径
|
|
|
|
|
+//
|
|
|
|
|
+// NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);//坐标
|
|
|
|
|
+//
|
|
|
|
|
+// NSString *saveDirectory=[paths objectAtIndex:0];
|
|
|
|
|
+//
|
|
|
|
|
+// NSString *saveFileName=[NSString stringWithFormat:@"%@.pdf",[[NSUUID UUID ] UUIDString] ] ;;
|
|
|
|
|
+//
|
|
|
|
|
+// NSString *newFilePath=[saveDirectory stringByAppendingPathComponent:saveFileName];
|
|
|
|
|
+//
|
|
|
|
|
+// const char *filename=[newFilePath UTF8String];
|
|
|
|
|
+//
|
|
|
|
|
+// NSLog(@"%@",newFilePath);
|
|
|
|
|
+// //设置页面大小 Letter纸
|
|
|
|
|
+//
|
|
|
|
|
+// //CGPDFDocumentGetMediaBox(document,1);
|
|
|
|
|
+// // CGPDFDictionaryRef pdf_dict= CGPDFDocumentGetInfo(document);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// //关联上下文的对象
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// CFStringRef path;
|
|
|
|
|
+//
|
|
|
|
|
+// CFURLRef url;
|
|
|
|
|
+//
|
|
|
|
|
+// path=CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
|
|
|
//
|
|
//
|
|
|
-// // NSString *temtext=[[NSString alloc]init];
|
|
|
|
|
-// //
|
|
|
|
|
-// // const char *text=(char *)[temtext UTF8String];
|
|
|
|
|
-// //
|
|
|
|
|
-// // int width;
|
|
|
|
|
-// //
|
|
|
|
|
-// // int height;
|
|
|
|
|
-// //
|
|
|
|
|
|
|
+// url=CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, 0);
|
|
|
//
|
|
//
|
|
|
-// // [self newpage:pdfContext size:papersize];
|
|
|
|
|
|
|
+// CFRelease(path);
|
|
|
|
|
+// // CGPDFCONTEXTCREATE
|
|
|
//
|
|
//
|
|
|
|
|
+//
|
|
|
|
|
+// CGContextRef pdfContext;
|
|
|
|
|
+// CGRect docsize = CGRectMake(0, 0, 100, 100);
|
|
|
//
|
|
//
|
|
|
//
|
|
//
|
|
|
|
|
+//// if(name.length==0)
|
|
|
|
|
+//// {
|
|
|
|
|
+//// name=@"Helvetica";
|
|
|
|
|
+//// // name=@"DejaVu Sans";
|
|
|
|
|
+//// }
|
|
|
|
|
+//// if(size==0)
|
|
|
|
|
+//// {
|
|
|
|
|
+//// size=10;
|
|
|
|
|
+//// }
|
|
|
|
|
+//// NSString* style = @"Regular";
|
|
|
|
|
+//// if(bold)
|
|
|
|
|
+//// style=@"Bold";
|
|
|
|
|
+////
|
|
|
|
|
+//// //name=@"Courier";
|
|
|
|
|
+//
|
|
|
|
|
+//// NSDictionary *PDFAttributes =
|
|
|
|
|
+//// [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
|
+//// @"usai2010", (NSString *)kCGPDFContextOwnerPassword,
|
|
|
|
|
+//// kCFBooleanTrue, (NSString *)kCGPDFContextAllowsPrinting,
|
|
|
|
|
+//// kCFBooleanFalse, (NSString *)kCGPDFContextAllowsCopying,
|
|
|
|
|
+//// nil];
|
|
|
|
|
+//// // Create a descriptor.
|
|
|
|
|
+//// CFDictionaryRef cfpdfAttributes =(__bridge CFDictionaryRef)(PDFAttributes);
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// // CFBridgingRelease(cfpdfAttributes);
|
|
|
|
|
+//// pdfContext=CGPDFContextCreateWithURL(url, &docsize,cfpdfAttributes);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// CFMutableDictionaryRef myDictionary = NULL;
|
|
|
|
|
+// //文档信息字典
|
|
|
|
|
+//// myDictionary = CFDictionaryCreateMutable(NULL, 0,
|
|
|
|
|
+//// &kCFTypeDictionaryKeyCallBacks,
|
|
|
|
|
+//// &kCFTypeDictionaryValueCallBacks);
|
|
|
|
|
+////
|
|
|
|
|
+////// CFStringRef password = (__bridge CFStringRef)@"usai2010";
|
|
|
|
|
+////// CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, password);
|
|
|
|
|
+////
|
|
|
|
|
+//// CFDictionarySetValue(myDictionary, kCGPDFContextCreator, CFSTR("My Name"));
|
|
|
|
|
+////
|
|
|
|
|
+//////
|
|
|
|
|
+//// CFDictionarySetValue(myDictionary, kCGPDFContextOwnerPassword, CFSTR("usai2010"));
|
|
|
|
|
+//////
|
|
|
|
|
+////
|
|
|
|
|
+//// CFDictionarySetValue(myDictionary, kCGPDFContextTitle, CFSTR("My PDF File"));
|
|
|
|
|
+//// CFDictionarySetValue(myDictionary, kCGPDFContextAllowsPrinting, kCFBooleanTrue);
|
|
|
|
|
+//// CFDictionarySetValue(myDictionary, kCGPDFContextAllowsCopying, kCFBooleanFalse);
|
|
|
|
|
+//
|
|
|
|
|
+// //创建文档
|
|
|
|
|
+// pdfContext = CGPDFContextCreateWithURL (url, &docsize, NULL);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// size_t page_count=CGPDFDocumentGetNumberOfPages(document);
|
|
|
|
|
+// for(int i=1;i<=page_count;i++)
|
|
|
|
|
+// {
|
|
|
|
|
+// NSMutableDictionary* page_control=controlTemplate[[NSString stringWithFormat:@"page_%d",i-1]];
|
|
|
|
|
+// CGPDFPageRef page= CGPDFDocumentGetPage (document , i);
|
|
|
|
|
+//
|
|
|
|
|
+// CGRect papersize=CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// CGContextBeginPage(pdfContext, &papersize);
|
|
|
|
|
+//
|
|
|
|
|
+// PDFPage* pdfPage = [[PDFPage alloc] init:nil size:papersize];
|
|
|
|
|
+//
|
|
|
|
|
+// [pdfPage DirectDraw:pdfContext page:page];
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// for(int j=0;j<[page_control[@"count"] intValue];j++)
|
|
|
|
|
+// {
|
|
|
|
|
+// NSMutableDictionary* control=page_control[[NSString stringWithFormat:@"control_%d",j]];
|
|
|
|
|
+//
|
|
|
|
|
+// PDFDrawable * control_drawable = nil;
|
|
|
|
|
+// CGRect control_rect = CGRectMake([control[@"pos_x"] floatValue], [control[@"pos_y"] floatValue], [control[@"width"] floatValue], [control[@"height"] floatValue]);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// NSString* control_type = control[@"type"];
|
|
|
|
|
+// if([control_type isEqualToString:@"Signature"]||[control_type isEqualToString:@"Image"])
|
|
|
|
|
+// {
|
|
|
|
|
+//
|
|
|
|
|
+// NSString* value = control[@"value"];
|
|
|
|
|
+// if(value.length==0)
|
|
|
|
|
+// continue;
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// 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"];
|
|
|
|
|
+// }
|
|
|
|
|
+// else if([control_type isEqualToString:@"TextView"]||[control_type isEqualToString:@"Label"]||[control_type isEqualToString:@"DatePicker"])
|
|
|
|
|
+// {
|
|
|
|
|
+//
|
|
|
|
|
+// NSString* value = control[@"value"];
|
|
|
|
|
+// if(value.length==0)
|
|
|
|
|
+// continue;
|
|
|
|
|
+// NSString* size = control[@"size"];
|
|
|
|
|
+// if(size.length==0)
|
|
|
|
|
+// size=@"10";
|
|
|
|
|
+// NSString* textAlignment=control[@"textAlignment"];
|
|
|
|
|
+// if(textAlignment.length==0)
|
|
|
|
|
+// textAlignment = @"Center";
|
|
|
|
|
+// double margin_left = [control[@"margin_left"] doubleValue];
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// 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];
|
|
|
|
|
+//
|
|
|
|
|
+// [control_drawable setMargin_left:margin_left];
|
|
|
|
|
+// }
|
|
|
|
|
+// else if([control_type isEqualToString:@"Check"])
|
|
|
|
|
+// {
|
|
|
|
|
+// NSArray* value = control[@"value"];
|
|
|
|
|
+// if(value.count==0)
|
|
|
|
|
+// continue;
|
|
|
|
|
+// NSArray* cadedate = control[@"cadedate"];
|
|
|
|
|
+// float marker_size = [control[@"marker_size"] floatValue];
|
|
|
|
|
+//
|
|
|
|
|
+// for(int c=0;c<value.count;c++)
|
|
|
|
|
+// {
|
|
|
|
|
+// NSArray* marker=cadedate[[value[c] intValue]];
|
|
|
|
|
+// if(marker.count>=3)
|
|
|
|
|
+// {
|
|
|
|
|
+// NSString* value = marker[0][0];
|
|
|
|
|
+// if(value.length==0)
|
|
|
|
|
+// continue;
|
|
|
|
|
+// NSString* size = control[@"size"];
|
|
|
|
|
+// if(size.length==0)
|
|
|
|
|
+// size=@"10";
|
|
|
|
|
+//
|
|
|
|
|
+// 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];
|
|
|
|
|
+// }
|
|
|
|
|
+// else
|
|
|
|
|
+// {
|
|
|
|
|
+// CGRect marker_rect= CGRectMake([marker[1][0] floatValue] ,[marker[1][1] floatValue], marker_size, marker_size);
|
|
|
|
|
+// PDFDrawable * marker_drawable = [[RectDrawable alloc] init:[self WindowRect2PDFRect:marker_rect pdf_rect:papersize window_size:window_rect.size] color:@"0x000000"];
|
|
|
|
|
+// if(marker_drawable)
|
|
|
|
|
+// [pdfPage DirectDraw:pdfContext drawable:marker_drawable];
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//
|
|
|
|
|
+//// NSString* size = control[@"size"];
|
|
|
|
|
+//// if(size.length==0)
|
|
|
|
|
+//// size=@"10";
|
|
|
|
|
+////
|
|
|
|
|
+//// 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];
|
|
|
|
|
+// }
|
|
|
|
|
+// if(control_drawable)
|
|
|
|
|
+//// for(int l=0;l<100;l++)
|
|
|
|
|
+// [pdfPage DirectDraw:pdfContext drawable:control_drawable];
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+//// NSMutableDictionary* tline1= [LineDrawable createlineTemplate:1 from:CGPointMake(20, 20) to:CGPointMake(500,500)];
|
|
|
|
|
+//// LineDrawable* line1=nil;
|
|
|
|
|
+//// line1= [[LineDrawable alloc] init:tline1];
|
|
|
|
|
+////
|
|
|
|
|
+//// [pdfPage DirectDraw:pdfContext drawable:line1];
|
|
|
|
|
+//// NSRange range = NSMakeRange(0,9999);
|
|
|
|
|
+//// [line1 Draw:pdfContext dataSource:nil ParentRect:papersize startX:0 startY:0 flipHeight:0 range:range];
|
|
|
|
|
+//
|
|
|
|
|
+// CGContextEndPage(pdfContext);
|
|
|
|
|
+//
|
|
|
|
|
+// // [pdfPage Draw:pdfContext dataSource:nil];
|
|
|
|
|
+//// [self drawPage:pdfContext template:page size:papersize dataSource:data];
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+//// CFBridgingRelease(page);
|
|
|
|
|
+// }
|
|
|
// CGContextRelease(pdfContext);
|
|
// CGContextRelease(pdfContext);
|
|
|
-
|
|
|
|
|
- return newFilePath;
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
|
|
+// CFRelease(url);
|
|
|
|
|
+// // CFRelease(myDictionary);
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// // CFRelease(cfpdfAttributes);
|
|
|
|
|
+//// //开始画pdf
|
|
|
|
|
+////
|
|
|
|
|
+//// // NSString *temtext=[[NSString alloc]init];
|
|
|
|
|
+//// //
|
|
|
|
|
+//// // const char *text=(char *)[temtext UTF8String];
|
|
|
|
|
+//// //
|
|
|
|
|
+//// // int width;
|
|
|
|
|
+//// //
|
|
|
|
|
+//// // int height;
|
|
|
|
|
+//// //
|
|
|
|
|
+////
|
|
|
|
|
+//// // [self newpage:pdfContext size:papersize];
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+////
|
|
|
|
|
+//// CGContextRelease(pdfContext);
|
|
|
|
|
+//
|
|
|
|
|
+// return newFilePath;
|
|
|
|
|
+//
|
|
|
|
|
+//}
|
|
|
|
|
|
|
|
@end
|
|
@end
|