0

A more accurate question is Here

I have this dbf database file containing several names and information of employees... and my java application reads rows from this database and prepare some papers (like work certificate...). And where i am from we use special characters in names since it's francophone country. Like for example "Hédia" or "fayçal".. The problem here is that the database contains names with special characters as mentioned, and when printing the papers in question, the characters are not supported and an empty white space is shown instead. I hope i am making myself clear.

So is there a way to programmatically make the printing support these characters?

I know that there's the Locale class in java but i don't know if it is possible to use it for printing purposes.

I hope this problem gets solved and thank you in advance for any help.

Edit: to create the table by the way i'm using a normal table constructor and to add the data to it i'm using a class that fetches the data from the database and returns an Object [], and a for method for this class since it's more than one row.

Here is my printing code for a table (i also wrapped the table printable to format the header and footer):

     final MessageFormat headerFormat = new MessageFormat(builder.toString(), Locale.FRANCE);
         PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
            aset.add(OrientationRequested.LANDSCAPE);
            aset.add(PrintQuality.HIGH);
            Bulletin.print(PrintMode.FIT_WIDTH, headerFormat, null, true, aset, true);

         }catch (PrinterException pe) {
             String s= "Une erreur est survenue lors de l'impression, vérifier que votre imprimante est connectée \n Si le problème persiste, contacter la personne qui s'occupe de votre système";
              JOptionPane.showMessageDialog(Bulletin, s, "Erreur d'impression", 1);

         } catch(IndexOutOfBoundsException e){

             JOptionPane.showMessageDialog(Bulletin, "Aucun bulletin dans la liste. Veuillez au moins ajouter une entrée.\n Pour ajouter une entrée, cliquez sur le menu \"Gérer les Assurances\" puis sur \"Ajouter un Bulletin\".", "Aucun Bulletin selectionné", 1);

         }

To build the textpane it's the default constructor plus a method to fetch the data and add that data to a default text contained in the jtextpane (the type of the JTextPane is html by the way).

And this one is for printing a textpane (it's the default printing method of the JTextPane):

public void print()
{
    MessageFormat headerMessage=new MessageFormat("Header");
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(OrientationRequested.PORTRAIT);
    aset.add(PrintQuality.HIGH);
    try {
        attest.print(headerMessage, null, true, null, aset, true);
    } catch (PrinterException e) {
        e.printStackTrace();
    }
}
Community
  • 1
  • 1
user3610008
  • 79
  • 2
  • 11
  • In Java, all strings are unicode, so that is not the problem per se. Maybe the font doesn't include those characters? A bit of code, showing how you try to print, would be useful. – Erich Kitzmueller Jun 26 '14 at 11:17
  • Okay, just a second :) And thank you. – user3610008 Jun 26 '14 at 11:20
  • @ammoQ check the edit and tell me if i need to add something. thank you – user3610008 Jun 26 '14 at 11:36
  • Just a wild guess, but maybe setting the correct content type (including charset=...) of the JTextPane might solve the problem? – Erich Kitzmueller Jun 26 '14 at 11:44
  • Okay, i'll try that, but could you just give me the right instruction that allows me to do that (I'm sorry, i'm novice when it comes to java :p ). And what about the jtable, i was just trying it to verify if it has the same problem or not, and unfortunately it does but the difference is that in the textpane the "ç" character for example is shown as something really bizarre: "‡" and a blank when it's printed... but for the Jtable it's a little square after the printing and the same as the textpane before printing. (I don't know if this information helps) – user3610008 Jun 26 '14 at 12:20
  • I guess it's either `yourTextPane.setContentType("text/html;charset=utf-8");` or `yourTextPane.setContentType("text/html;charset=iso-8859-15");`, but I might be completely misguided too. – Erich Kitzmueller Jun 26 '14 at 12:26
  • Well... still nothing, i should maybe look up for the right charset on internet? – user3610008 Jun 26 '14 at 12:41
  • @ammoQ I tried both by the way. – user3610008 Jun 26 '14 at 12:49
  • Honestly, I'm out of ideas. Hopefully, somebody else knows the answer. – Erich Kitzmueller Jun 26 '14 at 12:49
  • I hope so too, and by the way, i don't think the problem is related to the character set since in the default text contained in the JtextPane there's special characters like "é" and when i add the character "ç" it prints normally, i think the problem here is related to the database if i'm not mistaken.. But at the same time when i open my .dbf files with MS Access, the characters are shown.. This is complicated.. -_-! – user3610008 Jun 26 '14 at 13:16
  • In this case, you have a database problem, not a printing problem. – Erich Kitzmueller Jun 26 '14 at 13:20
  • Yeah i just figured that out, so i'm going to close this question and ask a more accurate one... – user3610008 Jun 26 '14 at 13:27

0 Answers0