Anything to determine the default paper size based on language?

Is there anything inside Java that I can use out of the box to decide the default paper size based on the language?

I am creating a web application and you need to create a PDF document. Its size can be letter, legal, A4, etc., depending on the locale. From the web application I can get information about the localization of the visitor, such as country, etc.

+5
source share
1 answer

java.awt.PageAttributes has a setMediaToDefault () method that should do just that.

If you consider it javadoc:

The default size for locales in the United States and Canada is MediaType.NA_LETTER. The default size for all other locales is MediaType.ISO_A4.

So, if you want to steal to borrow its implementation:

public void setMediaToDefault(){ String defaultCountry = Locale.getDefault().getCountry(); if (defaultCountry != null && (defaultCountry.equals(Locale.US.getCountry()) || defaultCountry.equals(Locale.CANADA.getCountry()))) { setMedia(MediaType.NA_LETTER); } else { setMedia(MediaType.ISO_A4); } } 
+2
source

Source: https://habr.com/ru/post/1204050/


All Articles