最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Print stickerbarcode label directly from browser on a (zebra) printer - Stack Overflow

programmeradmin1浏览0评论

We have to following situation, for one of our clients we are looking for a solution. He has build an PHP script that generates a label with some info and barcodes on it, so the workflow is as discribed : User put in some data ( some is data is pulled from the database, some not )

When the user clicks on print label, a windows opens and the label is generated. So now the code ( i guess javascript can do the job ) must do the work. The client wants that when the user clicks on ok ( or print label ) the label will be printed and the window will close without any interuption from a user.

Possible solution : /

So in fact :

  1. The script must select the right printer ( not the default one )
  2. Script must select the right format ( landscape/portrait and sizes of the labels )
  3. Must be printed without user interuption.
  4. Window must close automatic after printing the label.

Thanks for the help ;)

We have to following situation, for one of our clients we are looking for a solution. He has build an PHP script that generates a label with some info and barcodes on it, so the workflow is as discribed : User put in some data ( some is data is pulled from the database, some not )

When the user clicks on print label, a windows opens and the label is generated. So now the code ( i guess javascript can do the job ) must do the work. The client wants that when the user clicks on ok ( or print label ) the label will be printed and the window will close without any interuption from a user.

Possible solution : http://dymodevelopers.wordpress./2010/06/02/dymo-label-framework-javascript-library-samples-print-a-label/

So in fact :

  1. The script must select the right printer ( not the default one )
  2. Script must select the right format ( landscape/portrait and sizes of the labels )
  3. Must be printed without user interuption.
  4. Window must close automatic after printing the label.

Thanks for the help ;)

Share Improve this question asked Feb 1, 2013 at 7:51 user2031649user2031649 411 gold badge1 silver badge2 bronze badges 1
  • maybe you can look here for autoselecting the printer. – user757095 Commented Feb 1, 2013 at 8:14
Add a ment  | 

4 Answers 4

Reset to default 2

I do exactly this but due to the limitations of web based stuff cannot control the windows print interface without either firing a java or an activex based sub app I have had to have the web browsers set to print to the dymo printers.

Now I enforce the usage of firefox which means I have a custom install bundle of firefox that sets the margins to zero, turns off headers and footers, selects the right printer and paper and landscape etc (I only did a custom bundle because I had 100+ pc's to configure if its only a few its a 60 second change job to do it manually). The advantage of enforcing firefox is that FF allows you to select and set as the default printer a different printer to the system default. So in my case ff is set for dymo's the system printer is set as the kyocera's so nothing gets lost/set etc outside of firefox.

As for generating the barcode I just create a basecode as a jpg on the fly display the jpg in a new popup window and use a little javascript to automatically popup the print box so all the user has to do is click ok. Its impossible to do this without user input!

Unfortunately there's no easy way so close the window as there's no return event trap from the system print spooler/drivers back into the web browsers (they're sandboxed from each other for obvious reasons!) so the best you can do is implement a timed close after xxx seconds.

Short of it though is there's no easy way to do this with no user input and without making a few promises. Now if cash and time is of no issue to you I do have a proper way of doing it fully automated etc but its a big job

We just use an FTP (used to use windows, now use whats built into cold fusion, but any would do) and you send the zebra printer the definition of your barcode to the machine that way... anything that can open up such a channel and send the code to the printer will work.. so if you want to do it with javascript see how fireftp does it... then use that... or you can send info in ZPLII coding... that tells it how to print.

Since the link you posted talks about driver requirements, I assume you have a fair amount of control over the machine's software? If that's the case and you can use Firefox, then an add-on called JS Print Setup may work.

It basically gives webpages the ability to print directly to a printer on the user's puter without a print dialog.

I assume it would print a label fine as long as the right size is provided, but I haven't tested that. I did test it when a printer wasn't connected and it did send it to that printer's queue, so definitely tells the system to print the file.

Here is a code sample from the documentation: (It appears that it lets you set margins and everything as well.)

<script>
// set portrait orientation
jsPrintSetup.setOption('orientation', jsPrintSetup.kPortraitOrientation);

// set top margins in millimeters
jsPrintSetup.setOption('marginTop', 15);
jsPrintSetup.setOption('marginBottom', 15);
jsPrintSetup.setOption('marginLeft', 20);
jsPrintSetup.setOption('marginRight', 10);

// set page header
jsPrintSetup.setOption('headerStrLeft', 'My custom header');
jsPrintSetup.setOption('headerStrCenter', '');
jsPrintSetup.setOption('headerStrRight', '&PT');

// set empty page footer
jsPrintSetup.setOption('footerStrLeft', '');
jsPrintSetup.setOption('footerStrCenter', '');
jsPrintSetup.setOption('footerStrRight', '');

// clears user preferences always silent print value
// to enable using 'printSilent' option
jsPrintSetup.clearSilentPrint();

// Suppress print dialog (for this context only)
jsPrintSetup.setOption('printSilent', 1);

// Do Print 
// When print is submitted it is executed asynchronous and
// script flow continues after print independently of pletetion of print process! 
jsPrintSetup.print();

// next mands
</script>

The add-on can be found here on Mozilla's add-on site:

https://addons.mozilla/en-US/firefox/addon/js-print-setup/

Never used it myself but Seagull Scientific' BarTender seems like a good solution for direct printing of barcodes. It includes embedded drivers for working with databases such as Oracle, MS SQL, and .NET platform and offers Commander for printing from PHP web apps. Tutorial for printing through PHP apps here http://cases.azoft./bartender-print-server/

发布评论

评论列表(0)

  1. 暂无评论
ok 不同模板 switch ($forum['model']) { /*case '0': include _include(APP_PATH . 'view/htm/read.htm'); break;*/ default: include _include(theme_load('read', $fid)); break; } } break; case '10': // 主题外链 / thread external link http_location(htmlspecialchars_decode(trim($thread['description']))); break; case '11': // 单页 / single page $attachlist = array(); $imagelist = array(); $thread['filelist'] = array(); $threadlist = NULL; $thread['files'] > 0 and list($attachlist, $imagelist, $thread['filelist']) = well_attach_find_by_tid($tid); $data = data_read_cache($tid); empty($data) and message(-1, lang('data_malformation')); $tidlist = $forum['threads'] ? page_find_by_fid($fid, $page, $pagesize) : NULL; if ($tidlist) { $tidarr = arrlist_values($tidlist, 'tid'); $threadlist = well_thread_find($tidarr, $pagesize); // 按之前tidlist排序 $threadlist = array2_sort_key($threadlist, $tidlist, 'tid'); } $allowpost = forum_access_user($fid, $gid, 'allowpost'); $allowupdate = forum_access_mod($fid, $gid, 'allowupdate'); $allowdelete = forum_access_mod($fid, $gid, 'allowdelete'); $access = array('allowpost' => $allowpost, 'allowupdate' => $allowupdate, 'allowdelete' => $allowdelete); $header['title'] = $thread['subject']; $header['mobile_link'] = $thread['url']; $header['keywords'] = $thread['keyword'] ? $thread['keyword'] : $thread['subject']; $header['description'] = $thread['description'] ? $thread['description'] : $thread['brief']; $_SESSION['fid'] = $fid; if ($ajax) { empty($conf['api_on']) and message(0, lang('closed')); $apilist['header'] = $header; $apilist['extra'] = $extra; $apilist['access'] = $access; $apilist['thread'] = well_thread_safe_info($thread); $apilist['thread_data'] = $data; $apilist['forum'] = $forum; $apilist['imagelist'] = $imagelist; $apilist['filelist'] = $thread['filelist']; $apilist['threadlist'] = $threadlist; message(0, $apilist); } else { include _include(theme_load('single_page', $fid)); } break; default: message(-1, lang('data_malformation')); break; } ?>