标签: pdfsharp

GetFontData在ASP.NET App中返回-1(GDI_ERROR),但在控制台应用程序中不返回.什么可能导致这个?

我们在我们的一个Web应用程序中使用PDFSharp(GDI + build).在一个PDF导出器中,我们使用非系统truetype字体,它在我们的开发环境中就像一个魅力,但是当我们在生产中运行它时会崩溃.

我们的开发和生产之间的关键区别(我认为)是我们的生产服务器在Windows Server 2008 64bit上运行,而我们的开发运行在2008 32bit.我写了一个很小的测试程序来调试.

try
{
    new XFont("ocrb10", 10, XFontStyle.Regular, new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always));
}
catch (Exception exc) { Console.WriteLine(exc.StackTrace); }
Run Code Online (Sandbox Code Playgroud)

错误消息是InvalidOperationException:内部错误.无法检索字体数据.

at PdfSharp.Fonts.OpenType.FontData.CreateGdiFontImage(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.FontData..ctor(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font, XPdfFontOptions options)
at PdfSharp.Fonts.OpenType.OpenTypeDescriptor..ctor(XFont font)
at PdfSharp.Fonts.FontDescriptorStock.CreateDescriptor(XFont font)
at PdfSharp.Drawing.XFont.get_Metrics()
at PdfSharp.Drawing.XFont.Initialize()
at PdfSharp.Drawing.XFont..ctor(String familyName, Double emSize, XFontStyle style, XPdfFontOptions pdfOptions)
Run Code Online (Sandbox Code Playgroud)

我从源代码构建了PDFSharp并添加了一些调试代码,以便了解发生了什么.问题是对GetFontData的pinvoke调用返回-1(GDI_ERROR).PdfSharp作者在FontData.cs中添加了有关此错误的注释,其中发生错误(搜索GDI_ERROR)但他也找不到合适的解决方案.

// Line 138 in FontData.cs, this GetFontData returns -1 here when 
// running as a web …
Run Code Online (Sandbox Code Playgroud)

c# asp.net pinvoke pdfsharp 32bit-64bit

4
推荐指数
1
解决办法
1582
查看次数

更改PDF - 文本重新定位

有没有办法将现有pdf页面内的文本移动/移动到其他位置

就像在区域x = 100处有一些文本,y = 100,w = 100,h = 100并且我想将其移动到x = 50,y = 200,w = 100,h = 100.

我做了很多研究,似乎iTextSharp做不到.PDFSharp声称它可以完成,但我找不到任何例子.

一种方法是制作我想要移动的文本的特定区域的位图,在该区域上绘制白色矩形并在新位置插入位图.我不想使用这个解决方案,因为我使用超过1K页面的大型pdf文件,其中每个页面都必须被更改.

我发现的是,我需要找到一种方法来改变文本定位操作符(文本矩阵和文本状态参数),这并不是那么简单.

有人有什么想法吗?

c# pdf pdfsharp itextsharp

4
推荐指数
1
解决办法
2万
查看次数

处理这些PDFSharp表限制的最佳方法是什么?

我正在使用PDFSharp将表导出为PDF(使用常规MigraDoc.DocumentObjectModel.Tables.Table对象).它运行得很好,除了我遇到了一些问题:

  1. 如果表格中单个单元格的内容长于页面的高度,则内容就会被切断.一个表本身可以跨越多个页面,但是一行似乎只能是1页高,看起来它不会延伸到下一页.

有没有解决方法或者这只是库中的错误?

  1. 对于跨越多个页面的表,是否有办法让表格上的标题行显示在每个页面的顶部?

c# pdf pdfsharp migradoc

4
推荐指数
1
解决办法
5715
查看次数

为什么PdfSharp在Web链接上创建边框?

我有以下功能来使用PdfSharp创建一个weblink:

    public static void AddWebLink(XGraphics gfx, PdfPage page, XFont font, string url, string text, int startX, int startY)
    {
        if (gfx == null)
            throw new ArgumentNullException("gfx");

        if (page == null)
            throw new ArgumentNullException("page");

        if (font == null)
            throw new ArgumentNullException("font");

        // Write out the text
        gfx.DrawString(text, font, XBrushes.Blue, new PointF(startX, startY));
        var stringSize = gfx.MeasureString(text, font);

        // Create the linked area
        // For some reason the Y of the rectangle needs to be startY minus the height
        startY -= (int)stringSize.Height; …
Run Code Online (Sandbox Code Playgroud)

c# pdfsharp

4
推荐指数
1
解决办法
2692
查看次数

如何在PDFsharp中获取XGraphics类

我正在使用PDFsharp生成pdf,但我无法使用XGraphics类.有人可以告诉我如何使用XGraphics类或我需要在我的应用程序中添加的dll和命名空间是什么.实际上我必须在我的dll的页眉和页脚中画一条线,并在链接http://www.pdfsharp.net/wiki/Graphics-sample.ashx#Draw_simple_lines_0上有一个方法DrawLine()使用XGraphics我无法找到的课程.

pdf pdfsharp

4
推荐指数
1
解决办法
5128
查看次数

使用 PDFSharp 将文本转换为 PDF

我想使用 PDFsharp 将文本文件转换为 PDF。应该采取什么方法?甚至有可能吗?我正在使用 C#.net 开发 Web 应用程序

converter pdfsharp

4
推荐指数
2
解决办法
6018
查看次数

在MigraDoc-WPF中使用section.AddImage()后释放锁定图像文件

我有以下代码生成报告PDF,上传它然后删除生成中使用的临时图像:

// Generate document and then add a section with an image
var document = new Document {Info = {Title = "Results"}};
var section = document.AddSection();
var logo = section.AddImage(logoPath);

// Render the PDF
const PdfFontEmbedding embedding = PdfFontEmbedding.Always;
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument(); // This is the line which locks the files

// Save the PDF to a memory stream and upload it to azure blob storage
var reportPath = "";
using (var stream …
Run Code Online (Sandbox Code Playgroud)

c# wpf pdfsharp migradoc asp.net-mvc-4

4
推荐指数
1
解决办法
1073
查看次数

适用于 azure 1.50 的 PDFSharp 私有字体

我已经下载并安装了 PDFSharp 1.5,但在使用私有字体时遇到了问题。我在测试中创建了一个 pdf 创建器,并且效果很好。当我将它加载到 Azure 时,它​​给了我无法加载字体的错误。做了研究,发现他们没有任何加载的字体,所以我必须使用私有字体。我只能找到旧的1.3版本的例子,方法改成新的。有人可以向我展示一个使用新版本 PDFSharp 的简单示例吗?

谢谢约翰

fonts private pdfsharp

4
推荐指数
2
解决办法
3112
查看次数

如何在PDFSharp中使用私有字体

我试图使用私有文本添加文本到PDF文档,即没有安装在系统上,TrueType字体和麻烦.我正在使用NuGet的PDFSharp + MigraDoc WPF版本1.32.2608.0.

我在论坛和StackOverFlow上找到了很多项目.最新的是这篇stackoverflow文章,它引用了PdfSharp网站上的这个例子.但是,此示例包含以下代码:

this.fontFamilies.Add(key, fontFamily);
Run Code Online (Sandbox Code Playgroud)

在第22行,但我在汇编中找不到任何对fontFamilies的引用.

因此,我遵循了一个看起来很好的例子,但它对我不起作用.当我使用这种方法时,我可以成功添加字体但是当我来使用命令时:

var font = new XFont(fontStyle.Name, new XUnit(fontStyle.SizePt, XGraphicsUnit.Point), XFontStyle.Regular, _fontOptions);
Run Code Online (Sandbox Code Playgroud)

fontStyle.Name前面没有#的字体名称在哪里?此时,PdfSharp private void Initialise()在PdfSharp.Drawing命名空间内的方法内部中断.

此时检查Initialise方法内的变量它具有:

  1. 找到了字体系列,即 this.family != null
  2. 找到了字体,即 this.typeface != null

我假设它在线上突破if (!typeface2.TryGetGlyphTypeface(out typeface))但我无法确定.

注意:我已经尝试过.ttf和.otf字体无济于事.

有人能指出我正确的方向吗?

更新

最后我换成了PDFSharp WPF 1.50 beta,因为它的字体处理要好得多.请参阅我在第二期的SO帖子以及解决我的问题的新字体解析器的信息.现在一切都运转良好.

c# wpf fonts pdfsharp

4
推荐指数
2
解决办法
8422
查看次数

MigraDoc - imbricated/nested表?

我想在另一个表(在特定单元格内)中添加一个表.我找不到将Table对象添加到Cell对象的方法.这根本不可能吗?

或者,我可能会合并一些细胞,但我在MigraDoc网站上找不到任何样本合并细胞的样本.

这是我的代码:

Table parentTable = new Table();
parentTable.AddColumn(Unit.FromCentimeter(9));
Row parentRow = parentTable.AddRow();
Cell parentCell = parentRow.Cells[0];

Table currentTable = new Table();
currentTable.AddColumn(Unit.FromCentimeter(4));
Row currentRow = currentTable.AddRow();
currentRow.Cells[0].AddParagraph("blablabla");

parentCell.Add(currentTable); // this does not work
Run Code Online (Sandbox Code Playgroud)

c# pdfsharp migradoc

4
推荐指数
1
解决办法
3135
查看次数