views:

374

answers:

5

We are using the html2ps Perl script to convert HTML to PostScript. I know it's not the best solution but this is what the developers here did (it was before my time).

Now we need to implement support for barcode fonts that is showing each HTML and needs to be shown in each converted PostScript file. How do you do this?

+1  A: 

I find barcodes made up with fonts amounts to a terrible hack. I suggest generating PostScript proper: http://www.terryburton.co.uk/barcodewriter/

daxim
well the problem is that first i generate html with the bar codethen i need to convert it to postscript,how can i do that ...
Vague questions can only get vague answers. Show some code/HTML!
daxim
the code is simple if i use this font : 3Of9Barcode.pfamy html looks like this: <TD style='font-size:30pt;font-family:3 of 9 Barcode'>*Conf123456*</TD>
So you have Code 39, which is supported by Barcode Writer. Read the documentation, input the string `*Conf123456*`, get a PostScript barcode rendering back.
daxim
sorry i didnt understand you , what i need to do ?
Have you read the documentation on the web site I already linked to? If yes, what is unclear? What have you tried so far and what are you having problems with specifically?
daxim
+2  A: 

Hmm, well, the html2ps user guide has a section named "The font block" that states:

Currently, html2ps recognizes the fonts: Times, New-Century-Schoolbook, Helvetica, Helvetica-Narrow, Palatino, Avantgarde, Bookman, and Courier.

It then goes on to explain how one defines a new font type for use in html2ps. Perhaps this could help?

Scott W
yeah i read it and did that , not working . maybe im missing something. i did in in unix
hmm... is there any way for you to render the barcode to an image and then link that image into the html instead of relying on html2ps to render the font properly?
Scott W
i cant use images..
You could try contacting the author of html2ps, but it looks like it is a stagnant project... may need to enhance it to work for your situation yourself.
Scott W
+1  A: 

Maybe you don't need to add barcode support to html2ps, you just have to generate html pages with images of the barcodes you need.

You could use a project like this one to achieve this :barcode-generator or GNU Barcode

Using GNU barcode, this is what I'd do :

  1. Generate the barcode I need in EPS format.
  2. Use imagemagick to convert it to an html friendly format, like PNG
  3. Use the generated image in the html page.

All this seem easily doable/scriptable to me, I can provide more help in that direction if you need.

David V.
See third comment to my answer... @user63898 states "i cant use images.." Maybe the requirements have changed since then...
Scott W
I'm curious why he can't use images.
David V.
I am curious as well.
Scott W
more files to handle and disk space
+3  A: 

Hi,

so what if seen in the comments is:

  1. you cannot use images created before, which are embedded in the html by using an <img />-tag
  2. you cannot include additional fonts to create the barcode (does not work)

To #1: Is not not possible, because you cannot store images? If this is the reason, try using online code creators like barcodesinc, e.g.:

http://www.barcodesinc.com/generator/image.php?code=Hello World&style=197&type=C128B&width=200&height=50&xres=1&font=3

Example:

Barcode2

If you cannot rely on external service providers, there are free classes for your avail for free on the web, e.g. Barcode Generator. Deploy on a web server and use a tag like <img src="http://myserver/myscript.php?code=HelloWorld"/&gt; pointing to this script. html2ps is supporting rendering inline images.

There is also an open source postscript barcode writer available at http://www.terryburton.co.uk/barcodewriter/. After using html2ps you could manipulate the ps files and embed the barcodewriter directive, e.g.:

50 450 moveto (978-1-86074-271) (includetext) /isbn /uk.co.terryburton.bwipp findresource exec

To #2: Could you provide an error message? At which stage do you have problems?

Ehmm... #3: Using only html + css (would only use if all others fail)

Barcodes can be created using simple css and span-elements:

        <style>
        .barcode {
            border:5px solid white;
            background:white;
            width:310px;
            text-align:center;

        }
        .ns{
            border-left:2px solid white;
            height:30;
        }
        .nb{
            border-left:2px solid black;
            height:30;
        }
        .ws{
            border-left:5px solid white;
            height:30;
        }
        .wb{
            border-left:5px solid black;
            height:30;
        }

    </style>
<div class='barcode' id='bcx2_bc' ><span class='nb'></span><span class='ws'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='wb'></span><span class='ws'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ws'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ws'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='wb'></span><span class='ws'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ws'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ws'></span><span class='wb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ws'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ws'></span><span class='nb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ws'></span><span class='nb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='wb'></span><span class='ns'></span><span class='nb'></span><span class='ns'></span><br>TEST8052</div>

Example:

Barcode

This code was created using HTML Bar Codes, also a php class. You could either

  • call this via command line interface and embed it into your normal html for every html-page (for dynamic barcodes)
  • create your code once using cli/server and put it into your html hard coded (only suitable if your barcode shall not change with every html-page)

I cannot image any other possiblities.

henchman
+10  A: 

OK, I've got it working only with fonts (no images, as required). Here is how:

  • Take your barcode font (I know nothing about barcodes, so I took the Code 128 freeware TrueType font; download link).
  • Make it into a Postcript (type 1) font, with extension .pfa. I use fontforge to perform this conversion, like so: open the ttf font, choose File > Generate Fonts, with "PS Type 1 (ASCII), and dismiss possible warnings.
  • So now, I have my font "Code128bWin" in PS Type 1 format in a file named Code128bWin.pfa.
  • Create a minimalistic test document (test.html):
<html>
 <head></head>
 <body>
  <p>This is a test:</p>
  <h4>BARCODE</h4>
 </body>
</html>
  • Create a configuration file (this is what took time to understand; you cannot put it as inline CSS in the HTML; it needs to be a configuration file for html2ps). So, create a file named config:
H4 { font-family: Code128bWin }

@html2ps {
  font {
    Code128bWin {
      names: "Code128bWin";
      files: "Code128bWin.pfa";
    }
  }
}
  • So, text in <h4> tags will be rendered with the codebar font. You now generate the Postscript output by running: html2ps -f config test.html > test.ps

Comments welcome!

As a sidenote: this is clearly ugly, but sometimes it's necessary to hack into an existing process, so I won't judge the OP. I think this solution satisfies all constraints :)

FX
nice solution, +1!
henchman