In VS2010 using MigraDoc if I run my .NET4.0 Windows application with a blank text field I get an exception;
ArgumentNullException was unhandled
This is pointing at ParagraphElements.cs > (beginning on Line 81)
Code:
public Text AddText(string text)
{
if (text == null)
throw new ArgumentNullException("text");
............ more code
I was unable to locate exception handling generally and specifically on this error. It maybe a newb mistake and my apologies for bothering you.
Ultimately I stepped outside of the code where the MigraDoc begins and placed some simple code
Code:
if (Pnumber == null)
{
MessageBox.Show("Please enter a Project Number.");
return;
}
if (Pname == null)
{
MessageBox.Show("Please enter a Project Name.");
return;
}
if (Prev == null)
{
MessageBox.Show("Please enter a Project Revision level.");
return;
}
This did not work within the basic creation of the MigraDoc pdf (which I basically copied and pasted together from the sample documentation).
Code:
Document document = CreateDocument();
document.UseCmykColor = true;
//document.DefaultPageSetup.PageHeight = DPS.PageHeight;
//document.DefaultPageSetup.PageWidth = DPS.PageWidth;
// string ddl = MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToString(document);
////#if true_
//// RtfDocumentRenderer renderer = new RtfDocumentRenderer();
//// renderer.Render(document, "HelloWorld.rtf", null);
////#endif
// ----- Unicode encoding and font program embedding in MigraDoc is demonstrated here -----
// A flag indicating whether to create a Unicode PDF or a WinAnsi PDF file.
// This setting applies to all fonts used in the PDF document.
// This setting has no effect on the RTF renderer.
const bool unicode = false;
<<More samples and comments>>
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
// Associate the MigraDoc document with a renderer
pdfRenderer.Document = document;
// Layout and render document to PDF
pdfRenderer.RenderDocument();
// Save the document...
string filename = Pnumber + "-SCG.pdf";
////const string filename = "HelloWorld.pdf";
pdfRenderer.PdfDocument.Save(filename);
// ...and start a viewer.
Process.Start(filename);
}
/// <summary>
/// Creates an absolutely minimalistic document.
/// </summary>
static Document CreateDocument()
{
<< the other part I copied and added to>>
return document;
My questions are:
1. Is this the appropriate way to handle exceptions when using MigraDoc that will throw user error exceptions, and
2. Is there any documentation explaining better exception handling of user errors when the MigraDoc statements have already been called?
Thank you very much for your assistance. I'm looking forward to working with MigraDoc and PDFsharp. It looks fascinating and isn't terribly difficult to use. I hope it performs as I've been told
Have a Great Day
Frank Pytel