|
@@ -9,6 +9,9 @@
|
|
|
#import "PDFUtils.h"
|
|
#import "PDFUtils.h"
|
|
|
#import "PDFPage.h"
|
|
#import "PDFPage.h"
|
|
|
#import "ImageDrawable.h"
|
|
#import "ImageDrawable.h"
|
|
|
|
|
+#import "TextDrawable.h"
|
|
|
|
|
+#import "RectDrawable.h"
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@implementation PDFUtils
|
|
@implementation PDFUtils
|
|
|
+(NSString*) addSignature :(UIImage*) img to:(NSMutableDictionary*)signatureData
|
|
+(NSString*) addSignature :(UIImage*) img to:(NSMutableDictionary*)signatureData
|
|
@@ -129,7 +132,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
++(CGRect)WindowRect2PDFRect:(CGRect)rect pdf_rect:(CGRect)pdf_rect window_size:(CGSize)window_size
|
|
|
|
|
+{
|
|
|
|
|
+ CGRect pdf_expand;
|
|
|
|
|
+ float offset_x = 0;
|
|
|
|
|
+ float offset_y = 0;
|
|
|
|
|
+ float scale =1;
|
|
|
|
|
+ if(pdf_rect.size.height>=pdf_rect.size.width)
|
|
|
|
|
+ {
|
|
|
|
|
+ pdf_expand = CGRectMake(0, 0, pdf_rect.size.height*window_size.width/window_size.height, pdf_rect.size.height);
|
|
|
|
|
+ offset_x = (pdf_expand.size.width-pdf_rect.size.width)/2;
|
|
|
|
|
+ scale = pdf_rect.size.height/window_size.height;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ pdf_expand = CGRectMake(0, 0, pdf_rect.size.width, pdf_rect.size.width*window_size.height/window_size.width);
|
|
|
|
|
+ offset_y = (pdf_expand.size.height-pdf_rect.size.height)/2;
|
|
|
|
|
+ scale = pdf_rect.size.width/window_size.width;
|
|
|
|
|
+ }
|
|
|
|
|
+ float x=rect.origin.x*scale-offset_x;
|
|
|
|
|
+ float y=rect.origin.y*scale-offset_y;
|
|
|
|
|
+ float width = rect.size.width*scale;
|
|
|
|
|
+ float height = rect.size.height*scale;
|
|
|
|
|
+
|
|
|
|
|
+ return CGRectMake(x, y, width, height);
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
+(void)SavePDF:(NSMutableDictionary*) controlTemplate source:(CGPDFDocumentRef )document window_rect:(CGRect)window_rect
|
|
+(void)SavePDF:(NSMutableDictionary*) controlTemplate source:(CGPDFDocumentRef )document window_rect:(CGRect)window_rect
|
|
|
{
|
|
{
|
|
@@ -178,7 +207,7 @@
|
|
|
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]];
|
|
|
|
|
|
|
+ NSMutableDictionary* page_control=controlTemplate[[NSString stringWithFormat:@"page_%d",i-1]];
|
|
|
CGPDFPageRef page= CGPDFDocumentGetPage (document , i);
|
|
CGPDFPageRef page= CGPDFDocumentGetPage (document , i);
|
|
|
|
|
|
|
|
CGRect papersize=CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
|
|
CGRect papersize=CGPDFPageGetBoxRect(page, kCGPDFMediaBox);
|
|
@@ -206,7 +235,43 @@
|
|
|
NSString* value = control[@"value"];
|
|
NSString* value = control[@"value"];
|
|
|
if(value.length==0)
|
|
if(value.length==0)
|
|
|
continue;
|
|
continue;
|
|
|
- control_drawable=[[ImageDrawable alloc] init:control_rect source_type:@"local" source:value hAlign:@"center" vAlign:@"middle"];
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ 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"])
|
|
|
|
|
+ {
|
|
|
|
|
+ NSString* value = control[@"value"];
|
|
|
|
|
+ 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 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]];
|
|
|
|
|
+ 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)
|
|
if(control_drawable)
|
|
|
[pdfPage DirectDraw:pdfContext drawable:control_drawable];
|
|
[pdfPage DirectDraw:pdfContext drawable:control_drawable];
|