PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Problems printing Documents
http://forum.pdfsharp.de/viewtopic.php?f=2&t=908
Page 1 of 1

Author:  MoodyMammoth [ Tue Oct 13, 2009 8:31 am ]
Post subject:  Problems printing Documents

Hi,

seems I am a little bit tired today, but I didn't get the right think to print some invoices :(
I use the sample to create some invoices and that works fine:
Code:
      InvoiceForm IF = new InvoiceForm();
      IF.Ort = dgv_Kunden.Rows[dgv_Kunden.CurrentRow.Index].Cells["Ort"].Value.ToString();
      IF.Positionen = dtRechnungsPositionen;
      doc = IF.CreateDocument();
      PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

      // Set the MigraDoc document
      pdfRenderer.Document = doc;

      // Create the PDF document
      pdfRenderer.RenderDocument();

      // Save the PDF document...
      string filename = Rechnungsnummer + ".pdf";
      pdfRenderer.Save(filename);
      // ...and start a viewer.
      Process.Start(filename);
      Gesamtsumme = IF.totalExtendedPrice;
      return filename;


But now I try to print these file only after creating, but I got the error that doc == null:(
tried it this way (and some other that didn't work:
Code:
      InvoiceForm IF = new InvoiceForm();
      IF.Positionen = dtRechnungsPositionen;
      doc = IF.CreateDocument();
      // Create a new MigraDoc document
     
      DocumentRenderer renderer = new DocumentRenderer(doc.Document);
      if (renderer != null)
      {
       
        MigraDocPrintDocument printDocument = new MigraDocPrintDocument();
        printDocument.Renderer = renderer;
        // Print the document
        printDocument.Print();
      }   



Can I get any hint whats wrong in my way to try it?

Best Regartds
Manfred

Author:  Thomas Hoevel [ Tue Oct 13, 2009 10:06 am ]
Post subject:  Re: Problems printing Documents

Hi!

Maybe you just have to call
Code:
renderer.PrepareDocument();

before
Code:
MigraDocPrintDocument printDocument = new MigraDocPrintDocument();

Author:  MoodyMammoth [ Tue Oct 13, 2009 10:09 am ]
Post subject:  Re: Problems printing Documents

Hi Thomas,

if doinig that, I got a NullReferneceException.

Any other idea?

[EDIT]
Copied that to the wrong place, put it to the right place and now it works. Thanks!
[/EDIT]
Best Regards
Manfred

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