Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.IO;
using MigraDoc;
using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using MigraDoc.RtfRendering;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.DocumentObjectModel.Shapes;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
namespace PdfSharpTest
{
public partial class _Default : System.Web.UI.Page
{
public static string FillerText = "filler text";
protected void Page_Load(object sender, EventArgs e)
{
// Create a MigraDoc document
Document document = CreateDocument();
document.Info.Title = "title";
//string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document);
//MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = document;
renderer.RenderDocument();
// Send PDF to browser
MemoryStream stream = new MemoryStream();
renderer.Save(stream, false); // or renderer.PdfDocument.Save(stream, false);
Response.Clear();
// Response.AddHeader("Content-Disposition", "attachment; filename=filename.pdf");
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();
}
The above code worked for me to stream a migradoc to the browser. In the case where i dont specify a (content disposition)filename it loads on the browser window it self without asking to save it as a file which i expect. But on the browser tab it displays "Specified method is not supported"
Attachment:
migradoc.jpg [ 72.28 KiB | Viewed 12903 times ]