|
|
@@ -8,7 +8,7 @@
|
|
|
|
|
|
#import "PDFUtils.h"
|
|
|
#import "PDFPage.h"
|
|
|
-#import "LineDrawable.h"
|
|
|
+#import "ImageDrawable.h"
|
|
|
|
|
|
@implementation PDFUtils
|
|
|
+(NSString*) addSignature :(UIImage*) img to:(NSMutableDictionary*)signatureData
|
|
|
@@ -131,7 +131,7 @@
|
|
|
}
|
|
|
|
|
|
|
|
|
-+(void)SavePDF:(NSMutableDictionary*) controlTemplate source:(CGPDFDocumentRef )document
|
|
|
++(void)SavePDF:(NSMutableDictionary*) controlTemplate source:(CGPDFDocumentRef )document window_rect:(CGRect)window_rect
|
|
|
{
|
|
|
|
|
|
//获取路径
|
|
|
@@ -172,16 +172,17 @@
|
|
|
// CGPDFCONTEXTCREATE
|
|
|
|
|
|
|
|
|
-
|
|
|
+ CGContextRef pdfContext;
|
|
|
+ CGRect docsize = CGRectMake(0, 0, 100, 100);
|
|
|
+ pdfContext=CGPDFContextCreateWithURL(url, &docsize, nil);
|
|
|
size_t page_count=CGPDFDocumentGetNumberOfPages(document);
|
|
|
for(int i=1;i<=page_count;i++)
|
|
|
{
|
|
|
- // NSMutableDictionary* page=pages[[ NSString stringWithFormat:@"page_%d",i ] ];
|
|
|
- CGPDFPageRef page= CGPDFDocumentGetPage (document , 1);
|
|
|
+ NSMutableDictionary* page_control=controlTemplate[[NSString stringWithFormat:@"page_%d",i]];
|
|
|
+ CGPDFPageRef page= CGPDFDocumentGetPage (document , i);
|
|
|
|
|
|
CGRect papersize=CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
|
|
|
- CGContextRef pdfContext;
|
|
|
- pdfContext=CGPDFContextCreateWithURL(url, &papersize, nil);
|
|
|
+
|
|
|
|
|
|
|
|
|
CGContextBeginPage(pdfContext, &papersize);
|
|
|
@@ -191,21 +192,39 @@
|
|
|
[pdfPage DirectDraw:pdfContext page:page];
|
|
|
|
|
|
|
|
|
-
|
|
|
- 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];
|
|
|
+ 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"])
|
|
|
+ {
|
|
|
+ NSString* value = control[@"value"];
|
|
|
+ if(value.length==0)
|
|
|
+ continue;
|
|
|
+ control_drawable=[[ImageDrawable alloc] init:control_rect source_type:@"local" source:value hAlign:@"center" vAlign:@"middle"];
|
|
|
+ }
|
|
|
+ if(control_drawable)
|
|
|
+ [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);
|
|
|
- CGContextRelease(pdfContext);
|
|
|
+
|
|
|
// [pdfPage Draw:pdfContext dataSource:nil];
|
|
|
// [self drawPage:pdfContext template:page size:papersize dataSource:data];
|
|
|
}
|
|
|
-
|
|
|
+ CGContextRelease(pdfContext);
|
|
|
CFBridgingRelease(url);
|
|
|
// //开始画pdf
|
|
|
//
|