0

We currently generate our own barcodes and generate a page using the barcode images; however, we also want to print these barcodes onto a template. So far we have tried simply matching the margins and spacing (with CSS) using the measurements in the template above, but each browser is just too inconsistent. Does anyone have an idea how this can be done, preferably on the client side?

Josh Mein
  • 28,107
  • 15
  • 76
  • 87
bjohnson
  • 301
  • 5
  • 15
  • 3
    Don't use HTML. Generate a PDF on the fly. – Tim Mar 02 '15 at 18:26
  • 1
    Duplicate: [Printing Labels from ASP.Net Page](http://stackoverflow.com/q/164197/2033671) –  Mar 02 '15 at 18:29
  • @Tim May I ask the best way of generating the PDF on the fly? I have looked into jsPDF but I was having troubles matching the template sizes/margins using it. – bjohnson Mar 02 '15 at 18:29
  • 1
    There are a ton of these server-side, but I can't tell what you're using based on the tags. Xml/XSLT is one option, another may be changing the MIME type on the output as it's streamed to the client. You may want to Google "PDF generator" for your particular technology. These have been around a long time - when I started in the business you had to pay for them, but you can probably find one free these days... – Tim Mar 02 '15 at 18:32
  • "What is the easiest solution [...]?" This is an opinionated question; whatever is easiest is whatever you are most familiar with. – TylerH Mar 02 '15 at 18:36
  • @TylerH I have reworded the question so it is not opinionated. – bjohnson Mar 02 '15 at 19:37
  • @bjohnson Unfortunately that's still too broad. Stack Overflow is a site for *specific* programming problems/questions. "Does anyone have a solution" is basically asking us to write the code for you. An appropriate question will have a minimal example of existing code, a clear desired outcome, and a clear error and explanation as to how the erroneous code differs from the desired outcome. – TylerH Mar 02 '15 at 19:41
  • 1
    @TylerH - the question was answered successfully by just pointing them to a different printing technology that is designed for typographic consistency. This is a technology question and doesn't look like it's primarily opinion-based to me. I voted to reopen (don't understand why people are so quick to jump on closing questions rather than guiding the question to be improved). – jfriend00 Mar 02 '15 at 23:17
  • @TylerH - One more thing. just look at the accepted answer. It doesn't appear to be primarily opinion-based so obviously a useful answer can be provided that is NOT primarily opinion-based. That alone should be proof that this is NOT a case of "answers to this question will tend to be almost entirely based on opinion". People are too quick to close just because they ask for the best solution to a problem. Just because opinion COULD be used in an answer doesn't mean that good answers will not or cannot be provided that are primarily based on other things. Question should be reopened. – jfriend00 Mar 02 '15 at 23:29
  • @TylerH If I was looking for a full fledged block of code ready to copy and paste I would have asked for it. Stack Overflow is simply a Q & A for programming related questions. Although I thought your first comment was unnecessary, I still edited the question so it wasn't "opinionated". The description under a question is where specifics are to be defined, as I did. – bjohnson Mar 03 '15 at 02:26
  • @jfriend00 Whether the question can be answered or not is not the reason for closure. Opinionated questions can have answers that completely answer the question, but that doesn't mean the question is not one of opinion. bjohnson is asking for a recommendation for a tool or method for solving a problem, which, pre-edit, was 100% an opinionated question. Post-edit, it's still asking for a recommendation of a tool or resource, and is still too broad to be on-topic (does *anyone* have *any* idea?). This site is for *specific* questions that have *specific* answers. Question should remain closed. – TylerH Mar 03 '15 at 04:13
  • @bjohnson Unfortunately you're just incorrect on that point; the site is more than "a Q&A for programming-related questions". You don't have to like the rules and guidelines, but they are there. What you're looking for is irrelevant. What matters is the question you ask, and yours was too broad, too opinionated, and off-topic. – TylerH Mar 03 '15 at 04:15
  • And, by the looks of it, a duplicate of the question linked above as well. Four close reasons! – TylerH Mar 03 '15 at 04:16
  • @TylerH - there's no request for a tool or resource anywhere in the question (you seem to have inferred something that simply isn't there). They are asking how to solve a problem. I can't believe that type of question is considered off-topic here. Absolutely silly. Why don't we err on the side of helping people rather than over policing borderline questions? Geez. There's zero damage done to this site by leaving questions like this one open and letting more people supply answers. I'm fine with closing for a dup if it's a legitimate dup that actually contains a good, relevant answer. – jfriend00 Mar 03 '15 at 04:30
  • @TylerH - It turns out there is a very specific, non-opinionated answer to this question and it's the same answer in the question Austin linked. So, you're just missing the boat by continuing to defend the fact that this question is off-topic because it's opinionated or too broad. It's not. It turns out it is a dup, but there's nothing, other than that, wrong with the question as it stands now. – jfriend00 Mar 03 '15 at 04:35
  • @jfriend00 "Does anyone have an idea how this can be done, preferably on the client side?" is a request for a resource. As for missing the boat, the community decided otherwise, as seen by the status of this question; seems like you're the one missing the boat my friend. This question, pre-edit (it's had two), was very opinionated. Post-edit, it's still a dupe, and still too broad. General, "how to do x" questions are typically and consistently not viewed as on-topic at Stack Overflow. They were in the past, of course, not anymore. – TylerH Mar 03 '15 at 05:00
  • @Tyler, you're inferring a request for a resource. They're asking "how" to solve a problem. They didn't ask for a tool or resource and the accepted answer didn't provide one. Those words you claim are simply not there. – jfriend00 Mar 03 '15 at 05:28
  • @TylerH - There is often a "herd" mentality with close votes - that doesn't mean the herd is always right. We should challenge this when it isn't in the best interests of the overall community and doesn't violate any rules. Far, far too many questions are (unfortunately) closed as opinionated just because the question includes the word "best". There's no ban or rule against using that word. There's only a ban on questions that lead to answers that "will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise". "Best" can use facts or references. – jfriend00 Mar 03 '15 at 05:31
  • @jfriend00 An *answer* to a request for the "best" can include facts and references, definitely. To call something the "best", though, is always opinion, because it depends on what you're measuring. And there's hardly any "best"s in library or tool or method choices... some people may find it easier to do it one way, so that way's best. Other people might find a different way easier/smarter/more intuitive, and therefore the best. – TylerH Mar 03 '15 at 16:34
  • @TylerH - many, many, many excellent answers here contain some opinion (and StackOverflow acknowledges that that is OK). The question is only whether the answer is "primarily opinion" or whether it's an opinion based on "facts, references and specific expertise". When it comes right down to it, we all want to hear the opinions of folks well educated on an issue. We want them to explain the facts and share the conclusion they draw (their opinion) from those facts. That's the fastest way for us to learn. We want them to share what they think is the "best" way to solve a problem. – jfriend00 Mar 03 '15 at 21:45

1 Answers1

3

The PDF format was created to create typographically consistent output. The browser was not created with that goal in mind and today's browsers are simply not designed to do that.

You can generate a PDF and let your user print that.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • After reading more into the documentation for jsPDF, I was able to recreate the template we are using and generating it into a PDF. That is why I chose this answer. – bjohnson Mar 02 '15 at 19:38
  • 1
    @bjohnson If you were able to come up with a solution on your own, it is better to create your own answer that explains how you resolved the problem. This allows other users to see exactly what helped you. – Josh Mein Mar 02 '15 at 20:17