2014-01-08 84 views
1

我有数据来生成具有页眉页脚和内容的报告。IOS有一个报告生成器在PDF中生成

在内容有当每个组在页面区域的数据把它添加新的页面,写组和持续的内容数据

我在哪里可以LIB的头多组。或者做什么这个任务?

感谢您的提前。

添加请求的代码

NSArray *headObject = [uniqueStates allObjects];////Store head of each group 
    NSArray *detail; //Store all of data to present in table 

    int allData = [detail count]; // Tel amount of all data to show 
    /* 
    int headGroupline = 1; //Tel amount of head group line 
    int footGroupline = 1; //Tel amount of foot group line 
    */ 
    int detailIndex = 0; ///Tel what line we are now 
    int detailHeadIndex = 0; ///Tel what group we are now 
    int subdetail = 0; // Tel what line on group now 

    int aviableLineInpage = 24; // Line avilable in page for data to show 

    int allPage = 0; //Sum of all page 

    for (; detailIndex < allData;) { 
     allPage++; 
     for (int i=0; i < aviableLineInpage;) { 

      if (allData - detailIndex == 0) { 
       ///ShowgrandTotal 
       ........ 

       detailIndex++; 
       i+=25; 
      }else{ 
       if (i == 0) { 
        //Show Head Group 
        ...... 
       }else{ 
        if (subdetail == [[detail filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(buy_date == %@)", headObject[detailHeadIndex]]] count]+1) { 
         detailHeadIndex++; 
         //Show Head Group 
          .......... 
        }else{ 
         if (subdetail == [[detail filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(buy_date == %@)", headObject[detailHeadIndex]]] count]) { 
          //Show sum of each group 
           .......... 
          i++; 
          detailIndex++; 
          subdetail++; 
          detailHeadIndex++; 
         }else{ 
          //Show data of detail 
          ........................ 
          detailIndex++; 
          subdetail++; 
         } 
        } 
       } 
       i++; 
      } 

     }//for all line in page 
    }//for allData 

它的格式是:

日期27/01/2014
数据1
数据2
数据3
和日期27/01/2014

date 28/01/2014
data1
DATA2
< ============如果页面制动添加新的页面和

日期28/01/2014
数据3
和日期28/01/2014

总计........

而且走得

日期27/01/2014
数据1
数据2
数据3
和日期27/01/2014

数据1
数据2
< ============如果页面制动添加新的页面和

日期28/01/2014
数据3
总计........

非常感谢

+1

所以你想根据你的数据做一个pdf? – Retro

+0

是的我有一个数据@Retro – Peerax

+0

我已经使用coreGraphics生成了具有不同表格和不同行的动态页面pdf,所以你想要这样吗? – Retro

回答

0
int allData = [detail count]; // Tel amount of all data to show 
    /* 
    int headGroupline = 1; //Tel amount of head group line 
    int footGroupline = 1; //Tel amount of foot group line 
    */ 
    int detailIndex = 0; ///Tel what line we are now 
    int detailHeadIndex = 0; ///Tel what group we are now 
    int subdetail = 0; // Tel what line on group now 

    int aviableLineInpage = 24; // Line avilable in page for data to show 

    int allPage = 0; //Sum of all page 

    for (; detailIndex < allData;) { 
     allPage++; 
     for (int i=0; i < aviableLineInpage;) { 

      if (allData - detailIndex == 0) { 

       detailIndex++; 
       i+=25; 
      }else{ 
       if (i == 0) { 

        if (subdetail == -1) { 
         subdetail = 0; 
        } 
       }else{ 
        if (subdetail == -1) { 

         subdetail = 0; 
        }else{ 
         if (subdetail == [[detail filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(buy_date == %@)", headObject[detailHeadIndex]]] count]) { 

          i++; 

          subdetail = -1; 
          detailHeadIndex++; 
          if (detailHeadIndex == [headObject count]) { 
           detailIndex++; 
          } 
         }else{ 

          detailIndex++; 
          subdetail++; 
         } 
        } 
       } 
      i++; 
      } 

     }//for all line in page 
    }//for allData 
0

使用CGPDFDocumentRef和相关函数来创建PDF文档及其包含的每个页面。当您创建一个页面(UIGraphicsBeginPDFPageWithInfo)时,您可以获取关联的绘图上下文(UIGraphicsGetCurrentContext)。一旦你有,你可以在许多方面得出:

  1. 您可以创建您的页眉和页脚视图,添加内容,并呈现到视图(使用其层)
  2. 你可以绘制图像和文字直接到上下文(使用CoreText(CTFrameDraw))

您需要创建设置多少内容可以适应任何一个网页上的逻辑,当你需要创建一个新的页面。此外,根据您选择如何将内容绘制到上下文中,您可能需要对上下文进行缩放和变换(CGContextScaleCTM + CGContextTranslateCTM),以便您的内容不会颠倒。

参见this Apple guide

+0

谢谢但我可以创建它的PDF。 现在我将范围逻辑的代码范围创建为每个页面。 我在问题上发帖。 感谢您的帮助 – Peerax

+0

您需要具体描述出了什么问题...... – Wain

+0

它错了,它不会在我的最终结果 – Peerax