how print PGL by XML



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

Post New Answer

More Dot Net WindowsForms Interview Questions

List out controls which does not have events?

8 Answers   Silicon,


Which property of the errorprovider control automatically sets to the form to which?

1 Answers  


Which controls have refresh method?

3 Answers  


Is it possible to save view state on the web server?

1 Answers   Arctern,


What is difference between winforms and windows forms?

1 Answers  


What are the forms of graphics?

1 Answers  


what is the difference between Listindex and Tab index?

1 Answers  


which property of menu cannot be set at run time?

3 Answers  


What are different options to store state in ASP.NET applications?

2 Answers   Arctern,


Explain the new events in textbox that has been included in vb?

1 Answers  


Explain how many number of events does the timer controls?

1 Answers  


What is form based application?

1 Answers  


Categories