Hello,
I've developed a ruby RGhost program that generates barcodes and text.
I've written it when I was on Ubuntu, and now, I want to make it work
on Windows.
But when I execute the file, there's some trouble :
C:\Documents and Settings\Administrateur\Bureau>ruby zcb.rb
c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
ruby_ghost_config.rb:67:in `iconv': invalid encoding ("latin1",
"utf8") (Iconv::InvalidEncoding)
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
ruby_ghost_config.rb:67
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
ruby_to_ps.rb:16:in `call'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
ruby_to_ps.rb:16:in `pack_string'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
ruby_to_ps.rb:7:in `to_string'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
parse_text.rb:45:in `ta_entry'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
parse_text.rb:32:in `text_to_ps'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
parse_text.rb:29:in `each'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
parse_text.rb:29:in `text_to_ps'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
parse_text.rb:27:in `map'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
parse_text.rb:27:in `text_to_ps'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
text.rb:37:in`ps'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
ps_object.rb:41:in `set'
from c:/ruby/lib/ruby/gems/1.8/gems/rghost-0.8/lib/rghost/
ps_facade.rb:166:in `text'
from zcb.rb:55:in `creeCodeBarre'
from zcb.rb:146
from zcb.rb:142:in `foreach'
from zcb.rb:142
I really don't know why it bugs, because on Ubuntu there isn't any
problem...
Here's my code :
require 'rubygems'
require 'rghost'
require 'rghost_barcode'
include RGhost
def creeCodeBarre (ligneFichier)
# Initiation des variables lues dans le fichier, forme :
# num_finess ; nomES ; numService ; libelleService ; rpps_chef ;
nomChef ; rpps_prescripteur ; nomPrescripteur
num_finess=ligneFichier[0]
nomES=ligneFichier[1]
numService=ligneFichier[2]
libelleService=ligneFichier[3]
rpps_chef=ligneFichier[4]
nomChef=ligneFichier[5]
rpps_prescripteur=ligneFichier[6]
nomPrescripteur=ligneFichier[7]
nomPrescripteur = nomPrescripteur.chomp
x_finess=20
y_finess=3
rotation_finess=90
hauteur_finess=1
x_rpps_prescripteur=20
y_rpps_prescripteur=22
rotation_rpps_prescripteur=90
hauteur_rpps_prescripteur=1
x_chefService=20
y_chefService=12
rotation_chefService=90
hauteur_chefService=1
doc=Document.new
texteInfos = 'num_finess : ' + num_finess + '<br/>nomES : ' + nomES +
'<br/>numService : ' + numService + '<br/>libelleService : ' +
libelleService + '<br/>rpps_chef : ' + rpps_chef + '<br/>nomChef : ' +
nomChef + '<br/>rpps_prescripteur : ' + rpps_prescripteur + '<br/
>nomPrescripteur : ' + nomPrescripteur
doc.text texteInfos
doc.define_tags do
tag :font1, :name => 'Times', :size => 10, :encoding => true
end
#-------------
# Génération du code barre Finess si le numéro Finess existe
if num_finess != ''
doc.barcode_code128('^105 ' + num_finess,
:x => x_finess,
:y=> y_finess,
:text=>{:size=>10},
:height => hauteur_finess,
:rotate => rotation_finess)
# Ecriture de "Numéro Finess" au dessus du code barre
doc.moveto :x => (x_finess-1.1), :y => (y_finess+0.5)
doc.rotate 90
doc.show("Numero Finess", :with => :font1)
doc.rotate -90
end
#-------------
#-------------
# Génération du code barre du chef de service si le rpps_chef
existe
if rpps_chef != ''
doc.barcode_code128('^105 ' + rpps_chef,
:x => x_chefService,
:y=> y_chefService,
:text=>{:size=>10},
:height => hauteur_chefService,
:rotate => rotation_chefService)
# Pour un numéro RPPS, la zone de texte où écrire s'étend de
y_chefService à y_chefService+3.5, et un caractère = 0.15 de largeur
milieu=1.75
largeurNomEnCaracteres=nomChef.size
largeurNomEnCm=largeurNomEnCaracteres*0.15
pointDeDepart=milieu-largeurNomEnCm/2
# Ecriture du nom du chef de service au dessus du code barre
doc.moveto :x => (x_chefService-1.1), :y => (y_chefService
+pointDeDepart)
doc.rotate 90
doc.show(nomChef, :with => :font1)
doc.rotate -90
end
#-------------
#-------------
# Génération du code barre RPPS du prescripteur si
rpps_prescripteur existe
if rpps_prescripteur != ''
doc.barcode_code128('^105 ' + rpps_prescripteur,
:x => x_rpps_prescripteur,
:y=> y_rpps_prescripteur,
:text=>{:size=>10},
:height => hauteur_rpps_prescripteur,
:rotate => rotation_rpps_prescripteur)
# Pour un numéro RPPS, la zone de texte où écrire s'étend de
y_chefService à y_chefService+3.5, et un caractère = 0.15 de largeur
milieu=1.75
largeurNomEnCaracteres=nomPrescripteur.size
largeurNomEnCm=largeurNomEnCaracteres*0.15
pointDeDepart=milieu-largeurNomEnCm/2
# Ecriture du nom du professionnel au dessus du code barre
doc.moveto :x => (x_rpps_prescripteur-1.1), :y =>
(y_rpps_prescripteur+pointDeDepart)
doc.rotate 90
doc.show(nomPrescripteur, :with => :font1)
doc.rotate -90
end
#-------------
# Remplacement des éventuels espaces par des points dans
nomPrescripteur
nomPrescripteur = nomPrescripteur.gsub(' ', '.')
nomDuFichier = rpps_prescripteur.to_s + '.' + nomPrescripteur +
'.pdf'
doc.render :pdf, :filename => nomDuFichier
#-------------
end
IO.foreach("tst.txt") { |block|
ligneFichier = block.split(' ; ')
creeCodeBarre(ligneFichier)
}
Thanks for your help.