Tôi đang cố gắng vẽ nội dung của scrollview
vào một ngữ cảnh PDF
& Tôi đang gặp sự cố với pagination
.Vẽ Contex + Phân trang
Tiếp theo Mã Tôi đã sử dụng:
- (void)renderTheView:(UIView *)view inPDFContext:(CGContextRef)pdfContext
{
// Creating frame.
CGFloat heightOfPdf = [[[self attributes] objectForKey:SRCPdfHeight] floatValue];
CGFloat widthOfPdf = [[[self attributes] objectForKey:SRCPdfWidth] floatValue];
CGRect pdfFrame = CGRectMake(0, 0, widthOfPdf, heightOfPdf);
CGRect viewFrame = [view frame];
if ([view isKindOfClass:[UIScrollView class]])
{
viewFrame.size.height = ((UIScrollView *)view).contentSize.height;
[view setFrame:viewFrame];
}
// Calculates number of pages.
NSUInteger totalNumberOfPages = ceil(viewFrame.size.height/heightOfPdf);
// Start rendering.
for (NSUInteger pageNumber = 0; pageNumber<totalNumberOfPages; pageNumber++)
{
// Starts our first page.
CGContextBeginPage (pdfContext, &pdfFrame);
// Turn PDF upsidedown
CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformMakeTranslation(0,view.bounds.size.height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
CGContextConcatCTM(pdfContext, transform);
// Calculate amount of y to be displace.
CGFloat ty = (heightOfPdf*(pageNumber));
CGContextTranslateCTM(pdfContext,0,-ty);
[view.layer renderInContext:pdfContext];
// We are done drawing to this page, let's end it.
CGContextEndPage (pdfContext);
}
}
Nó tạo ra số lượng yêu cầu của trang nhưng đặt nội dung sai. Hình sau giải thích nó.
Có điều gì sai trong mã của tôi không?
không may mắn với điều này? – Magnus
Tò mò về cách mọi thứ hoạt động nếu bạn chọn chế độ xem phụ của mình trong ScrollView? – bentford
Các phần u cần thêm vào các trang pdf đặt trong các khung nhìn riêng biệt bên trong cuộn và hiển thị chế độ xem theo ngữ cảnh pdf –