Pdf生成用于动态数据

时间:2011-10-31 12:01:55

标签: iphone objective-c ios pdf-generation

在生成pdf时,会创建一个新页面,但数据不会写入pdf,这是我正在使用的代码,请帮我解决这个问题:

               x=50;
                y=y-20;
                BOOL isNewPageReq=FALSE;
                for(int trLisCnt=2;trLisCnt<=4;trLisCnt++){
                    NSMutableArray *tranListingContArray=[eachSkuAry objectAtIndex:trLisCnt];
                    for(int dicCnt=0;dicCnt<[tranListingContArray count];dicCnt++){
                        NSMutableArray *actContents=[tranListingContArray objectAtIndex:dicCnt];
                        y=y-10;
                        if(y<=40){ //here i am checking the y position
                            y=700;//here i am setting y position for the new page
                            CGContextEndPage(pdfContext);//here i am ending the current page
                            CGContextBeginPage(pdfContext, &pageRect);/*here i am starting a new page,i am ending this                                                     page at end not shown in this*/
                        }
                        x=50;
                        for(int j=0;j<7;j++){
                            if((j==0)&&(trLisCnt==2)){
                                const char *str=[@"SO" UTF8String];
                                CGContextShowTextAtPoint(pdfContext,x,y,str,strlen(str));
                                x=x+50;
                            }
                            else if((j==1)&&(trLisCnt==2)){
                                const char *cont=[[actContents objectAtIndex:3]UTF8String];
                                CGContextShowTextAtPoint(pdfContext,x,y,cont,strlen(cont));
                                x=x+50;

                            }
                            else if((j==2)&&(trLisCnt==2)){
                                const char *cont=[[actContents objectAtIndex:1]UTF8String];
                                CGContextShowTextAtPoint(pdfContext,x,y,cont,strlen(cont));
                                x=x+50;
                            }
                            else if((j==3)&&(trLisCnt==2)){
                                const char *cont=[@"NULL" UTF8String];
                                CGContextShowTextAtPoint(pdfContext,x,y,cont,strlen(cont));
                                x=x+110;
                            }
                            else if((j==4)&&(trLisCnt==2)){
                                const char *cont=[@"NULL" UTF8String];
                                CGContextShowTextAtPoint(pdfContext,x,y,cont,strlen(cont));
                                x=x+110;
                            }
                            else if((j==5)&&(trLisCnt==2)){
                                const char *cont=[@"NULL" UTF8String];
                                CGContextShowTextAtPoint(pdfContext,x,y,cont,strlen(cont));
                                x=x+110;
                            }
                            else if((j==6)&&(trLisCnt==2)){
                                const char *cont=[[actContents objectAtIndex:2]UTF8String];
                                CGContextShowTextAtPoint(pdfContext,x,y,cont,strlen(cont));
                                x=x+50;
                            }
}
}

1 个答案:

答案 0 :(得分:1)

您需要设置字体和颜色......

CGContextSelectFont (pdfContext, "Helvetica", 14, kCGEncodingMacRoman);
CGContextSetTextDrawingMode (pdfContext, kCGTextFill);
CGContextSetRGBFillColor (pdfContext, 0, 0, 0, 1);
相关问题