2011-09-14 10 views

답변

2

레이블을 미리 볼 수있는 유일한 방법은 프린터의 웹 페이지입니다. 당신이 http://<printer IP>/dir 목록 프린터의 디렉토리로 이동 (새로 만들거나) 저장된 라벨을 클릭하면

당신은 내 응용 프로그램에서 라벨을 보일 수있는 능력을 필요로 "Preview Label"

+0

인쇄하지 않고 레이블을 프린터 형식으로 사용하는 몇 가지 다른 방법이 있습니다. 프린터를 인라인으로 받아 들일 수 있습니까? – banno

+0

불행히도 많은 프린터에이 도구가 없습니다. ( – bluish

+0

실제 프린터가 아닌 프린터 드라이버 만 설치 한 경우에도이 디렉토리 목록에 계속 액세스 할 수 있습니까? –

8

클릭 할 수 있습니다. 그래서 나는 Fiddler를 연결하고 레이블의 이미지를 얻기위한 의사 소통이 무엇인지 알아 냈습니다.

LinqPad에서 실행하고 있습니다. 는 HTTP 물건은 조금 정리 될 수있다,하지만 난 다른 사람이 사용할 수 있도록 내가 코드를 게시 할 것이라고 생각 :

HtmlAgilityPack 
System.Drawing 
System.Net 

다음과 같은 용도 :

이 다음 참조를 가지고

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.Drawing.Imaging 
System.Net 

참고 : 직렬/비 IP 주소 지정 프린터와 통신하는 방법을 찾지 못했습니다. (그렇다고해서 방법이 없다는 의미는 아닙니다.)

+0

좋은 결과가 나타납니다. – bluish

+0

@bluish - Zebra Label 프린터 : ZM400에서 테스트했습니다. – Vaccano

+0

또한 Zebra170Xi4와 호환됩니다. 프린터에서 생성하는 이미지가 많은 양의 공백 렌더링 된 레이블 주위에 공백입니다 .ZPL있는 레이블 너비를 설정하면 (대부분의 우리 디자인 않습니다.) 확실하지 않다 . – nbering

16

Labelary web service을 보시면 ZPL을 이미지로 프로그래밍 방식으로 변환 할 수 있습니다.

렌더링하려는 ZPL을 포함하는 URL을 작성하고 웹 서버에서 이미지를 가져온 다음 응용 프로그램 내에서 사용자에게 이미지를 표시하십시오.

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을 편집하고 볼 수있는 ZPL viewer도 있습니다.

+1

온라인 편집기/뷰어 링크 : http://labelary.com/viewer.html – Chris