Question

I'm currently writing an application in ASP.NET/C#, where the user needs to be able to generate PDF's of invoice summary's through the web based admin system.

The customer did not want to use an open source solution such as iTextSharp (stupid, I know) and instead purchased Adobe Acrobat/Reader (not sure which) which come with a virtual PDF printer. So we'll be interfacing with this printer on the server to generate the PDF's.

That's working well - we can easily generate PDF's and display them to the user. However, the way the content is written to the document to be printed (using the Graphics class of the PrintPageEventArgs event) is a bit foreign to me right now. Writing the text and header information is a piece of cake, but what's the easiest way of writing the contents of the GridView to the doucment?

Here's some example code of the sort of thing I'm using:

   protected void Page_Load(object sender, EventArgs e)
        {
            PrintDocument NewDoc = new PrintDocument();
            NewDoc.PrinterSettings.PrinterName = "PrinterName";
            NewDoc.PrintPage += new PrintPageEventHandler(NewDoc_PrintPage);
            NewDoc.Print();
        }

        void NewDoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawString("Test Header", new Font("Verdana", 18), Brushes.Black, 220, 120);
    }
Was it helpful?

Solution

Ended up having to essentially draw the grid myself. Pretty hacky but it works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top