Hello!
I've tried to create a PDF from my webpage project by including the DLL and everything works fine with the compiling and that but when running the project i get "You cannot draw on a page that is not owned by a PdfDocument object.".
This comes from XGraphics.cs
if (page.Owner == null)
throw new ArgumentException("You cannot draw on a page that is not owned by a PdfDocument object.", "page");
Iv'e tried a normal console application and there everythin workes fine.
I've also enabled the attribute write on the webapplication in Internet Information Server.
My code looks like this.
Code:
using System;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PdfSharp;
using PdfSharp.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
PdfDocument dokument = new PdfDocument();
PdfPage sida = new PdfPage();
XGraphics grafik = XGraphics.FromPdfPage(sida);
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
grafik.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, sida.Width, sida.Height),XStringFormat.Center);
string filename = "HelloWorld.pdf";
dokument.Save(filename);
Process.Start(filename);
}
}