我正在创建pdf表单uiwebview webview heiht是29649或更高或更低我正在检查uiwebview高度并采取适当的必要宽度我只得到pdf的ome部分并且剩下的所有页面都是空白
//in the mac it is working fine but in the iphone only some part of the data is only coming
help me.... please
我的代码是
if ([tmpview isKindOfClass:[UIWebView class]])
{
UIWebView *tmp = (UIWebView *)tmpview;
tmp.hidden = NO;
output = [tmp stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
if (tmp.tag == 1001) {
for (id subview in tmp.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]]) {
UIScrollView *sv1 = (UIScrollView*) subview;
CGFloat scrollViewHeight = 0.0f;
CGFloat scrollViewWidth = 0.0f;
UIView *tmp_view;
for (UIImageView* view in sv1.subviews) {
if([view isKindOfClass:[UIImageView class]]) {
view.backgroundColor = [UIColor yellowColor];
[view removeFromSuperview];
} else { }
tmp_view = view;
CGFloat y = view.frame.origin.y;
CGFloat h = view.frame.size.height;
CGFloat x = view.frame.origin.x;
CGFloat w = view.frame.size.width;
if (y + h > scrollViewHeight) {
scrollViewHeight = h + y;
}
if (x + w > scrollViewWidth) {
scrollViewWidth = w + x;
}
}
if(scrollViewWidth < 816) {
scrollViewWidth = 816;
}
sv1.frame = CGRectMake(0, 0, scrollViewWidth, scrollViewHeight);
NSLog(@"%f",scrollViewWidth);
NSLog(@"%f",scrollViewHeight);
NSLog(@"%f",tmp.frame.size.width);
tmp.frame = CGRectMake(0, 0, tmp.frame.size.width, scrollViewHeight);
if (scrollViewHeight > 4210.0) {
cnt = (int)ceil(scrollViewHeight/4210.0);
} else {
cnt = 1;
}
for (int i = 0,j=0; j<cnt; i++,j++)
{
NSLog(@"%f",scrollViewHeight);
NSLog(@"%f",scrollViewWidth);
NSLog(@"%f",scrollViewHeight);
NSLog(@"%f",tmp.frame.size.width);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *directroyPath = nil;
NSString *filepathpdf = @"/";
filepathpdf = [filepathpdf stringByAppendingString:[NSString stringWithFormat:@"%d.pdf",(i+1)]];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:filepathpdf];
// check for the "PDF" directory
NSError *error;
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
} else {
[[NSFileManager defaultManager] createDirectoryAtPath:directroyPath
withIntermediateDirectories:NO
attributes:nil
error:&error];
}
//scrolview height
CGRect S = CGRectMake(0,0, scrollViewWidth, (i+1)*4210);
CGContextRef pdfContext = [self createPDFContext:S path:(CFStringRef)filePath];
CGRect pageRect = CGRectMake(0, 0, scrollViewWidth, 4210);
NSAutoreleasePool *pppp = [[NSAutoreleasePool alloc] init];
// page 1
CGContextBeginPage (pdfContext,&pageRect);
//turn PDF upsidedown
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(0, (i+1)*4210);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
CGContextConcatCTM(pdfContext, transform);
[sv1.layer renderInContext:pdfContext];
CGContextEndPage (pdfContext);
// CGContextFlush(pdfContext);
[sv1 setContentOffset:CGPointMake(0, (i+1) * 4210) animated:NO];
CGContextRelease (pdfContext);
[pppp release];
}
//scrollViewWidth = 0.0;
}
}
}
}
//for pdf creating using media box i am using this
+(CGContextRef) createPDFContext:(CGRect)inMediaBox path:(CFStringRef) path
{
CGContextRef myOutContext = NULL;
CFURLRef url;
url = CFURLCreateWithFileSystemPath (NULL, path,
kCFURLPOSIXPathStyle,
false);
if (url != NULL) {
myOutContext = CGPDFContextCreateWithURL (url,
&inMediaBox,
NULL);
CFRelease(url);
}
return myOutContext;
}