पर भेजने से पहले .NET WinForm का उपयोग करने का आदेश देता है मेरे पास एक .NET Windows अनुप्रयोग है जो ZPL II या EPL2 का उपयोग करके ज़ेबरा प्रिंटर को आदेश प्रिंट करता है। क्या ज़ेबरा प्रिंटर से सीधे प्रिंट करने से पहले किसी फ़ॉर्म में डेटा का पूर्वावलोकन करने का कोई तरीका है?प्रिंट पूर्वावलोकन जेपीएल II जेबरा प्रिंटर
उत्तर
लेबल का पूर्वावलोकन करने का एकमात्र तरीका प्रिंटर के वेब पेज पर है।
आप प्रिंटर की निर्देशिका लिस्टिंग http://<printer IP>/dir
जाने के लिए और बचाया लेबल पर क्लिक करें (या एक नया बना) तो आप क्लिक कर सकते हैं "Preview Label"
मैं अपने आवेदन में लेबल दिखाने की क्षमता की जरूरत है। इसलिए मैंने फिडलर को झुकाया और यह पता लगाया कि लेबल की छवि प्राप्त करने के लिए संचार क्या था।
मुझे यह लिंककैड में चल रहा है। HTTP सामान थोड़ा साफ किया जा सकता है, लेकिन मैं दूसरों का उपयोग करने के लिए मैं कोड पोस्ट होगा सोचा:
void Main()
{
string printerIpAddress = "10.92.0.167";
string zpl="^XA^CFD^CVY^PON^FWN^LS0^LT0^LH15,17^FS^FO0,2^FO14,3^FH^FDHi^FS^XZ";
// post the data to the printer
var imageName = PostZplAndReturnImageName(zpl, printerIpAddress);
// Get the image from the printer
var image = LoadImageFromPrinter(imageName, printerIpAddress);
Console.WriteLine(image);
}
public static string PostZplAndReturnImageName(string zpl, string printerIpAddress)
{
string response = null;
// Setup the post parameters.
string parameters = "data="+ zpl;
parameters = parameters + "&" + "dev=R";
parameters = parameters + "&" + "oname=UNKNOWN";
parameters = parameters + "&" + "otype=ZPL";
parameters = parameters + "&" + "prev=Preview Label";
parameters = parameters + "&" + "pw=";
// Post to the printer
response = HttpPost("http://"+ printerIpAddress +"/zpl", parameters);
// Parse the response to get the image name. This image name is stored for one retrieval only.
HtmlAgilityPack.HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(response);
var imageNameXPath = "/html[1]/body[1]/div[1]/img[1]/@alt[1]";
var imageAttributeValue = doc.DocumentNode.SelectSingleNode(imageNameXPath).GetAttributeValue("alt","");
// Take off the R: from the front and the .PNG from the back.
var imageName = imageAttributeValue.Substring(2);
imageName = imageName.Substring(0,imageName.Length - 4);
// Return the image name.
return imageName;
}
public static string HttpPost(string URI, string Parameters)
{
System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
req.Proxy = new System.Net.WebProxy();
//Add these, as we're doing a POST
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
//We need to count how many bytes we're sending.
//Post'ed Faked Forms should be name=value&
byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
req.ContentLength = bytes.Length;
System.IO.Stream os = req.GetRequestStream();
os.Write (bytes, 0, bytes.Length); //Push it out there
os.Close();
System.Net.WebResponse resp = req.GetResponse();
if (resp== null) return null;
System.IO.StreamReader sr =
new System.IO.StreamReader(resp.GetResponseStream());
return sr.ReadToEnd().Trim();
}
public static Image LoadImageFromPrinter(string imageName, string printerIpAddress)
{
string url = "http://"+ printerIpAddress +"/png?prev=Y&dev=R&oname="+ imageName +"&otype=PNG";
var response = Http.Get(url);
using (var ms = new MemoryStream(response))
{
Image image = Image.FromStream(ms);
return image;
}
}
public static class Http
{
public static byte[] Get(string uri)
{
byte[] response = null;
using (WebClient client = new WebClient())
{
response = client.DownloadData(uri);
}
return response;
}
}
यह निम्न संदर्भ दिया गया है:
HtmlAgilityPack
System.Drawing
System.Net
और निम्न उपयोग:
HtmlAgilityPack
System.Drawing
System.Drawing.Imaging
System.Net
नोट: मुझे एक धारावाहिक/गैर-आईपी संबोधित प्रिंटर के साथ संवाद करने का कोई तरीका नहीं मिला। (हालांकि इसका मतलब यह नहीं है कि कोई रास्ता नहीं है।)
अच्छा काम लगता है! आप कौन सा प्रिंटर विक्रेता जोड़ते हैं और मॉडल के साथ आपका कोड काम करते हैं, कृपया? – bluish
@bluish - ज़ेबरा लेबल प्रिंटर। मैंने इसे ZM400 पर परीक्षण किया। – Vaccano
ज़ेबरा 170Xi4 के साथ भी काम करता है। मुझे पता चला है कि प्रिंटर जेनरेट की गई छवि बड़ी मात्रा में बनाता है प्रस्तुत लेबल के चारों ओर सफेद जगह। मुझे यकीन नहीं है कि ZPL में लेबल चौड़ाई निर्धारित करने से यह ठीक हो जाएगा (हमारे अधिकांश डिज़ाइन नहीं हैं) – nbering
Labelary web service पर एक नज़र डालें, जो आपको जेपीएल को प्रोग्रामेटिक रूप से एक छवि में परिवर्तित करने की अनुमति देता है।
बस जेपीएल युक्त एक यूआरएल बनाएं जिसे आप प्रस्तुत करना चाहते हैं, छवि को वेब सर्वर से वापस प्राप्त करें, और छवि को अपने एप्लिकेशन के भीतर से उपयोगकर्ता को दिखाएं।
string zpl = "YOUR ZPL HERE";
string url = "http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/" + zpl;
using (WebClient client = new WebClient()) {
client.DownloadFile(url, "zpl.png");
}
नहीं है यह भी एक ZPL viewer आप एक वेब पेज पर संपादित करें और देखें ZPL सीधे देता है।
ऑनलाइन संपादक/दर्शक से लिंक: http://labelary.com/viewer.html – Chris
मुद्रित किए बिना लेबल प्रारूप प्रिंटर प्रारूप का उपयोग करके ऐसा करने के कुछ अन्य तरीके हैं। एक प्रिंटर ऑनलाइन स्वीकार्य है? – banno
दुर्भाग्य से कई प्रिंटर को यह टूल नहीं मिला है :( – bluish
क्या होगा यदि मेरे पास केवल प्रिंटर ड्राइवर स्थापित है और वास्तविक प्रिंटर नहीं है? क्या मैं अभी भी इस निर्देशिका सूची तक पहुंचने में सक्षम हूं? –