Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9031055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:38:19+00:00 2026-06-16T07:38:19+00:00

I have a strange issue. I’m currently trying myself out with svg generation and

  • 0

I have a strange issue. I’m currently trying myself out with svg generation and I use the following code to generate an svg file:

public class SVGGenerator {

    private static void drawSquare(Graphics2D g2d) {
        g2d.setPaint(Color.blue);
        g2d.setFont(new Font(g2d.getFont().getName(), g2d.getFont().getStyle(), 60));
        g2d.drawString("Ruccc", 200, 64);
        g2d.setFont(new Font(g2d.getFont().getName(), g2d.getFont().getStyle(), 120));
        AffineTransform fontAT = new AffineTransform();

        // get the current font
        Font theFont = g2d.getFont();

        // Derive a new font using a rotatation transform
        fontAT.rotate(Math.PI / 2);
        Font theDerivedFont = theFont.deriveFont(fontAT);

        // set the derived font in the Graphics2D context
        g2d.setFont(theDerivedFont);

        // Render a string using the derived font
        g2d.setPaint(Color.red);
        g2d.drawString("bloody", 200, 64);
        g2d.setPaint(Color.green);
        // put the original font back
        g2d.setFont(new Font(g2d.getFont().getName(), g2d.getFont().getStyle(), 60));
        g2d.drawString("Ruccc", 200, 440);
    }

    public static void GenerateSVG()
    {
        DOMImplementation dom = GenericDOMImplementation.getDOMImplementation();
        Document doc = dom.createDocument(null, "svg", null);
        SVGGraphics2D generator = new SVGGraphics2D(doc);
        drawSquare(generator);
        // Write the generated SVG document to a file
        try {
                FileWriter file = new FileWriter("c://Development//out.svg");
                PrintWriter writer = new PrintWriter(file);
                generator.stream(writer);
                writer.close();
            } catch (IOException ioe) {
                System.err.println("IO problem: " + ioe.toString());
            }
    }    
}

If I run my program with NetBeans, it generates the following:

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" stroke="black" text-rendering="auto" stroke-linecap="square" stroke-miterlimit="10" stroke-opacity="1" shape-rendering="auto" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
  ><g fill="blue" font-size="60" stroke="blue"
    ><text x="200" xml:space="preserve" y="64" stroke="none"
      >Rúccc</text
      ><text x="200" font-size="120" y="64" transform="matrix(0,1,-1,0,264,-136)" fill="red" stroke="none" xml:space="preserve"
      >bloody</text
    ></g
    ><g fill="lime" font-size="60" stroke="lime"
    ><text x="200" xml:space="preserve" y="440" stroke="none"
      >Rúccc</text
    ></g
  ></g
></svg
>

This is shown correctly in the browser. However, if I run it with cmd, the content of the file is as follows:

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" stroke="black" text-rendering="auto" stroke-linecap="square" stroke-miterlimit="10" stroke-opacity="1" shape-rendering="auto" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
  ><g fill="blue" font-size="60" stroke="blue"
    ><text x="200" xml:space="preserve" y="64" stroke="none"
      >Rúccc</text
      ><text x="200" font-size="120" y="64" transform="matrix(0,1,-1,0,264,-136)" fill="red" stroke="none" xml:space="preserve"
      >bloody</text
    ></g
    ><g fill="lime" font-size="60" stroke="lime"
    ><text x="200" xml:space="preserve" y="440" stroke="none"
      >Rúccc</text
    ></g
  ></g
></svg
>

In this case the browser gives me the following error:

XML5617: Illegal XML character. 
out.svg, line 9 character 9

However, if, instead of Rúccc I type Ruccc, everything is fine both from command line and from the browser. I guess that the problem is the presence of the Hungarian character of ú. How can I handle Hungarian characters with svg generation in Java, so that my svg will be generated correctly from command-line? Thanks for any input.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T07:38:20+00:00Added an answer on June 16, 2026 at 7:38 am

    Use the 2 argument form of PrintWriter and specify an appropriate character set that allows Hungarian output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strange issue with my code I can't seem to figure out.
I have a strange issue . I am currently working on a mail app
I have a strange issue with eclipse. When I put a .xls file in
I have some strange issue when trying to apply a conversion from HSI to
I have a strange issue. I'm trying to get Apple Push Notifications working with
I have a strange issue with my css navigation menu. The code is here:
I have a strange issue using HttpWebRequest, I'm trying to post a string to
I have a strange issue trying to run the Facebook iOS SDK DemoApp (from
I have a strange issue with a Widget that I am trying to create.
Hello have following strange issue, can vertical center the menu text if it's one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.