adspace


how print PGL by XML

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

No New Questions to Answer in this Category !!    You can

Post New Questions

Answer Questions in Different Category