You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Peter Prusinowski <pe...@gmx.de> on 2016/05/20 13:41:59 UTC
Setting base font from name as string
Hello,
I am trying set a base font from its name as string. In PDType1Font
class, there is a constructor for this purpose: PDType1Font(String
baseFont), but only private accessible.
I also tried with FontMappers class without success. Can anyone help me ?
Thank you
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting base font from name as string
Posted by Peter Prusinowski <pe...@gmx.de>.
Okay, thank you guys
Am 23.05.2016 um 00:08 schrieb John Hewson:
>> On 20 May 2016, at 10:16, Peter Prusi <pe...@gmx.de> wrote:
>>
>> Not exactly. In my case, I dont know which font should be used. I am getting a string which respresents the font name. For example I could make a big switch/case block:
>>
>> switch (fontName) {
>> case "HELVETICA":
>> PDFont font = PDType1Font.HELVETICA;
>> break;
>> \u2026
>> }
> Yes, you should do that.
>
>> with 14 cases, one for each available font, but I think there is a nicer way to do this :-) In 1.8 I could simply pass the font name to PDType1Font constructor, but in 2.0 I dont see this option.
> You could also pass garbage to the PDType1Font constructor and PDFBox would either produce broken PDFs or crash. The above method prevents this.
>
> \u2014 John
>
>> Am 20.05.2016 um 18:44 schrieb Tilman Hausherr:
>>> Just use the static variables, e.g. PDType1Font.HELVETICA. Is this what you had in mind?
>>>
>>> Tilman
>>>
>>> Am 20.05.2016 um 18:42 schrieb Peter Prusi:
>>>> No, I like to use one of the 14 fonts defined in PDType1Font class. In version 1.8 it was possible to pass a font name to the PDType1Font constructor (PDType1Font(String baseFont)) to create a PDType1Font object with given name. In version 2.0 this constructor is private. In 1.8 I see also a function getStandardFont(String name), which returns the PDType1Font object with the passed string.
>>>>
>>>> I am looking for something like this in version 2.0.
>>>>
>>>> Am 20.05.2016 um 17:27 schrieb Tilman Hausherr:
>>>>> Am 20.05.2016 um 15:41 schrieb Peter Prusinowski:
>>>>>> Hello,
>>>>>>
>>>>>> I am trying set a base font from its name as string. In PDType1Font class, there is a constructor for this purpose: PDType1Font(String baseFont), but only private accessible.
>>>>>> I also tried with FontMappers class without success. Can anyone help me ?
>>>>> Could you clarify what you mean with "set a base font from its name as string"?
>>>>>
>>>>> Do you want to use an external font?
>>>>>
>>>>> Tilman
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting base font from name as string
Posted by John Hewson <jo...@jahewson.com>.
> On 20 May 2016, at 10:16, Peter Prusi <pe...@gmx.de> wrote:
>
> Not exactly. In my case, I dont know which font should be used. I am getting a string which respresents the font name. For example I could make a big switch/case block:
>
> switch (fontName) {
> case "HELVETICA":
> PDFont font = PDType1Font.HELVETICA;
> break;
> …
> }
Yes, you should do that.
> with 14 cases, one for each available font, but I think there is a nicer way to do this :-) In 1.8 I could simply pass the font name to PDType1Font constructor, but in 2.0 I dont see this option.
You could also pass garbage to the PDType1Font constructor and PDFBox would either produce broken PDFs or crash. The above method prevents this.
— John
> Am 20.05.2016 um 18:44 schrieb Tilman Hausherr:
>> Just use the static variables, e.g. PDType1Font.HELVETICA. Is this what you had in mind?
>>
>> Tilman
>>
>> Am 20.05.2016 um 18:42 schrieb Peter Prusi:
>>> No, I like to use one of the 14 fonts defined in PDType1Font class. In version 1.8 it was possible to pass a font name to the PDType1Font constructor (PDType1Font(String baseFont)) to create a PDType1Font object with given name. In version 2.0 this constructor is private. In 1.8 I see also a function getStandardFont(String name), which returns the PDType1Font object with the passed string.
>>>
>>> I am looking for something like this in version 2.0.
>>>
>>> Am 20.05.2016 um 17:27 schrieb Tilman Hausherr:
>>>> Am 20.05.2016 um 15:41 schrieb Peter Prusinowski:
>>>>> Hello,
>>>>>
>>>>> I am trying set a base font from its name as string. In PDType1Font class, there is a constructor for this purpose: PDType1Font(String baseFont), but only private accessible.
>>>>> I also tried with FontMappers class without success. Can anyone help me ?
>>>>
>>>> Could you clarify what you mean with "set a base font from its name as string"?
>>>>
>>>> Do you want to use an external font?
>>>>
>>>> Tilman
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting base font from name as string
Posted by Peter Prusi <pe...@gmx.de>.
Exactly, I get some parameters like font name and size from a json file.
So I dont know these at first.
Am 20.05.2016 um 19:39 schrieb Tilman Hausherr:
> But how does it come that you have a name in the first place? It is
> normally a fixed decision to use a specific font when creating a file.
> Or are you creating a file from parameters that are transmitted over a
> network, e.g. in an XML file, that has these names?
>
> Tilman
>
> Am 20.05.2016 um 19:16 schrieb Peter Prusi:
>> Not exactly. In my case, I dont know which font should be used. I am
>> getting a string which respresents the font name. For example I could
>> make a big switch/case block:
>>
>> switch (fontName) {
>> case "HELVETICA":
>> PDFont font = PDType1Font.HELVETICA;
>> break;
>> ...
>> }
>>
>> with 14 cases, one for each available font, but I think there is a
>> nicer way to do this :-) In 1.8 I could simply pass the font name to
>> PDType1Font constructor, but in 2.0 I dont see this option.
>>
>>
>> Am 20.05.2016 um 18:44 schrieb Tilman Hausherr:
>>> Just use the static variables, e.g. PDType1Font.HELVETICA. Is this
>>> what you had in mind?
>>>
>>> Tilman
>>>
>>> Am 20.05.2016 um 18:42 schrieb Peter Prusi:
>>>> No, I like to use one of the 14 fonts defined in PDType1Font class.
>>>> In version 1.8 it was possible to pass a font name to the
>>>> PDType1Font constructor (PDType1Font(String baseFont)) to create a
>>>> PDType1Font object with given name. In version 2.0 this constructor
>>>> is private. In 1.8 I see also a function getStandardFont(String
>>>> name), which returns the PDType1Font object with the passed string.
>>>>
>>>> I am looking for something like this in version 2.0.
>>>>
>>>> Am 20.05.2016 um 17:27 schrieb Tilman Hausherr:
>>>>> Am 20.05.2016 um 15:41 schrieb Peter Prusinowski:
>>>>>> Hello,
>>>>>>
>>>>>> I am trying set a base font from its name as string. In
>>>>>> PDType1Font class, there is a constructor for this purpose:
>>>>>> PDType1Font(String baseFont), but only private accessible.
>>>>>> I also tried with FontMappers class without success. Can anyone
>>>>>> help me ?
>>>>>
>>>>> Could you clarify what you mean with "set a base font from its
>>>>> name as string"?
>>>>>
>>>>> Do you want to use an external font?
>>>>>
>>>>> Tilman
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting base font from name as string
Posted by Tilman Hausherr <TH...@t-online.de>.
But how does it come that you have a name in the first place? It is
normally a fixed decision to use a specific font when creating a file.
Or are you creating a file from parameters that are transmitted over a
network, e.g. in an XML file, that has these names?
Tilman
Am 20.05.2016 um 19:16 schrieb Peter Prusi:
> Not exactly. In my case, I dont know which font should be used. I am
> getting a string which respresents the font name. For example I could
> make a big switch/case block:
>
> switch (fontName) {
> case "HELVETICA":
> PDFont font = PDType1Font.HELVETICA;
> break;
> ...
> }
>
> with 14 cases, one for each available font, but I think there is a
> nicer way to do this :-) In 1.8 I could simply pass the font name to
> PDType1Font constructor, but in 2.0 I dont see this option.
>
>
> Am 20.05.2016 um 18:44 schrieb Tilman Hausherr:
>> Just use the static variables, e.g. PDType1Font.HELVETICA. Is this
>> what you had in mind?
>>
>> Tilman
>>
>> Am 20.05.2016 um 18:42 schrieb Peter Prusi:
>>> No, I like to use one of the 14 fonts defined in PDType1Font class.
>>> In version 1.8 it was possible to pass a font name to the
>>> PDType1Font constructor (PDType1Font(String baseFont)) to create a
>>> PDType1Font object with given name. In version 2.0 this constructor
>>> is private. In 1.8 I see also a function getStandardFont(String
>>> name), which returns the PDType1Font object with the passed string.
>>>
>>> I am looking for something like this in version 2.0.
>>>
>>> Am 20.05.2016 um 17:27 schrieb Tilman Hausherr:
>>>> Am 20.05.2016 um 15:41 schrieb Peter Prusinowski:
>>>>> Hello,
>>>>>
>>>>> I am trying set a base font from its name as string. In
>>>>> PDType1Font class, there is a constructor for this purpose:
>>>>> PDType1Font(String baseFont), but only private accessible.
>>>>> I also tried with FontMappers class without success. Can anyone
>>>>> help me ?
>>>>
>>>> Could you clarify what you mean with "set a base font from its name
>>>> as string"?
>>>>
>>>> Do you want to use an external font?
>>>>
>>>> Tilman
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting base font from name as string
Posted by Peter Prusi <pe...@gmx.de>.
Not exactly. In my case, I dont know which font should be used. I am
getting a string which respresents the font name. For example I could
make a big switch/case block:
switch (fontName) {
case "HELVETICA":
PDFont font = PDType1Font.HELVETICA;
break;
...
}
with 14 cases, one for each available font, but I think there is a nicer
way to do this :-) In 1.8 I could simply pass the font name to
PDType1Font constructor, but in 2.0 I dont see this option.
Am 20.05.2016 um 18:44 schrieb Tilman Hausherr:
> Just use the static variables, e.g. PDType1Font.HELVETICA. Is this
> what you had in mind?
>
> Tilman
>
> Am 20.05.2016 um 18:42 schrieb Peter Prusi:
>> No, I like to use one of the 14 fonts defined in PDType1Font class.
>> In version 1.8 it was possible to pass a font name to the PDType1Font
>> constructor (PDType1Font(String baseFont)) to create a PDType1Font
>> object with given name. In version 2.0 this constructor is private.
>> In 1.8 I see also a function getStandardFont(String name), which
>> returns the PDType1Font object with the passed string.
>>
>> I am looking for something like this in version 2.0.
>>
>> Am 20.05.2016 um 17:27 schrieb Tilman Hausherr:
>>> Am 20.05.2016 um 15:41 schrieb Peter Prusinowski:
>>>> Hello,
>>>>
>>>> I am trying set a base font from its name as string. In PDType1Font
>>>> class, there is a constructor for this purpose: PDType1Font(String
>>>> baseFont), but only private accessible.
>>>> I also tried with FontMappers class without success. Can anyone
>>>> help me ?
>>>
>>> Could you clarify what you mean with "set a base font from its name
>>> as string"?
>>>
>>> Do you want to use an external font?
>>>
>>> Tilman
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting base font from name as string
Posted by Tilman Hausherr <TH...@t-online.de>.
Just use the static variables, e.g. PDType1Font.HELVETICA. Is this what
you had in mind?
Tilman
Am 20.05.2016 um 18:42 schrieb Peter Prusi:
> No, I like to use one of the 14 fonts defined in PDType1Font class. In
> version 1.8 it was possible to pass a font name to the PDType1Font
> constructor (PDType1Font(String baseFont)) to create a PDType1Font
> object with given name. In version 2.0 this constructor is private. In
> 1.8 I see also a function getStandardFont(String name), which returns
> the PDType1Font object with the passed string.
>
> I am looking for something like this in version 2.0.
>
> Am 20.05.2016 um 17:27 schrieb Tilman Hausherr:
>> Am 20.05.2016 um 15:41 schrieb Peter Prusinowski:
>>> Hello,
>>>
>>> I am trying set a base font from its name as string. In PDType1Font
>>> class, there is a constructor for this purpose: PDType1Font(String
>>> baseFont), but only private accessible.
>>> I also tried with FontMappers class without success. Can anyone help
>>> me ?
>>
>> Could you clarify what you mean with "set a base font from its name
>> as string"?
>>
>> Do you want to use an external font?
>>
>> Tilman
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting base font from name as string
Posted by Peter Prusi <pe...@gmx.de>.
No, I like to use one of the 14 fonts defined in PDType1Font class. In
version 1.8 it was possible to pass a font name to the PDType1Font
constructor (PDType1Font(String baseFont)) to create a PDType1Font
object with given name. In version 2.0 this constructor is private. In
1.8 I see also a function getStandardFont(String name), which returns
the PDType1Font object with the passed string.
I am looking for something like this in version 2.0.
Am 20.05.2016 um 17:27 schrieb Tilman Hausherr:
> Am 20.05.2016 um 15:41 schrieb Peter Prusinowski:
>> Hello,
>>
>> I am trying set a base font from its name as string. In PDType1Font
>> class, there is a constructor for this purpose: PDType1Font(String
>> baseFont), but only private accessible.
>> I also tried with FontMappers class without success. Can anyone help
>> me ?
>
> Could you clarify what you mean with "set a base font from its name as
> string"?
>
> Do you want to use an external font?
>
> Tilman
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: Setting base font from name as string
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 20.05.2016 um 15:41 schrieb Peter Prusinowski:
> Hello,
>
> I am trying set a base font from its name as string. In PDType1Font
> class, there is a constructor for this purpose: PDType1Font(String
> baseFont), but only private accessible.
> I also tried with FontMappers class without success. Can anyone help me ?
Could you clarify what you mean with "set a base font from its name as
string"?
Do you want to use an external font?
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org