bwip-js icon indicating copy to clipboard operation
bwip-js copied to clipboard

Width text height

Open lublak opened this issue 2 years ago • 8 comments

Hi, ich found your lib :) and its awesome. If i understand correctly i can set the maxheight and width with widht and height and it generates the biggest barcode possible in this size. This is awesome! But I have some issues with text. It looks very strechy. Can i somehow make the text auto resize in the height? So it looks more normal?

grafik

I try to create a barcode with max 200mm width and max 100mm height and render it to a pdf.

lublak avatar Jan 26 '23 13:01 lublak

To generate a barcode without text stretching, set the scale to achieve the desired width. Then adjust the height, For your example, you could start with scale=3 and height=15.

metafloor avatar Jan 26 '23 15:01 metafloor

@metafloor so to get a perfect barcode i need to generate it twice? First to get the default width and hight of the image. As an example 50mm. If i need a 200 width barcode i device it with 50mm (200/50=4) so i get a scale of 4 and i need to generate it again? Or is it possible to get the size without generate it?

lublak avatar Jan 26 '23 23:01 lublak

So for the complete ratio: ratio = Math.min(maxWidth / srcWidth, maxHeight / srcHeight)

I have a simple place in the pdf and here should be the barcode with the maximum size in the available space.

I found the method raw which gets some data. But can I pass the raw to the render function?

lublak avatar Jan 28 '23 01:01 lublak

Are you only generating ISBN barcodes? Because they are fixed format. Or are you looking for a generic solution for different barcode types?

metafloor avatar Jan 31 '23 03:01 metafloor

@metafloor I will not only use ISBNs but all sorts of things. Therefore, I am already looking for a general solution that works for all barcodes. There is always a fixed coordinate and width and height.

lublak avatar Jan 31 '23 09:01 lublak

@metafloor i think there is only the double generation for this or? So it can be closed?

lublak avatar Feb 12 '23 13:02 lublak

Sorry, lost track of this issue. Yes, you will need to double generate. It is the same as with using BWIPP in a postscript environment.

metafloor avatar Feb 12 '23 15:02 metafloor

Sorry, lost track of this issue. Yes, you will need to double generate. It is the same as with using BWIPP in a postscript environment.

@metafloor no problem :) thanks for the answer I can use raw so it doesn't generate to much data. And run it again to generate the pdf image.

lublak avatar Feb 12 '23 15:02 lublak