1

我使用PDF Clown创建包含文本和不同形状的 PDF 文件。保存文件会带来所需的结果。但是当我打印页面或将它们渲染为位图时,只有形状可见并且缺少文本元素。

我已经用多个文件尝试了不同版本的库,总是得到相同的结果。

也许有人可以就这个问题给我一个提示。

编辑:

这是我使用的源代码的简化形式(结果与上述相同;见最后的图片):

File file = new File();

Document document = file.Document;
document.PageSize = PageFormat.GetSize(PageFormat.SizeEnum.A4, PageFormat.OrientationEnum.Portrait);

Page page = new Page(document);
document.Pages.Add(page);

PrimitiveComposer composer = new PrimitiveComposer(page);


//draw a rectangle
composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.LightSalmon));
composer.DrawRectangle(new RectangleF(30, 42, 300, 32));
composer.Fill();


//draw some text
composer.SetFillColor(DeviceRGBColor.Get(System.Drawing.Color.Black));
composer.SetFont(new StandardType1Font(document, StandardType1Font.FamilyEnum.Courier, true, false), 32);
composer.ShowText("Hello World!", new PointF(32, 48));
composer.Flush();


//save the file
file.Save(@"..\document.pdf", SerializationModeEnum.Standard);


//and print it
Renderer renderer = new Renderer();
renderer.Print(file.Document, false);

上述代码的结果(打印版本是用虚拟打印机Adob​​e PDF创建的;也用XPS Document Writer测试过):

在此处输入图像描述

4

1 回答 1

3

(我没有足够的分数来添加评论,所以我将此评论作为答案。)如果您查看 RenderingSample 类的源代码,您将看到以下评论:

此示例演示如何将 PDF 页面呈现为光栅图像。注意:渲染目前处于 pre-alpha 阶段;因此这个样本只不过是一个初始存根(没有假设工作!)。

我不认为 Stephano Chizzolini 有时间完成它。

还有另一个 NuGet 下载,PDFClown.Net 版本 2.0.0,由 Matthieu 提供。它有 PDF-To-Image、Rasterizer 和 PDF 的标签,但我也无法让它工作。我找不到它的文档。检查下载的 NuGET 程序集的属性显示版本 0.1.2.0 而不是 2.0.0。

于 2017-08-11T22:02:36.107 回答