Browse Source

Fix: GeneratePdf closes provided stream

Marcin Ziąbek 4 years ago
parent
commit
9c05c182b8
2 changed files with 2 additions and 8 deletions
  1. 2 3
      QuestPDF.ReportSample/Tests.cs
  2. 0 5
      QuestPDF/Drawing/DocumentGenerator.cs

+ 2 - 3
QuestPDF.ReportSample/Tests.cs

@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.Diagnostics;
 using System.IO;
 using System.Linq;
@@ -18,8 +18,7 @@ namespace QuestPDF.ReportSample
             var report = new StandardReport(reportModel);
             
             var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"test_result.pdf");
-            using var stream = new FileStream(path, FileMode.Create);
-            report.GeneratePdf(stream);
+            report.GeneratePdf(path);
             
             Process.Start("explorer.exe", path);
         }

+ 0 - 5
QuestPDF/Drawing/DocumentGenerator.cs

@@ -35,8 +35,6 @@ namespace QuestPDF.Drawing
                 catch (Exception exception)
                 {
                     pdf.Close();
-                    stream.Close();
-                    
                     throw new DocumentDrawingException("An exception occured during document drawing.", exception);
                 }
 
@@ -45,8 +43,6 @@ namespace QuestPDF.Drawing
                 if (totalPages >= metadata.DocumentLayoutExceptionThreshold)
                 {
                     pdf.Close();
-                    stream.Close();
-
                     throw new DocumentLayoutException("Composed layout generates infinite document.");
                 }
                 
@@ -57,7 +53,6 @@ namespace QuestPDF.Drawing
             }
             
             pdf.Close();
-            stream.Dispose();
         }
 
         internal static IEnumerable<byte[]> GenerateImages(IDocument document)