# データバインダー 与えられた配列を別データに変換(データバインド)するための仕組みについて説明する。 PicoPDFでは配列をヘッダー、フッターを追加したセクションモデルに変換する。 ## データバインド 要素からBind名のプロパティをバインドして表示する。 {: data-filename="example.json"} ```json { "Sections": [ {"Type": "DetailSection", "Name": "Detail", "Height": 50, "Elements": [ {"Type": "BindElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0}, {"Type": "BindElement", "Bind": "Bar", "Size": 30, "X": 10, "Y": 0}, {"Type": "BindElement", "Bind": "Baz", "Size": 30, "X": 10, "Y": 0}, ]}, ], } ``` プロパティはgetを持つ必要がある。 {: data-filename="Sample.cs"} ```cs var datas = new Data[] { new Data { Foo = 1, Bar = "abc", Baz = 123.5f }, new Data { Foo = 2, Bar = "def", Baz = 234.5f }, new Data { Foo = 3, Bar = "efg", Baz = 345.5f }, }; PicoPDF.Pdf.PdfUtility.CreateDocument("example.json", datas).Save("example.pdf"); ``` ## データ集計 要素からBind名のプロパティをバインドして集計する。 {: data-filename="example.json"} ```json { "Detail": { "BreakKey": "Key", "Detail": "Detail", "Footer": "Footer", }, "Sections": [ {"Type": "DetailSection", "Name": "Detail", "Height": 50, "Elements": [ {"Type": "BindElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0}, {"Type": "BindElement", "Bind": "Key", "Size": 30, "X": 10, "Y": 0}, {"Type": "SummaryElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0, "SummaryType": "Summary", "SummaryMethod": "PageIncremental" }, {"Type": "SummaryElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0, "SummaryType": "Summary", "SummaryMethod": "GroupIncremental" }, {"Type": "SummaryElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0, "SummaryType": "Summary", "SummaryMethod": "CrossSectionPageIncremental" }, {"Type": "SummaryElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0, "SummaryType": "Summary", "SummaryMethod": "AllIncremental" }, ]}, {"Type": "FooterSection", "Name": "Footer", "Height": 50, "Elements": [ {"Type": "BindElement", "Bind": "Key", "Size": 30, "X": 10, "Y": 0}, {"Type": "SummaryElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0, "SummaryType": "Summary", "SummaryMethod": "Page" }, {"Type": "SummaryElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0, "SummaryType": "Summary", "SummaryMethod": "Group" }, {"Type": "SummaryElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0, "SummaryType": "Summary", "SummaryMethod": "CrossSectionPage" }, {"Type": "SummaryElement", "Bind": "Foo", "Size": 30, "X": 10, "Y": 0, "SummaryType": "Summary", "SummaryMethod": "All" }, ]}, ], } ``` グループ化するためにブレークキーが異なるように設定する。 {: data-filename="Sample.cs"} ```cs var datas = new Data[] { new Data { Foo = 1, Key = "A" }, new Data { Foo = 2, Key = "A" }, new Data { Foo = 3, Key = "A" }, new Data { Foo = 4, Key = "A" }, new Data { Foo = 5, Key = "A" }, new Data { Foo = 6, Key = "B" }, new Data { Foo = 7, Key = "B" }, }; PicoPDF.Pdf.PdfUtility.CreateDocument("example.json", datas).Save("example.pdf"); ``` 1ページ5行の場合次のように集計される。 | セクション | ページ | Foo | Key | PageIncremental | GroupIncremental | CrossSectionPageIncremental | AllIncremental | Page | Group | CrossSectionPage | All | |---------------|-------:|----:|-----|----------------:|-----------------:|----------------------------:|---------------:|-----:|------:|-----------------:|----:| | DetailSection | 1 | 1 | A | 1 | 1 | 1 | 1 | | | | | | DetailSection | 1 | 2 | A | 3 | 3 | 3 | 3 | | | | | | DetailSection | 1 | 3 | A | 6 | 6 | 6 | 6 | | | | | | DetailSection | 1 | 4 | A | 10 | 10 | 10 | 10 | | | | | | FooterSection | 1 | | A | | | | | 10 | 15 | 10 | 28 | | DetailSection | 2 | 5 | A | 5 | 15 | 5 | 15 | | | | | | FooterSection | 2 | | A | | | | | 5 | 15 | 18 | 28 | | DetailSection | 2 | 6 | B | 6 | 6 | 11 | 21 | | | | | | DetailSection | 2 | 7 | B | 13 | 13 | 18 | 28 | | | | | | FooterSection | 2 | | B | | | | | 13 | 13 | 18 | 28 | SummaryMethodは集計をクリアするタイミングに影響する。 非Incremental系は集計確定時に最終値に更新される。Incremental系はその時の値になる。 | SummaryMethod | クリアタイミング | |--------------------|--------------------------------------------------------| | Page系 | ページの切り替わり、グループの切り替わりでクリアされる | | Group系 | グループの切り替わりでクリアされる | | CrossSectionPage系 | ページの切り替わりでクリアされる | | All系 | クリアされない |