|
1 | 1 | using Syncfusion.Pdf;
|
2 | 2 | using Syncfusion.Pdf.Graphics;
|
3 | 3 | using System.ComponentModel;
|
| 4 | +using System.IO; |
4 | 5 |
|
5 | 6 |
|
6 | 7 | namespace CreatePDF
|
@@ -38,28 +39,35 @@ public PdfViewerViewModel()
|
38 | 39 | //Set the created PDF stream to pdfDocumentStream for loading it in PDF Viewer
|
39 | 40 | pdfDocumentStream = CreatePDF();
|
40 | 41 | }
|
41 |
| - private MemoryStream CreatePDF() |
| 42 | + private Stream CreatePDF() |
42 | 43 | {
|
43 |
| - //Create a new PDF document. |
| 44 | + // Create a new PDF document. |
44 | 45 | PdfDocument document = new PdfDocument();
|
45 |
| - //Add a page to the document. |
| 46 | + |
| 47 | + // Add a page to the document. |
46 | 48 | PdfPage page = document.Pages.Add();
|
47 |
| - //Create PDF graphics for the page. |
| 49 | + |
| 50 | + // Create PDF graphics for the page. |
48 | 51 | PdfGraphics graphics = page.Graphics;
|
49 | 52 |
|
50 |
| - //Set the standard font. |
| 53 | + // Set the standard font. |
51 | 54 | PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);
|
52 |
| - //Draw the text. |
| 55 | + // Draw the text. |
53 | 56 | graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new Syncfusion.Drawing.PointF(0, 0));
|
54 | 57 |
|
55 |
| - //Creating the stream object. |
| 58 | + // Creating the stream object. |
56 | 59 | MemoryStream stream = new MemoryStream();
|
57 |
| - //Save the document into memory stream. |
| 60 | + |
| 61 | + // Save the document into memory stream. |
58 | 62 | document.Save(stream);
|
59 |
| - //Close the document. |
| 63 | + |
| 64 | + // Close the document. |
60 | 65 | document.Close(true);
|
61 | 66 |
|
62 |
| - return stream; |
| 67 | + if (stream.CanSeek) |
| 68 | + stream.Position = 0; |
| 69 | + |
| 70 | + return stream; |
63 | 71 |
|
64 | 72 | }
|
65 | 73 | /// <summary>
|
|
0 commit comments