public FlowDocument CreateFlowDocumentReport(ReportDefinition rd, ReportData rData) { int pageWidth = (int)XpsPrintHelper.GetImagebleWidth(); //700;//just for testing !! get it from your printer FlowDocument fd = new FlowDocument(); fd.ColumnWidth = pageWidth; fd.Blocks.Add(createReportPart <Section>(rd.HeaderTemplate, rData.ReportGroup)); TableRowGroup trg = new TableRowGroup(); for (int i = 0; i < rData.Groups.Count; i++) { addGroup(rd, trg, rData.Groups[i], rData.Rows); } MemoryStream tableStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(rd.TableDefinition)); Table table = (Table)XamlReader.Load(tableStream, XamlContext); table.RowGroups.Add(trg); fd.Blocks.Add(table); fd.Blocks.Add(createReportPart <Section>(rd.FooterTemplate, rData.ReportGroup)); //return ReportPaginator.CreateXpsDocument(fd, rd.Page); // Open the file that contains the FlowDocument... // FileStream xamlFile = new FileStream("../Debug/Data/SalesSummaryReport", FileMode.Open, FileAccess.Read); // and parse the file with the XamlReader.Load method. // FlowDocument fd = XamlReader.Load(xamlFile) as FlowDocument; // xamlFile.Close(); return(fd); }
public XpsDocument CreateReport(ReportDefinition rd, ReportData rData) { //int pageWidth = 700;//just for testing !! get it from your printer int pageWidth = (int)XpsPrintHelper.GetImagebleWidth(); //XpsPrintHelper.GetPageWidth(); FlowDocument fd = new FlowDocument(); fd.Name = rd.ReportName; fd.ColumnWidth = pageWidth; fd.Blocks.Add(createReportPart <Section>(rd.HeaderTemplate, rData.ReportGroup)); TableRowGroup trg = new TableRowGroup(); for (int i = 0; i < rData.Groups.Count; i++) { addGroup(rd, trg, rData.Groups[i], rData.Rows); } MemoryStream tableStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(rd.TableDefinition)); Table table = (Table)XamlReader.Load(tableStream, XamlContext); table.RowGroups.Add(trg); fd.Blocks.Add(table); fd.Blocks.Add(createReportPart <Section>(rd.FooterTemplate, rData.ReportGroup)); return(ReportPaginator.CreateXpsDocument(fd, rd.Page)); }
public XpsDocument CreateLabels(List <WPFBarcode> listBarcode, int numberAcross, int numberDown, double topMargin, double sideMargin) { //int pageWidth = 700;//just for testing !! get it from your printer int pageWidth = (int)XpsPrintHelper.GetImagebleWidth(); //XpsPrintHelper.GetPageWidth(); FlowDocument fd = new FlowDocument(); fd.ColumnWidth = pageWidth; //pageWidth-2*sideMargin*96; Table table1 = new Table(); // ...and add it to the FlowDocument Blocks collection. fd.Blocks.Add(table1); // Set some global formatting properties for the table. table1.CellSpacing = 0; // table1.to // Create columns and add them to the table's Columns collection. /// Create a local print server double colWidth = (pageWidth - 2 * sideMargin * 96) / numberAcross; for (int x = 0; x < numberAcross; x++) { TableColumn tcol = new TableColumn(); tcol.Width = new GridLength(colWidth); table1.Columns.Add(tcol); //For debuging only // Set alternating background colors for the middle colums. // if (x % 2 == 0) // table1.Columns[x].Background = Brushes.Beige; // else // table1.Columns[x].Background = Brushes.LightSteelBlue; } int row = -1; int col = numberAcross + 1; // Create and add an empty TableRowGroup to hold the table's Rows. table1.RowGroups.Add(new TableRowGroup()); foreach (WPFBarcode b in listBarcode) { // Add the first (title) row. if (col >= numberAcross) { row++; table1.RowGroups[0].Rows.Add(new TableRow()); col = 0; } // Alias the current working row for easy reference. TableRow currentRow = table1.RowGroups[0].Rows[row]; // Add the header row with content, try { Image img = b.Encode(); TableCell tableCell = new TableCell(new BlockUIContainer(img)); //TableCell tableCell = new TableCell(new BlockUIContainer(b.Generate_vector_image_canvas())); currentRow.Cells.Add(tableCell); //tableCell.BorderBrush = Brushes.Red; //tableCell.BorderThickness = new Thickness(.5); } catch (Exception e) { MessageBox.Show(e.ToString()); break; } col++; } PageDefinition pd = new PageDefinition(); pd.FooterHeight = 0; pd.Margin = new Size(sideMargin * 96, topMargin * 96); pd.HeaderHeight = 0; return(ReportPaginator.CreateXpsDocument(fd, pd)); }