You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Michael Gentry <mg...@masslight.net> on 2010/08/17 21:32:00 UTC
Problem with PowerPoint fonts
Hi everyone,
I'm trying to use POI to read in a PowerPoint template and do textual
substitution in the template to create a new PowerPoint. Everything
is working fine except that some of the text fonts and point sizes do
not open correctly. When I substitute the text, I don't change the
font name or size, just do text substitutions. However, it is somehow
changing Calibri 11pt in the template to Arial 24pt in the generated
PowerPoint.
Does anyone know what would cause the fonts to change in the
new/generated document?
Thanks,
mrg
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Problem with PowerPoint fonts
Posted by mikki <mi...@mail.ru>.
Hi Michael.
The final newline does have some magical effect on the font size.
I have to remove him forcibly.
May be bugs.
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Problem-with-PowerPoint-fonts-tp2638655p2643206.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Problem with PowerPoint fonts
Posted by Michael Gentry <mg...@masslight.net>.
If this helps anyone, I think I found my problem.
The data was coming from an HTML TEXTAREA and had a trailing newline.
Calling setText with the trailing newline somehow blew the fonts
apart. I'm now calling StringUtils.trimToEmpty() on the string I
actually set and it keeps the fonts now.
This seems like a bug to me. Do others agree?
Thanks,
mrg
On Wed, Aug 18, 2010 at 10:25 AM, Michael Gentry <mg...@masslight.net> wrote:
> Hi Mikki and others,
>
> I'm actually only dealing with one SlideShow which I read in from disk
> (it is a template). I search for substitution text and replace it
> (kind of like Velocity) and then save the template back out under a
> new name.
>
> The core of my code that does the substitution is:
>
> // Loop over all the shapes in the slide to replace the substitution text.
> for (Shape shape : slide.getShapes())
> {
> if (shape instanceof TextBox)
> {
> TextBox textBox = (TextBox) shape;
>
> // Get the candidate substitution text.
> String substitutionText = textBox.getText();
>
> // If the substitution text matches a key in the substitution
> map, replace it.
> if (substitutionMap.containsKey(substitutionText))
> textBox.setText(substitutionMap.get(substitutionText) ==
> null ? "" : substitutionMap.get(substitutionText));
> }
> }
>
> All I'm doing is setting the text to values. I'm not changing the
> font name or font size, but for some reason when I save the SlideShow,
> some of my TextBoxes (not all) have changed to Arial 24pt (and I don't
> use Arial anywhere in the template, only Calibri). I'd have expected
> only the text to change, but for some reason more is changing and I
> don't know why.
>
> Any ideas would be appreciated.
>
> Thanks,
>
> mrg
>
>
> On Wed, Aug 18, 2010 at 3:15 AM, mikki <mi...@mail.ru> wrote:
>>
>> Hi!
>>
>> May help you this code
>>
>> SlideShow write_SlideShow = new SlideShow( new HSLFSlideShow( "New_File.ppt"
>> ) );
>> SlideShow read_SlideShow = new SlideShow( new HSLFSlideShow( "Old_File.ppt"
>> ) );
>> // Add Font
>> for (int k=0; k < read_SlideShow.getNumberOfFonts(); k++){
>> PPFont rf=read_SlideShow.getFont(k);
>> int j=0;
>> for (j=0; j < write_SlideShow.getNumberOfFonts(); j++){
>> if (rf.equals(write_SlideShow.getFont(j))){
>> break;
>> }
>> }
>> if (j>=write_SlideShow.getNumberOfFonts()){
>> write_SlideShow.addFont(rf);
>> }
>> }
>>
>> --
>> View this message in context: http://apache-poi.1045710.n5.nabble.com/Problem-with-PowerPoint-fonts-tp2638655p2639025.html
>> Sent from the POI - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Problem with PowerPoint fonts
Posted by Michael Gentry <mg...@masslight.net>.
Hi Mikki and others,
I'm actually only dealing with one SlideShow which I read in from disk
(it is a template). I search for substitution text and replace it
(kind of like Velocity) and then save the template back out under a
new name.
The core of my code that does the substitution is:
// Loop over all the shapes in the slide to replace the substitution text.
for (Shape shape : slide.getShapes())
{
if (shape instanceof TextBox)
{
TextBox textBox = (TextBox) shape;
// Get the candidate substitution text.
String substitutionText = textBox.getText();
// If the substitution text matches a key in the substitution
map, replace it.
if (substitutionMap.containsKey(substitutionText))
textBox.setText(substitutionMap.get(substitutionText) ==
null ? "" : substitutionMap.get(substitutionText));
}
}
All I'm doing is setting the text to values. I'm not changing the
font name or font size, but for some reason when I save the SlideShow,
some of my TextBoxes (not all) have changed to Arial 24pt (and I don't
use Arial anywhere in the template, only Calibri). I'd have expected
only the text to change, but for some reason more is changing and I
don't know why.
Any ideas would be appreciated.
Thanks,
mrg
On Wed, Aug 18, 2010 at 3:15 AM, mikki <mi...@mail.ru> wrote:
>
> Hi!
>
> May help you this code
>
> SlideShow write_SlideShow = new SlideShow( new HSLFSlideShow( "New_File.ppt"
> ) );
> SlideShow read_SlideShow = new SlideShow( new HSLFSlideShow( "Old_File.ppt"
> ) );
> // Add Font
> for (int k=0; k < read_SlideShow.getNumberOfFonts(); k++){
> PPFont rf=read_SlideShow.getFont(k);
> int j=0;
> for (j=0; j < write_SlideShow.getNumberOfFonts(); j++){
> if (rf.equals(write_SlideShow.getFont(j))){
> break;
> }
> }
> if (j>=write_SlideShow.getNumberOfFonts()){
> write_SlideShow.addFont(rf);
> }
> }
>
> --
> View this message in context: http://apache-poi.1045710.n5.nabble.com/Problem-with-PowerPoint-fonts-tp2638655p2639025.html
> Sent from the POI - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: Problem with PowerPoint fonts
Posted by mikki <mi...@mail.ru>.
Hi!
May help you this code
SlideShow write_SlideShow = new SlideShow( new HSLFSlideShow( "New_File.ppt"
) );
SlideShow read_SlideShow = new SlideShow( new HSLFSlideShow( "Old_File.ppt"
) );
// Add Font
for (int k=0; k < read_SlideShow.getNumberOfFonts(); k++){
PPFont rf=read_SlideShow.getFont(k);
int j=0;
for (j=0; j < write_SlideShow.getNumberOfFonts(); j++){
if (rf.equals(write_SlideShow.getFont(j))){
break;
}
}
if (j>=write_SlideShow.getNumberOfFonts()){
write_SlideShow.addFont(rf);
}
}
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Problem-with-PowerPoint-fonts-tp2638655p2639025.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org