简体   繁体   English

段落中的MigraDoc图像-不完整的文件路径

[英]MigraDoc Images in a Paragraph - not Full File Path

I want to display an image within a paragraph in MigraDoc. 我想在MigraDoc的段落中显示图像。 So far, the examples I have found have all required the full file path to reference the image file: 到目前为止,我发现的示例都需要完整的文件路径来引用图像文件:

answerParagraph.AddImage("C:\Project\Images\Image.png")

However I want to use some kind of relative path or namespace reference. 但是我想使用某种相对路径或名称空间引用。 Or even an actual Image Object. 甚至是实际的图像对象。 Anything but the full file path. 除了完整的文件路径外,什么都没有。

The PDF renderer allows to set a working directory (property WorkingDirectory in class PdfDocumentRenderer ). PDF渲染器允许设置工作目录(类PdfDocumentRenderer属性WorkingDirectory )。 I think the same applies to the RTF renderer. 我认为RTF渲染器也是如此。

Searches for files with relative path will start from this working directory. 搜索具有相对路径的文件将从此工作目录开始。

The samples you can download for MigraDoc all use relative paths. 您可以为MigraDoc下载的示例均使用相对路径。 One example: 一个例子:
http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx http://pdfsharp.net/wiki/HelloMigraDoc-sample.ashx

Image image = section.AddImage("../../images/Logo landscape.png");

I don't know which samples you looked at - but requiring absolute paths would not be comfortable for sample code that should compile and work anywhere the user unzips it. 我不知道您查看的是哪个示例-但是要求绝对路径对于应该在用户解压缩的任何地方都可以编译和工作的示例代码不满意。

You can also pass the binary data of the image in a pseudo-filename (PDF renderer only). 您还可以使用伪文件名(仅PDF渲染器)传递图像的二进制数据。 See also: 也可以看看:
http://pdfsharp.net/wiki/MigraDoc_FilelessImages.ashx http://pdfsharp.net/wiki/MigraDoc_FilelessImages.ashx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM