$title = new Run(); $title->getFont()->setBold(true)->setSize(36); $title->createText($slide_title);
时间: 2024-03-11 07:49:13 浏览: 21
根据代码,我看到问题可能出在 `$title->createText($slide_title);` 这一行。在 PhpOffice\PhpPresentation\Shape\RichText\Run 类中,确实没有 createText() 方法。
建议您将该行代码修改为 `$title->setText($slide_title);`,这样就能将 `$slide_title` 的文本内容设置到 `$title` 对象中了。另外,如果需要更多的样式设置,可以使用 `$title->getFont()->setBold(true)->setSize(36);` 这样的方式来设置字体的加粗和大小。
修改后的代码如下:
```
$title = new Run();
$title->getFont()->setBold(true)->setSize(36);
$title->setText($slide_title);
```
如果问题依然存在,请提供更多的代码信息以便进一步排查。
相关问题
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-36-6da7a0d23674> in <module> 13 height=2500 14 ) ---> 15 wordcloud.fit_words(num)#传入词频 16 17 #展示词云 C:\ProgramData\Anaconda3\lib\site-packages\wordcloud\wordcloud.py in fit_words(self, frequencies) 387 self 388 """ --> 389 return self.generate_from_frequencies(frequencies) 390 391 def generate_from_frequencies(self, frequencies, max_font_size=None): # noqa: C901 C:\ProgramData\Anaconda3\lib\site-packages\wordcloud\wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size) 451 font_size = self.height 452 else: --> 453 self.generate_from_frequencies(dict(frequencies[:2]), 454 max_font_size=self.height) 455 # find font sizes C:\ProgramData\Anaconda3\lib\site-packages\wordcloud\wordcloud.py in generate_from_frequencies(self, frequencies, max_font_size) 506 font, orientation=orientation) 507 # get size of resulting text --> 508 box_size = draw.textbbox((0, 0), word, font=transposed_font, anchor="lt") 509 # find possible places using integral image: 510 result = occupancy.sample_position(box_size[3] + self.margin, C:\ProgramData\Anaconda3\lib\site-packages\PIL\ImageDraw.py in textbbox(self, xy, text, font, anchor, spacing, align, direction, features, language, stroke_width, embedded_color) 565 font = self.getfont() 566 mode = "RGBA" if embedded_color else self.fontmode --> 567 bbox = font.getbbox( 568 text, mode, direction, features, language, stroke_width, anchor 569 ) AttributeError: 'TransposedFont' object has no attribute 'getbbox'
这个错误是因为 `wordcloud` 库的一个 bug,在使用旋转的字体时会出现。具体地说,它是因为 `TransposedFont` 对象没有 `getbbox()` 方法而抛出的 `AttributeError`。
要解决这个问题,你可以在调用 `textbbox()` 方法时,传入 `font.font` 属性而不是 `TransposedFont` 对象本身。例如:
```
box_size = draw.textbbox((0, 0), word, font=transposed_font.font, anchor="lt")
```
这个代码将会使用 `TransposedFont` 对象的 `font` 属性,该属性是一个普通的 `PIL` 字体对象,并且具有 `getbbox()` 方法,因此不会出现 `AttributeError`。
DocumentBuilder builder = new DocumentBuilder(document);builder.getFont();font1.setName("Wingdings 2");
根据你提供的代码,我看到你正在尝试更改字体名称为 "Wingdings 2"。请注意,这并不是设置字体的正确方式。正确的做法是使用系统中已有的字体或者引入自定义字体。以下是一些示例代码:
使用系统中已有的字体:
```
Font font = new Font("Arial", 12);
builder.getFont().setName(font.getName());
```
引入自定义字体:
```
FontSettings fontSettings = new FontSettings();
fontSettings.setFontsFolder("/path/to/fonts/folder", true);
builder.getFontManager().setFontSettings(fontSettings);
Font font = new Font("MyCustomFont", 12);
builder.getFont().setName(font.getName());
```
其中 `/path/to/fonts/folder` 是你自定义字体所在的路径,可以根据实际情况进行修改。你需要将字体文件放在该路径下,并且确保字体文件的格式正确。
请注意,如果你使用了一个不存在的字体名称或者路径不正确,会导致生成的 PDF 文件出现空白方框等问题。因此,请确保你的字体设置正确。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)