Page 1 of 1

ZPL view

Posted: Tue Feb 22, 2022 11:44 am
by Georg_BA
Hello everyone

I'm trying to create a ZPL viewer
display the label from the label printer before I print it
This is also good for presentations if you don't have a label printer

I use api from the site http://labelary.com

Code: Select all

Function zpl_view()

LOCAL hCurl

url:="http://api.labelary.com/v1/printers/8dpmm/labels/4x10/0/"

//cFormBody:=' --data '+'"^xa^cfa,50^fo100,100^fdHello World^fs^xz"'+' > label.png'
 cFormBody:=' --data '+'"^xa^cfa,50^fo100,100^fdHello World^fs^xz"'
 cFormBody+=' --header '+'"Accept: application/pdf"'+' > label.pdf'
 //msgbox(cformbody)

 curl_global_init()

 IF !empty( hCurl := curl_easy_init() )
    curl_easy_setopt( hCurl, HB_CURLOPT_URL, url + cFormBody )
    //curl_easy_setopt( hCurl, HB_CURLOPT_DL_FILE_SETUP, "test.txt" )
    curl_easy_setopt( hCurl, HB_CURLOPT_HTTPPOST, .T. )
    curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDSIZE, LEN( cFormBody ) )
    curl_easy_setopt( hCurl, HB_CURLOPT_POSTFIELDS, cFormBody )
    curl_easy_setopt( hCurl, HB_CURLOPT_DL_BUFF_SETUP )

    curl_easy_perform( hCurl )
    //msginfo( curl_easy_dl_buff_get( hCurl ) )    //return png
    //velke_foto2(curl_easy_dl_buff_get( hCurl ))
    curl_easy_reset( hCurl )
  ENDIF
  curl_global_cleanup()
Return
the function returns a png image but I can't display it

The API allows input data from a file and output in PDF

this way of communication would suit me the most, the input data have more lines and I will display the output in Sumatra - PDF view

curl Examples:

curl --request POST http://api.labelary.com/v1/printers/8dpmm/labels/4x6/0/ --form file=@label.zpl --header "Accept: application/pdf" > label.pdf

in the annex is a sample of the ZPL code (input data )

Thanks for the help