Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing Avery labels from ASP.NET MVC

I'm trying to dynamically generate and print Avery labels from an ASP.NET MVC 2 application. The labels will be limited to about 5 or so different templates. I am wondering what the best way for doing this is? The Labels are critical to our application and as such, we need to reduce printing error as much as possible.

I have heard I can go for the kludgey approach and make HTML templates, however there will be numerous printing errors. The better approach I've come across is to print to PDF. Are there any pitfalls for this approach and how difficult is it to implement? Also would I go about doing this? Does anyone know of any API's or third party software that would take care of this functionality?

like image 817
James Avatar asked Feb 19 '11 01:02

James


2 Answers

I also struggled with the HTML/CSS approach due to the inconsistent printing behaviour across browsers.

I created a C# library to produce Avery Labels in PDF from ASP.NET which I hope you might find useful:

https://github.com/wheelibin/SharpPDFLabel#readme

You can add images and text to the labels, and it's easy to define more labels types.

(I use it for barcode labels, the barcode is generated as an image and then added to the label using this library.)

Cheers

like image 116
wheelibin Avatar answered Oct 16 '22 05:10

wheelibin


Take a look as CSS Media options. http://www.w3.org/TR/CSS2/media.html

Basically you can target styling to the printer, which can hide all the non essential guff on the page and perform fine tuned layout options.

-- Update: More info on PDF generation:

With PDF's typically you have a PDF engine (and there are a LOT out there) on the server with a template that generates a PDF file, this file is then usually downloaded to the browser via a generic handler. Generating your PDF with an html template on the server should eliminate your browser inconsistencies.

http://www.codeproject.com/KB/aspnet/Creating_PDF_documents_in.aspx

I stumbled on this technique that uses the Razor View Engine to generate PDF's ala MVC, looks promosing.

http://www.emphess.net/2010/11/09/create-high-quality-pdfs-with-razor-view-engine-and-latex/

like image 38
Slappy Avatar answered Oct 16 '22 05:10

Slappy