5
मैं निम्नलिखित कोड की मदद से पीडीएफ/छवि के लिए एक UIWebView परिवर्तित कर रहा हूँ:पीडीएफ/छवि के लिए एक UIWebView परिवर्तित कर देता है केवल एक इंच चौड़ी उत्पादन
NSString *heightStr = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
int height = [heightStr intValue];
CGFloat screenHeight = webView.bounds.size.height;
int pages = ceil(height/screenHeight);
NSMutableData *pdfData = [NSMutableData data];
UIGraphicsBeginPDFContextToData(pdfData, webView.bounds, nil);
CGRect frame = [webView frame];
NSMutableArray *imageArray= [[NSMutableArray alloc]init];
for (int i = 0; i < pages; i++)
{
// Check to screenHeight if page draws more than the height of the UIWebView
if ((i+1) * screenHeight > height)
{
CGRect f = [webView frame];
f.size.height -= (((i+1) * screenHeight) - height);
[webView setFrame: f];
}
UIGraphicsBeginImageContext(frame.size);
UIGraphicsBeginPDFPage();
CGContextRef currentContext = UIGraphicsGetCurrentContext();
//CGContextTranslateCTM(currentContext, 72, 72); // Translate for 1" margins
[[[webView subviews] lastObject] setContentOffset:CGPointMake(0, screenHeight * i) animated:NO];
[webView.layer renderInContext:currentContext];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
[imageArray insertObject:viewImage atIndex:imageArray.count] ;
UIGraphicsEndImageContext();
}
UIGraphicsEndPDFContext();
[webView setFrame:frame];
//Send all images
NSData *imgData = [self blendImages:imageArray];
//Final Image
UIImage *finalImage = [UIImage imageWithData:imgData];
-(NSData*)blendImages:(NSMutableArray *)arrImage{
// get data from document
CGFloat height=0 ,width=0 ;
UIImage *tempImg = [arrImage objectAtIndex:0] ;
width =tempImg.size.width ;
for (int i = 0 ; i<arrImage.count ; i++){
UIImage *img= [arrImage objectAtIndex:i];
height = img.size.height +height;
}
CGSize size = CGSizeMake(width, height) ;
UIGraphicsBeginImageContext(size);
CGFloat h = 0;
for (int i=0; i<arrImage.count; i++) {
UIImage* uiimage = [arrImage objectAtIndex:i];
[uiimage drawAtPoint:CGPointMake(0, h) blendMode:kCGBlendModeNormal alpha:1.0];
h = uiimage.size.height +h ;
}
NSData *imageData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
UIGraphicsEndImageContext();
return imageData;
}
लेकिन मैं केवल एक इंच चौड़ी हो रही है उत्पादन। इसके अलावा पूरे पृष्ठ में एक पृष्ठ में फिट बैठता है और इसे अपठनीय बना देता है। ए 4 आकार का आउटपुट कैसे बनाएं?
मैं अपने कोड के साथ एक सा खेला है। यह मेरे लिए अस्पष्ट है कि आप क्या हासिल करने की कोशिश कर रहे हैं। क्या आप एकाधिक पृष्ठों के साथ पीडीएफ बनाना चाहते हैं, प्रत्येक पृष्ठ ए 4 आकार? या आप पूरे वेब पेज से एकल छवि बनाने की कोशिश कर रहे हैं, जैसे आपका कोड वर्तमान में व्यवहार करता है, लेकिन परिणाम आकार बदलता है? –
@ बोरीस वेरेब्स्की: मैं एकाधिक पृष्ठों के साथ बनाना चाहता हूं। – Poles