Closed imamanatee closed 4 years ago
Hi
I can't reproduce the issue, sorry. All is OK for me
I'm experiencing the same issue. For me, it has to do with a non-default pptx template. I don't know what it is about the template that causes this, but the default for adding text using officer is bold (note that when adding a text box directly in powerpoint, however, the default text is not bold) and it is not overridden by using fp_text(bold = FALSE)
.
For a little more detail, I have a slide for which the master is just a header and no content. I first add a header to the slide. Then I add a custom element to the slide using ph_empty_at()
. If I leave the content of this blank and view the result, it shows that it is a placeholder for another header. Using ph_add_par(... type = "body")
on this element doesn't make it act like a body element which doesn't have bold styling, it stays bold even when I explicitly use fp_text(bold = FALSE)
. Is there any way to make ph_empty_at()
be able to specify which type of element it is creating?
Oh sorry I think it looks like you just fixed this here: https://github.com/davidgohel/officer/issues/47
This is the code I used to test this case:
library(magrittr)
library(officer)
style_txt <- fp_text(font.size = 16, bold = FALSE,
font.family = "Calibri", vertical.align = 'baseline')
my_pres <- read_pptx() %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_empty(type = "body") %>%
ph_add_par() %>%
ph_add_text(str = "Title - text", type = "body", style = style_txt) %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_empty_at(left = 1, top = 2, width = 5, height = 4, template_type = "body") %>%
ph_add_par() %>%
ph_add_text(str = "Title - text", type = "body", style = style_txt)
print(my_pres, target = "test.pptx")
Could you show me the code you are using?
Yes sorry I meant to say by my last comment that your latest commit fixed this for me. The ability to specify template_type = "body"
solves the problem, as before then it was using the title template. Although it would seem like fp_text()
should be able to override the boldness of a title template as well.
Although it would seem like fp_text() should be able to override the boldness of a title template as well.
Really sorry, I don't understand. The following code works for me, I made the text red and bold:
library(magrittr)
library(officer)
style_txt <- fp_text(font.size = 16, bold = TRUE, color = "red",
font.family = "Calibri", vertical.align = 'baseline')
my_pres <- read_pptx() %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_empty(type = "body") %>%
ph_add_par() %>%
ph_add_text(str = "Title - text", type = "body", style = style_txt) %>%
add_slide(layout = "Title and Content", master = "Office Theme") %>%
ph_empty_at(left = 1, top = 2, width = 5, height = 4, template_type = "title") %>%
ph_add_par() %>%
ph_add_text(str = "Title - text", type = "title", style = style_txt)
print(my_pres, target = "test.pptx")
Don't you get the same result? test.pptx
I saw this chain is old, but I'm still having the same issue. Here is the code that should reproduce the issue. Use any template that uses bold face font in the title placeholder. When I add a new text placeholder, all of the other control works except for "bold=False".
my_pres <- read_pptx("test_template.pptx")
mytmp <- layout_summary(my_pres)[[2]][1]
style_txt <- fp_text(font.size = 16, bold = FALSE, color = "red",
font.family = "Calibri")
my_pres <- my_pres %>%
add_slide(layout = "Title and Content", master = mytmp) %>%
ph_with("Bold as expected", location=ph_location_type("title")) %>%
ph_empty(location = ph_location(left = 1, top = 2, width = 5, height = 2, label = "new")) %>%
ph_add_par(ph_label = "new") %>%
ph_add_text(str = "shouldn't be bold", ph_label = "new", style = style_txt)
print(my_pres, target = "test.pptx")
Is there anything wrong with the code? Thanks.
I don't think I ever got that bold function to disable properly...
I think it is solved now:
library(officer)
library(magrittr)
my_pres <- read_pptx()
style_bold <- fp_text(font.size = 16, bold = TRUE, color = "red",
font.family = "Calibri")
style_notbold <- fp_text(font.size = 16, bold = FALSE, color = "red",
font.family = "Calibri")
my_pres <- my_pres %>%
add_slide(layout = "Title and Content") %>%
ph_with(empty_content(), location = ph_location(left = 1, top = 2, width = 5, height = 2, newlabel = "new") ) %>%
ph_add_par(ph_label = "new") %>%
ph_add_text(str = "should be bold", ph_label = "new", style = style_bold) %>%
ph_add_par(ph_label = "new") %>%
ph_add_text(str = "shouldn't be bold", ph_label = "new", style = style_notbold)
print(my_pres, target = "test.pptx")
Hi, I came across the same issue (working with officer 0.3.8). Your example above is working perfectly, but if I use my own template (attached), both text are bold and I can't figure out how to input no bold text without creating predefined placeholder in the template.
I figured out that this behaviour is emerging when the titles in presentation template are set to bold (same issue as JW900 was reporting earlier in this thread)
`my_pres <- read_pptx("PATH_TO_MY_TEMPLATE_PPTX") layout_summary(my_pres)
style_bold <- fp_text(font.size = 16, bold = TRUE, color = "red", font.family = "Calibri") style_notbold <- fp_text(font.size = 16, bold = FALSE, color = "red", font.family = "Calibri")
my_pres <- my_pres %>% add_slide(layout = "title and graph", master = "My template") %>% ph_with(empty_content(), location = ph_location(left = 1, top = 2, width = 5, height = 2, newlabel = "new") ) %>% ph_add_par(ph_label = "new") %>% ph_add_text(str = "should be bold", ph_label = "new", style = style_bold) %>% ph_add_par(ph_label = "new") %>% ph_add_text(str = "shouldn't be bold", ph_label = "new", style = style_notbold)
print(my_pres, target = "test.pptx")`
I have the same issue as @matyas-k. If the title in the layout is set to bold, the bold setting for any text paragraphs could not be overwritten, all texts are bold.
I have investigated the issue a bit. Looks like bold = FALSE
option doesn't have any effect on a:rPr
node of the paragraph and the bold setting is inherited from the a:defRPr
node from the layout. For example:
(slide)
<p:txBody>
<a:bodyPr/>
<a:lstStyle/>
<a:p>
<a:pPr algn="l" marL="0" marR="0">
<a:spcBef>
<a:spcPts val="0"/>
</a:spcBef>
<a:spcAft>
<a:spcPts val="0"/>
</a:spcAft>
<a:buNone/>
</a:pPr>
<a:r>
<a:rPr cap="none" sz="1000">
<a:solidFill>
<a:srgbClr val="070707">
<a:alpha val="100000"/>
</a:srgbClr>
</a:solidFill>
<a:latin typeface="Calibri"/>
<a:cs typeface="Calibri"/>
</a:rPr>
<a:t>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</a:t>
</a:r>
</a:p>
</p:txBody>
(layout)
<p:txBody>
<a:bodyPr wrap="square" anchor="t">
<a:spAutoFit/>
</a:bodyPr>
<a:lstStyle>
<a:lvl1pPr>
<a:lnSpc>
<a:spcPct val="80000"/>
</a:lnSpc>
<a:defRPr sz="2400" b="1">
<a:solidFill>
<a:schemeClr val="accent6"/>
</a:solidFill>
</a:defRPr>
</a:lvl1pPr>
</a:lstStyle>
<a:p>
<a:r>
<a:rPr dirty="0"/>
<a:t>Title</a:t>
</a:r>
</a:p>
</p:txBody>
The result is b="1"
is inherited from the layout. The strange thing is this property is always inherited from the title (the first text chunk in the layout?) and not following text paragraphs, but I'm not good in OOXML so let it be.
But when bold = TRUE
the b="1"
attribute is added to the a:rPr
node and all is fine. May be it is possible to force set b="0"
when bold = FALSE
?
(slide)
<p:txBody> ... <a:r> <a:rPr cap="none" sz="1000" b="1"> ... </a:rPr> <a:t>Lorem ipsum ...</a:t> </a:r> </a:p> </p:txBody>
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.
Hi there,
I am really enjoying using the functions you created. I have a question though, when I try to use the "bold = FALSE" parameter in fp_text, it ignores it and still prints my text in bold. Is this a bug or am I not using it correctly?
my_pres <- ph_add_text(my_pres,str = "Title - text",style=fp_text(font.size = 16, bold = FALSE,font.family="Calibri", vertical.align = 'baseline'))