PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 3:23 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Feb 10, 2008 10:34 pm 
Offline

Joined: Sun Feb 10, 2008 10:24 pm
Posts: 1
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);
    }
}


Top
 Profile  
Reply with quote  
PostPosted: Fri Jun 26, 2015 9:49 am 
Offline

Joined: Tue Apr 29, 2014 10:21 am
Posts: 27
I think you need to add the document to the page

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


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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 38 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group