how print PGL by XML
Answer / Pushpraj Singh
To print a PCL (Printer Control Language) document from an XML file in Windows Forms, you can use the PrintDocument class and XSLT transformation. Here is an example:
```csharp
// Load the XML and XSLT files
XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(Path.GetFullPath("MyPGLTemplate.xslt"));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Path.GetFullPath("MyXMLData.xml"));
// Transform the XML to PCL using the XSLT template
MemoryStream ms = new MemoryStream();
transform.Transform(xmlDoc, null, ms);
byte[] pclBytes = ms.ToArray();
// Create a PrintDocument and set its PrintPage event handler
PrintDocument printDoc = new PrintDocument();
printDoc.PrintPage += PrintPCL;
printDoc.Print();
// Print the PCL bytes to the default printer in the PrintPage event handler
void PrintPCL(object sender, PrintPageEventArgs e)
{
byte[] pclBytes = (byte[])e.UserState;
int i = 0;
foreach (byte b in pclBytes)
{
// Send each byte of the PCL to the printer
e.Graphics.DrawString(b.ToString(), new Font("Courier New", 12), Brushes.Black, i++, 0);
}
}
```
| Is This Answer Correct ? | 0 Yes | 0 No |
List out controls which does not have events?
Which property of the errorprovider control automatically sets to the form to which?
Which controls have refresh method?
Is it possible to save view state on the web server?
What is difference between winforms and windows forms?
What are the forms of graphics?
what is the difference between Listindex and Tab index?
which property of menu cannot be set at run time?
What are different options to store state in ASP.NET applications?
Explain the new events in textbox that has been included in vb?
Explain how many number of events does the timer controls?
What is form based application?