Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 79ef578

Browse files
Add public void Run (Stream stream) and public void Run (string fileName,bool show) to Pdf/PdfExporter.cs
1 parent 8698272 commit 79ef578

1 file changed

Lines changed: 37 additions & 12 deletions

File tree

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Pdf/PdfExporter.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Collections.ObjectModel;
2121
using System.Diagnostics;
2222

23+
using System.IO;
2324
using PdfSharp.Pdf;
2425
using ICSharpCode.Reporting.Exporter;
2526
using ICSharpCode.Reporting.Exporter.Visitors;
@@ -32,39 +33,63 @@ namespace ICSharpCode.Reporting.Pdf
3233
/// </summary>
3334
public class PdfExporter:BaseExporter{
3435

35-
PdfVisitor visitor;
3636
PdfDocument pdfDocument;
3737

38-
3938
public PdfExporter(Collection<ExportPage> pages):base(pages){
4039
}
4140

41+
42+
public void Run (string fileName,bool show) {
43+
string file;
44+
if (String.IsNullOrEmpty(fileName)) {
45+
file = Pages[0].PageInfo.ReportName + ".pdf";
46+
}
47+
pdfDocument = new PdfDocument();
48+
ConvertPagesToPdf();
49+
pdfDocument.Save(fileName);
50+
if (show) {
51+
Process.Start(fileName);
52+
}
53+
}
54+
55+
56+
public void Run (Stream stream) {
57+
if (stream == null)
58+
throw new ArgumentNullException("stream");
59+
pdfDocument = new PdfDocument(stream);
60+
ConvertPagesToPdf();
61+
pdfDocument.Save(stream,false);
62+
stream.Seek(0, SeekOrigin.Begin);
63+
}
64+
65+
4266
public override void Run()
4367
{
44-
pdfDocument = new PdfDocument();
45-
visitor = new PdfVisitor(pdfDocument);
68+
var fileName = Pages[0].PageInfo.ReportName + ".pdf";
69+
Run(fileName, false);
70+
Process.Start(fileName);
71+
}
72+
73+
74+
void ConvertPagesToPdf()
75+
{
76+
var visitor = new PdfVisitor(pdfDocument);
4677
SetDocumentTitle(Pages[0].PageInfo.ReportName);
4778
foreach (var page in Pages) {
4879
var acceptor = page as IAcceptor;
4980
if (acceptor != null) {
5081
visitor.Visit(page);
5182
}
5283
}
53-
54-
const string filename = "HelloWorld.pdf";
55-
56-
pdfDocument.Save(filename);
57-
58-
// ...and start a viewer.
59-
60-
Process.Start(filename);
6184
}
6285

86+
6387
void SetDocumentTitle(string reportName)
6488
{
6589
pdfDocument.Info.Title = reportName;
6690
}
6791

92+
6893
public PdfDocument PdfDocument {
6994
get { return pdfDocument; }
7095
}

0 commit comments

Comments
 (0)