Basically, I want to generate a Word file, then print it.
Here's what I have so far:
private void CreateDocument()
{
try
{
// Create an instance for word app
Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application();
// Set status for word application is to be visible or not.
winword.Visible = false;
// Create a missing variable for missing value
object missing = System.Reflection.Missing.Value;
// Create a new document
Microsoft.Office.Interop.Word.Document document = winword.Documents.Add(ref missing, ref missing, ref missing, ref missing);
// Add paragraph with Heading 1 style
Microsoft.Office.Interop.Word.Paragraph para1 = document.Content.Paragraphs.Add(ref missing);
object styleHeading1 = "Heading 1";
para1.Range.set_Style(ref styleHeading1);
para1.Range.Text = "BRGY. BOLO WATER SERVICE COOPERATIVE";
para1.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
para1.Range.InsertParagraphAfter();
// Save the document
filename = Application.StartupPath + @"\Disconnection\temp1.docx";
document.SaveAs(ref filename);
document.Close(ref missing, ref missing, ref missing);
document = null;
MessageBox.Show("Document created successfully !");
if (File.Exists(filename.ToString()))
{
PrintDocument printDoc = new PrintDocument();
PrinterSettings prnsetting = new PrinterSettings();
prnsetting.PrintFileName = Application.StartupPath + @"\Disconnection\.do";
printDoc.DocumentName = "temp1";
printPreviewDialog1.Document = printDoc;
printPreviewDialog1.ShowDialog();
}
}
catch (Exception ex)
{
//debug purposes
MessageBox.Show(ex.Message +"\n"+filename.ToString());
}
}
The problem is when the print preview shows up, its only a blank page. Is there a proper way of doing this? Do I have to set up the file path for the printer?