PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Cant create PDF from my Webproject
https://forum.pdfsharp.net/viewtopic.php?f=2&t=320
Page 1 of 1

Author:  danbli [ Sun Feb 10, 2008 10:34 pm ]
Post subject:  Cant create PDF from my Webproject

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);
    }
}

Author:  bizzel74 [ Fri Jun 26, 2015 9:49 am ]
Post subject:  Re: Cant create PDF from my Webproject

I think you need to add the document to the page

replace:
Code:
PdfPage sida = new PdfPage();


with:
Code:
PdfPage sida = dokument.AddPage();

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/