다중 페이지 PDF를 작성하려고합니다. 나는 이것을 따라 갔다 tutorial. 정적 텍스트 용 XIB 파일로 작업 한 다음 코드에서 테이블을 추가합니다. 하지만 ATM을 사용하는 데 문제가되는 것은 테이블이 커지면 한 페이지 큽니다. 테이블에 9 행 이상있을 때. 다음 페이지에서 계속 진행해야합니다.다중 페이지 PDF를 objective-c로 작성하십시오.
이것은 내가 코드에서 수행하고있는 작업입니다.
+(void)drawPDF:(NSString*)fileName
{
NSMutableDictionary *mutDictValues = [[[NSUserDefaults standardUserDefaults] objectForKey:@"dicValues"] mutableCopy];
NSMutableArray *arrSelectedCities = [[mutDictValues objectForKey:@"cities"]mutableCopy ];
if(arrSelectedCities.count <= 8){
// If there are only 8 rows --> we can fit everyting on one page !
// Create the PDF context using the default page size of 612 x 792.
UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, nil);
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
[self drawLabels];
[self drawLogo];
int xOrigin = 50;
int yOrigin = 350;
int rowHeight = 50;
int columnWidth = 240;
int numberOfRows = 9;
int numberOfColumns = 2;
[self drawTableAt:CGPointMake(xOrigin, yOrigin) withRowHeight:rowHeight andColumnWidth:columnWidth andRowCount:numberOfRows andColumnCount:numberOfColumns];
[self drawTableDataAt:CGPointMake(xOrigin, yOrigin) withRowHeight:rowHeight andColumnWidth:columnWidth andRowCount:numberOfRows andColumnCount:numberOfColumns withArray:arrSelectedCities];
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
}else{
// When we have more then 8 rows we should have 2 pages.
NSLog(@"Create 2 pages");
// Create the PDF context using the default page size of 612 x 792.
UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, nil);
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
[self drawLabels];
[self drawLogo];
int xOrigin = 50;
int yOrigin = 350;
int rowHeight = 50;
int columnWidth = 240;
int numberOfRows = 9;
int numberOfColumns = 2;
[self drawTableAt:CGPointMake(xOrigin, yOrigin) withRowHeight:rowHeight andColumnWidth:columnWidth andRowCount:numberOfRows andColumnCount:numberOfColumns];
[self drawTableDataAt:CGPointMake(xOrigin, yOrigin) withRowHeight:rowHeight andColumnWidth:columnWidth andRowCount:numberOfRows andColumnCount:numberOfColumns withArray:arrSelectedCities];
// Create the PDF context using the default page size of 612 x 792.
UIGraphicsBeginPDFContextToFile(fileName, CGRectZero, nil);
// Mark the beginning of a new page.
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
int xOrigin2 = 50;
int yOrigin2 = 60;
int numberOfRows2 = ((arrSelectedCities.count+1)-9);
[self drawTableAt:CGPointMake(xOrigin2, yOrigin2) withRowHeight:rowHeight andColumnWidth:columnWidth andRowCount:numberOfRows2 andColumnCount:numberOfColumns];
[self drawTableDataAt:CGPointMake(xOrigin2, yOrigin2) withRowHeight:rowHeight andColumnWidth:columnWidth andRowCount:numberOfRows2 andColumnCount:numberOfColumns withArray:arrSelectedCities];
}
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
}
내가 여기서하고있는 일을 설명하겠습니다. 내 tableview 채우기합니다 배열이 있습니다. 배열이 8보다 크면 2 페이지를 사용해야합니다. 다른 모든 것은 한 페이지로 작동합니다. 이, 그것은 단지 두 번째 페이지를 만드는 것입니다 무엇을
....
이아무도 나를 도와 드릴까요? 단지 UIGraphicsBeginPDFPageWithInfo()
두 번째 페이지를 만들 때 다시 UIGraphicsBeginPDFContextToFile()
를 호출해서는 안
를 사용! 고마워 친구 ! – Steaphann
일부 변경 사항은이 하나의 완벽한 다중 페이지 PDF를 생성하기 위해 일했습니다. 고마워. :) –