9 changed files with 574 additions and 55 deletions
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 03.05.2011 |
||||
* Time: 19:34 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.Drawing; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Documents; |
||||
|
||||
using ICSharpCode.Reports.Core; |
||||
using ICSharpCode.Reports.Core.BaseClasses; |
||||
using ICSharpCode.Reports.Core.Exporter; |
||||
using ICSharpCode.Reports.Core.Exporter.ExportRenderer; |
||||
using ICSharpCode.Reports.Core.Globals; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
|
||||
namespace ICSharpCode.Reports.Addin.Project.WPF |
||||
{ |
||||
/// <summary>
|
||||
/// Description of WPFReportPreview.
|
||||
/// </summary>
|
||||
public class WPFReportPreview: AbstractSecondaryViewContent |
||||
{ |
||||
ReportDesignerLoader designerLoader; |
||||
DocumentViewer viewer = new DocumentViewer(); |
||||
|
||||
public WPFReportPreview(ReportDesignerLoader loader,IViewContent content):base(content) |
||||
{ |
||||
this.designerLoader = loader; |
||||
base.TabPageText = "Wpf View"; |
||||
} |
||||
|
||||
protected override void LoadFromPrimary() |
||||
{ |
||||
Console.WriteLine("WPFReportPreview - LoadFromPrimary"); |
||||
ReportModel model = designerLoader.CreateRenderableModel(); |
||||
|
||||
IReportCreator reportCreator = FormPageBuilder.CreateInstance(model); |
||||
// reportCreator.SectionRendering += new EventHandler<SectionRenderEventArgs>(PushPrinting);
|
||||
// reportCreator.PageCreated += OnPageCreated;
|
||||
reportCreator.BuildExportList(); |
||||
|
||||
var pages = reportCreator.Pages; |
||||
|
||||
// var pages = CreateTestPage();
|
||||
|
||||
Console.WriteLine("WPFReportPreview - Create FixedDocumentRenderer"); |
||||
|
||||
|
||||
FixedDocumentRenderer renderer = FixedDocumentRenderer.CreateInstance(model.ReportSettings,pages); |
||||
|
||||
renderer.Start(); |
||||
renderer.RenderOutput(); |
||||
renderer.End(); |
||||
// Console.WriteLine("WPFReportPreview - document to viewer");
|
||||
IDocumentPaginatorSource document = renderer.Document; |
||||
viewer.Document = renderer.Document; |
||||
} |
||||
|
||||
|
||||
PagesCollection CreateTestPage() |
||||
{ |
||||
var pages = new PagesCollection(); |
||||
ExporterPage page = ExporterPage.CreateInstance(new SectionBounds(new ReportSettings(),false),1); |
||||
page.PageNumber = 1; |
||||
|
||||
TextStyleDecorator decorator1 = new TextStyleDecorator() |
||||
{ |
||||
Location = new System.Drawing.Point (10,10), |
||||
Font = GlobalValues.DefaultFont, |
||||
ForeColor = Color.Black, |
||||
BackColor = Color.White |
||||
|
||||
}; |
||||
|
||||
|
||||
page.Items.Add(new ExportText (decorator1,false) |
||||
{ |
||||
Text = "hello world" |
||||
|
||||
}); |
||||
|
||||
|
||||
TextStyleDecorator decorator2 = new TextStyleDecorator() |
||||
{ |
||||
Location = new System.Drawing.Point (20,20), |
||||
Font = GlobalValues.DefaultFont, |
||||
ForeColor = Color.Black, |
||||
BackColor = Color.White |
||||
|
||||
}; |
||||
page.Items.Add(new ExportText (decorator2,false) |
||||
{ |
||||
Text = "My First PdfPrintout" |
||||
|
||||
}); |
||||
|
||||
|
||||
pages.Add(page); |
||||
return pages; |
||||
} |
||||
|
||||
|
||||
protected override void SaveToPrimary() |
||||
{ |
||||
// throw new NotImplementedException();
|
||||
} |
||||
|
||||
|
||||
public override object Control { |
||||
get { |
||||
return viewer; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,151 @@
@@ -0,0 +1,151 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 05.05.2011 |
||||
* Time: 20:27 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Markup; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.Reports.Core.Globals; |
||||
using ICSharpCode.Reports.Core.WPF; |
||||
|
||||
namespace ICSharpCode.Reports.Core.Exporter.ExportRenderer |
||||
{ |
||||
/// <summary>
|
||||
/// Description of FixedDocumentRenderer.
|
||||
/// </summary>
|
||||
public class FixedDocumentRenderer:BaseExportRenderer |
||||
{ |
||||
private PagesCollection pages; |
||||
private ReportSettings reportSettings; |
||||
private FixedDocument document ; |
||||
private FixedDocumentCreator docCreator; |
||||
|
||||
// http://www.nbdtech.com/Blog/archive/2009/04/20/wpf-printing-part-2-the-fixed-document.aspx
|
||||
|
||||
|
||||
public static FixedDocumentRenderer CreateInstance (ReportSettings reportSettings,PagesCollection pages) |
||||
{ |
||||
var instance = new FixedDocumentRenderer(reportSettings,pages); |
||||
return instance; |
||||
} |
||||
|
||||
private FixedDocumentRenderer(ReportSettings reportSettings,PagesCollection pages):base(pages) |
||||
{ |
||||
this.pages = pages; |
||||
this.reportSettings = reportSettings; |
||||
this.docCreator = new FixedDocumentCreator(); |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
#region overrides
|
||||
|
||||
public override void Start() |
||||
{ |
||||
base.Start(); |
||||
Console.WriteLine("FixedDocumentRenderer - Start"); |
||||
document = new FixedDocument(); |
||||
|
||||
|
||||
// point 595x842
|
||||
|
||||
// 827/1169
|
||||
|
||||
// A4 paper is 210mm x 297mm
|
||||
//8.2 inch x 11.6 inch
|
||||
//1240 px x 1754 px
|
||||
/* |
||||
iTextSharp uses a default of 72 pixels per inch. |
||||
792 would be 11", or the height of a standard Letter size paper." + |
||||
595 would be 8.264",
|
||||
which is the standard width of A4 size paper. |
||||
Using 595 x 792 as the page size would be a cheap and dirty way |
||||
to ensure that you could print on either A4 or Letter |
||||
without anything getting cut off. – |
||||
*/ |
||||
PrintDialog printDialog = new PrintDialog(); |
||||
var w = printDialog.PrintableAreaHeight; |
||||
var h = printDialog.PrintableAreaWidth; |
||||
Console.WriteLine(new System.Windows.Size(w,h)); |
||||
|
||||
PageSize = new System.Windows.Size(reportSettings.PageSize.Width,reportSettings.PageSize.Height); |
||||
document.DocumentPaginator.PageSize = PageSize; |
||||
} |
||||
|
||||
|
||||
|
||||
public override void RenderOutput() |
||||
{ |
||||
base.RenderOutput(); |
||||
Console.WriteLine("FixedDocumentRenderer - RenderOutput"); |
||||
|
||||
foreach (var page in pages) |
||||
{ |
||||
FixedPage fixedPage = docCreator.CreatePage (page); |
||||
docCreator.ArrangePage(document.DocumentPaginator.PageSize,fixedPage); |
||||
AddPageToDocument(document,fixedPage); |
||||
} |
||||
|
||||
//http://www.ericsink.com/wpf3d/B_Printing.html
|
||||
// http://www.switchonthecode.com/tutorials/wpf-printing-part-2-pagination
|
||||
|
||||
|
||||
// http://stackoverflow.com/questions/3671724/wpf-flowdocument-page-break-positioning
|
||||
// http://wpf.2000things.com/tag/drawingvisual/
|
||||
http://wpf.2000things.com/2011/03/25/256-use-a-fixeddocument-to-display-content-at-fixed-locations/
|
||||
|
||||
//http://wpf.2000things.com/2011/03/25/256-use-a-fixeddocument-to-display-content-at-fixed-locations/
|
||||
//http://www.neodynamic.com/ND/FaqsTipsTricks.aspx?tabid=66&prodid=0&sid=99
|
||||
|
||||
//http://www.eggheadcafe.com/tutorials/aspnet/9cbb4841-8677-49e9-a3a8-46031e699b2e/wpf-printing-and-print-pr.aspx
|
||||
//http://www.eggheadcafe.com/tutorials/aspnet/9cbb4841-8677-49e9-a3a8-46031e699b2e/wpf-printing-and-print-pr.aspx
|
||||
//
|
||||
//http://www.eggheadcafe.com/tutorials/aspnet/22ac97f3-4a3d-4fee-a411-e456f77f6a90/wpf-report-engine-part-3.aspx
|
||||
/* |
||||
System.Windows.Controls.Border b = new System.Windows.Controls.Border(); |
||||
b.BorderThickness = new Thickness(2); |
||||
b.BorderBrush = System.Windows.Media.Brushes.Black; |
||||
b.Padding = new Thickness(15); |
||||
b.Child = page2Text; |
||||
FixedPage.SetLeft(b, 2 * 96 * 0.75 ); |
||||
FixedPage.SetTop(b,3 * 96 * 0.75 ); |
||||
|
||||
page.Children.Add((UIElement)b); |
||||
*/ |
||||
/* |
||||
*/ |
||||
Document = document; |
||||
} |
||||
|
||||
|
||||
|
||||
void AddPageToDocument(FixedDocument doc,FixedPage page) |
||||
{ |
||||
Console.WriteLine("AddPageToDocument"); |
||||
PageContent pageContent = new PageContent(); |
||||
((IAddChild)pageContent).AddChild(page); |
||||
doc.Pages.Add(pageContent); |
||||
} |
||||
|
||||
|
||||
public override void End() |
||||
{ |
||||
base.End(); |
||||
Console.WriteLine("FixedDocumentRenderer - End"); |
||||
} |
||||
|
||||
public Size PageSize {get;private set;} |
||||
public IDocumentPaginatorSource Document {get;private set;} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,97 @@
@@ -0,0 +1,97 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.IO.Packaging; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Input; |
||||
using System.Windows.Media; |
||||
using System.Windows.Xps; |
||||
using System.Windows.Xps.Packaging; |
||||
|
||||
using ICSharpCode.Reports.Core.WPF; |
||||
|
||||
namespace ICSharpCode.Reports.Core.Exporter.ExportRenderer |
||||
{ |
||||
/// <summary>
|
||||
/// Description of XPSRenderer.
|
||||
/// </summary>
|
||||
public class FlowDocumentRenderer:BaseExportRenderer |
||||
{ |
||||
private PagesCollection pages; |
||||
private FlowDocumentCreator pageCreator; |
||||
|
||||
#region Constructor
|
||||
|
||||
public static FlowDocumentRenderer CreateInstance (PagesCollection pages) { |
||||
|
||||
var instance = new FlowDocumentRenderer(pages); |
||||
|
||||
return instance; |
||||
} |
||||
|
||||
private FlowDocumentRenderer(PagesCollection pages):base(pages) |
||||
{ |
||||
this.pages = pages; |
||||
Console.WriteLine("FlowDocumentRenderer - Create Instance"); |
||||
this.pageCreator = new FlowDocumentCreator(); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region overrides
|
||||
|
||||
public override void Start() |
||||
{ |
||||
base.Start(); |
||||
Console.WriteLine("FlowDocumentRenderer - Start"); |
||||
} |
||||
|
||||
|
||||
public override void RenderOutput() |
||||
{ |
||||
base.RenderOutput(); |
||||
Console.WriteLine("FlowDocumentRenderer - RenderOutput"); |
||||
|
||||
IDocumentPaginatorSource d = new FlowDocument(pageCreator.CreatePage(pages[0])); |
||||
|
||||
|
||||
if ( d is FlowDocument) |
||||
{ |
||||
// DocumenattViewer does not support FlowDocument, so we'll convert it
|
||||
MemoryStream xpsStream = new MemoryStream(); |
||||
Package package = Package.Open(xpsStream, FileMode.Create, FileAccess.ReadWrite); |
||||
string packageUriString = "memorystream://data.xps"; |
||||
PackageStore.AddPackage(new Uri(packageUriString), package); |
||||
|
||||
XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.Normal, packageUriString); |
||||
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument); |
||||
|
||||
writer.Write(d.DocumentPaginator); |
||||
Document = xpsDocument.GetFixedDocumentSequence(); |
||||
// cleanup = delegate {
|
||||
// viewer.Document = null;
|
||||
// xpsDocument.Close();
|
||||
// package.Close();
|
||||
// PackageStore.RemovePackage(new Uri(packageUriString));
|
||||
// };
|
||||
} |
||||
else { |
||||
Document = d; |
||||
} |
||||
} |
||||
|
||||
|
||||
public override void End() |
||||
{ |
||||
base.End(); |
||||
Console.WriteLine("FlowDocumentRenderer - End"); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
public IDocumentPaginatorSource Document {get;private set;} |
||||
} |
||||
} |
@ -1,50 +0,0 @@
@@ -1,50 +0,0 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Reports.Core.Exporter.ExportRenderer |
||||
{ |
||||
/// <summary>
|
||||
/// Description of XPSRenderer.
|
||||
/// </summary>
|
||||
public class XpsRenderer:BaseExportRenderer |
||||
{ |
||||
#region Constructor
|
||||
|
||||
public static XpsRenderer CreateInstance (PagesCollection pages) { |
||||
if (pages == null) { |
||||
throw new ArgumentNullException("pages"); |
||||
} |
||||
XpsRenderer instance = new XpsRenderer(pages); |
||||
return instance; |
||||
} |
||||
|
||||
private XpsRenderer(PagesCollection pages):base(pages) |
||||
{ |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region overrides
|
||||
|
||||
public override void Start() |
||||
{ |
||||
base.Start(); |
||||
} |
||||
|
||||
|
||||
public override void RenderOutput() |
||||
{ |
||||
base.RenderOutput(); |
||||
} |
||||
|
||||
|
||||
public override void End() |
||||
{ |
||||
base.End(); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,116 @@
@@ -0,0 +1,116 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 10.05.2011 |
||||
* Time: 19:41 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Documents; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.Reports.Core.Exporter; |
||||
|
||||
namespace ICSharpCode.Reports.Core.WPF |
||||
{ |
||||
/// <summary>
|
||||
/// Description of FixedDocumentCreator.
|
||||
/// </summary>
|
||||
public class FixedDocumentCreator |
||||
{ |
||||
public FixedDocumentCreator() |
||||
{ |
||||
} |
||||
|
||||
|
||||
public FixedPage CreatePage(ExporterPage exporterPage) |
||||
{ |
||||
Console.WriteLine("\tCreatepage with {0} items ",exporterPage.Items.Count); |
||||
FixedPage page = new FixedPage(); |
||||
//http://www.bing.com/search?q=Convert+Windows+Forms+to+WPF&FORM=QSRE
|
||||
foreach (var element in exporterPage.Items) { |
||||
var item = ItemFactory(element); |
||||
page.Children.Add(item); |
||||
} |
||||
|
||||
Console.WriteLine("\tPage created with with {0} items ",page.Children.Count); |
||||
return page; |
||||
} |
||||
|
||||
|
||||
UIElement ItemFactory (BaseExportColumn column) |
||||
{ |
||||
var text = column as ExportText; |
||||
UIElement element = null; |
||||
if (text != null) { |
||||
element = CreateTextColumn(text); |
||||
} |
||||
return element; |
||||
} |
||||
|
||||
|
||||
TextBlock CreateTextColumn(ExportText et) |
||||
{ |
||||
TextBlock tb = new TextBlock(); |
||||
tb.Text = et.Text; |
||||
|
||||
SetFont(tb,et.StyleDecorator); |
||||
FixedPage.SetLeft(tb,et.StyleDecorator.Location.X ); |
||||
FixedPage.SetTop(tb,et.StyleDecorator.Location.Y); |
||||
return tb; |
||||
} |
||||
|
||||
|
||||
void SetFont(TextBlock tb, TextStyleDecorator styleDecorator) |
||||
{ |
||||
//
|
||||
// http://msdn.microsoft.com/en-us/library/system.windows.textdecorations.aspx
|
||||
// http://stackoverflow.com/questions/637636/using-a-system-drawing-font-with-a-wpf-label
|
||||
|
||||
var s = NewTypeFaceFromFont (styleDecorator.Font); |
||||
|
||||
// FontFamilyConverter conv = new FontFamilyConverter();
|
||||
// FontFamily mfont1 = conv.ConvertFromString(styleDecorator.Font.Name) as FontFamily;
|
||||
// tb.FontFamily = mfont1;
|
||||
tb.FontFamily = new FontFamily(styleDecorator.Font.FontFamily.Name); |
||||
tb.FontSize = styleDecorator.Font.GetHeight(); |
||||
if (styleDecorator.Font.Bold) { |
||||
tb.FontWeight = FontWeights.Bold; |
||||
} |
||||
Console.WriteLine ("{0} - {1}",styleDecorator.Font.FontFamily.Name,styleDecorator.Font.GetHeight()); |
||||
} |
||||
|
||||
|
||||
private static Typeface NewTypeFaceFromFont(System.Drawing.Font f) |
||||
{ Typeface typeface = null; |
||||
FontFamily ff = new FontFamily(f.Name); |
||||
if (typeface == null) |
||||
{ |
||||
typeface = new Typeface(ff, (f.Style == System.Drawing.FontStyle.Italic ? FontStyles.Italic : FontStyles.Normal), |
||||
(f.Style == System.Drawing.FontStyle.Bold ? FontWeights.Bold : FontWeights.Normal), |
||||
FontStretches.Normal); |
||||
} |
||||
if (typeface == null) |
||||
{ |
||||
typeface = new Typeface(new FontFamily("Arial"), |
||||
FontStyles.Italic, |
||||
FontWeights.Normal, |
||||
FontStretches.Normal); |
||||
} |
||||
return typeface; |
||||
} |
||||
|
||||
|
||||
public void ArrangePage(Size pageSize, FixedPage page) |
||||
{ |
||||
Console.WriteLine("Arrange page with Size {0}",pageSize); |
||||
page.Measure(pageSize); |
||||
page.Arrange(new Rect(new System.Windows.Point(), pageSize)); |
||||
page.UpdateLayout(); |
||||
} |
||||
|
||||
} |
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 04.05.2011 |
||||
* Time: 20:06 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using ICSharpCode.Reports.Core.Exporter; |
||||
|
||||
using System.Windows.Documents; |
||||
|
||||
namespace ICSharpCode.Reports.Core.WPF |
||||
{ |
||||
/// <summary>
|
||||
/// Description of FlowDocumentCreator.
|
||||
/// </summary>
|
||||
public class FlowDocumentCreator |
||||
{ |
||||
|
||||
ExporterPage page; |
||||
|
||||
public FlowDocumentCreator() |
||||
{ |
||||
Console.WriteLine("FlowDocumentCreator :Constructor"); |
||||
} |
||||
|
||||
// http://stackoverflow.com/questions/3671724/wpf-flowdocument-page-break-positioning
|
||||
public Block CreatePage (ExporterPage page) |
||||
{ |
||||
Console.WriteLine("FlowDocumentCreator :CreatePage"); |
||||
this.page = page; |
||||
Paragraph p = new Paragraph(); |
||||
|
||||
Run r = new Run("Hallo"); |
||||
p.Inlines.Add(r); |
||||
|
||||
return p; |
||||
} |
||||
|
||||
} |
||||
} |
Loading…
Reference in new issue