标签: pdfsharp

pdfsharp - font embed?

我得到一个具有其他语言字体的文件.他们无法下载字体,因此他们希望我将其嵌入到pdf中.

现在,我只有PDF阅读器,所以我无法编辑或创建PDF文件.所以我决定使用PDFSharp库在C#.NET中快速完成它,但我似乎无法弄清楚如何使用pdfSharp嵌入字体?!

此外,它只有一个我必须处理的文件,所以如果你知道一种手动方式,那么这也会很棒.

pdfsharp

6
推荐指数
1
解决办法
9985
查看次数

使用PDFSharp连接PDF文件返回空白页

我尝试连接rdlc报告中的2个PDF数据.

问题是结果是空白页面.

我不知道为什么,请有人帮助我.

这是我的代码:

private ActionResult ConcatPdf(byte[] pdfData1, byte[] pdfData2)
{
    MemoryStream ms1 = new MemoryStream(pdfData1);
    MemoryStream ms2 = new MemoryStream(pdfData2);

    PdfDocument inputDoc1 = PdfReader.Open(ms1, PdfDocumentOpenMode.Import);
    PdfDocument inputDoc2 = PdfReader.Open(ms2, PdfDocumentOpenMode.Import);

    PdfDocument outputDoc = new PdfDocument();

    foreach (PdfPage page in inputDoc1.Pages)
    {
        outputDoc.AddPage(page);
    }

    foreach (PdfPage page in inputDoc2.Pages)
    {
        outputDoc.AddPage(page);
    }

    MemoryStream outputMs = new MemoryStream();
    outputDoc.Save(outputMs);

    return File(outputMs.ToArray(), "application/pdf");
}
Run Code Online (Sandbox Code Playgroud)

在生成报告功能时看起来像这样:

public ActionResult TestPDF(int id)
{
    // Set report path.
    LocalReport rep = viewer.LocalReport;
    rep.ReportPath = Server.MapPath("~/Reports/rptExternalTransferIndividual.rdlc");
    rep.DataSources.Clear(); …
Run Code Online (Sandbox Code Playgroud)

c# pdf rdlc pdfsharp

6
推荐指数
2
解决办法
4250
查看次数

C#PDFSharp:如何从PDF中删除文本的示例?

我有一个相当简单的任务:我需要读取PDF文件并写出其图像内容,同时忽略其文本内容.所以基本上我需要做"另存为文本"的补充.

理想情况下,我宁愿避免任何形式的图像内容重新压缩,但如果不可能,也可以.

是如何做到的例子?

谢谢!

c# text pdfsharp

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

MigraDoc子弹列表(孔)

在我的解决方案中,我使用PDF文件中的项目符号列表.

看起来像这样:

• Solcellepaneler kræver hverken autoriseret service eller tidskrævende vedligehold.
• Solceller er støjfri, forurener ikke og har ingen bevægelige dele, hvilket mindsker
service og vedligehold
• Solceller kan integreres i bygningers arkitektur eller anvendes som
bygningselement i form af tag, facader eller solafskærmning
• Solceller har lang levetid, med en produktionsgaranti på hele 25 år
• 10 kvadrameter solceller sparer ca. ½ ton CO2 om året
Run Code Online (Sandbox Code Playgroud)

我想要的是 :

• Solcellepaneler kræver hverken autoriseret service eller tidskrævende vedligehold.
• …
Run Code Online (Sandbox Code Playgroud)

c# pdfsharp migradoc

6
推荐指数
1
解决办法
2450
查看次数

创建多个字节数组时出现OutOfMemoryException

我经常在一个OutOfMemoryException内部创建并处理一些字节数组的方法.代码如下所示:

  1. 创建MemoryStream以获取一些数据(大约60MB).
  2. 创建字节数组(与MemoryStream大小相同,大约60MB)
  3. 使用内存流中的字节填充数组
  4. 关闭MemoryStream
  5. 处理来自字节数组的数据
  6. 离开方法

当这个方法被调用20-30次时,我得到OutOfMemoryException了分配字节数组的位置.但我不认为这是系统内存问题.应用程序内存使用量约为500MB(专用工作集),测试机器为64位,内存为4GB.

字节数组使用的内存是否可能MemoryStream在方法完成后未释放?但是,由于私有工作集只有500MB左右,因此看起来这个内存不会分配给进程.

OutOfMemoryException在物理内存不足的情况下,什么时候可能导致创建大字节数组(60MB)?

[编辑添加代码示例] 源来自PdfSharp lib

排除异常byte[] imageBits = new byte[streamLength];它确实看起来像LOH碎片问题.

/// <summary>
/// Reads images that are returned from GDI+ without color palette.
/// </summary>
/// <param name="components">4 (32bpp RGB), 3 (24bpp RGB, 32bpp ARGB)</param>
/// <param name="bits">8</param>
/// <param name="hasAlpha">true (ARGB), false (RGB)</param>
private void ReadTrueColorMemoryBitmap(int components, int bits, bool hasAlpha)
{
  int pdfVersion = Owner.Version;
  MemoryStream memory = new MemoryStream(); …
Run Code Online (Sandbox Code Playgroud)

.net c# out-of-memory pdfsharp

6
推荐指数
1
解决办法
5854
查看次数

PDFSharp:使用自动换行测量长文本的高度

PDFSharp 在绘制长文本部分时支持自动文本换行:

textFormatter.DrawString(text, font, XBrushes.Black, new XRect(x, y, textAreaWidth, 1000), XStringFormats.TopLeft);
Run Code Online (Sandbox Code Playgroud)

如果文本长于,这将换行 textAreaWidth.

如何获取刚刚绘制的文本的高度?

我用 尝试过gfx.MeasureString(),但没有支持指定最大宽度的重载。gfx.MeasureString()返回没有文本换行的文本大小。

感谢您的任何提示。

c# pdf pdf-generation pdfsharp

6
推荐指数
2
解决办法
9581
查看次数

pdfsharp和内部对

我试图填写pdf表单的字段,所以我使用以下代码

  string filePath = @"c:\test.pdf";
  string newPath = @"E\Result";

  if(File.Exists(filePath))
  {
        PdfDocument document = PdfReader.Open(filePath, PdfDocumentOpenMode.Modify);
        // Get the root object of all interactive form fields
        PdfAcroForm form = document.AcroForm;
        // Get all form fields of the whole document
        PdfAcroField.PdfAcroFieldCollection fields = document.AcroForm.Fields; //"/Fields"
        string[] names = fields.Names;
        names = fields.DescendantNames;
Run Code Online (Sandbox Code Playgroud)

问题是它给出错误PDF名称必须以斜杠(/)开头.

我知道document.AcroForm有4对,其中有关键字"/ Fields",如何到达它

c# pdfsharp

6
推荐指数
1
解决办法
649
查看次数

PDFsharp缺少Xps命名空间

我需要PDFsharp的XPS功能才能从WPF转换 - > XPS - > PDF.我已经尝试引用PDFsharp 1.20,1.30,1.31和1.32,但这些都没有包含PdfSharp.Xps每个人都在谈论的神秘命名空间.显然1.31是包含XPS功能的最后一个版本,但我也没有找到任何东西.

这是我需要的一行代码:

//error: 'Xps' is not a member of 'PdfSharp'
var test = PdfSharp.Xps.XpsModel.XpsDocument.Open(_MemoryStream);
Run Code Online (Sandbox Code Playgroud)

c# wpf pdfsharp

6
推荐指数
1
解决办法
4665
查看次数

如何使用 Migradoc PDF 库打开现有的 PDF 文件

我正在尝试使用 PDFSharp ( http://www.pdfsharp.net/ ) 中的 Migradoc 库来打印 pdf 文件。到目前为止,我发现 Migradoc 确实支持通过其MigraDoc.Rendering.Printing.MigraDocPrintDocument类进行打印。但是,我还没有找到使用 MigraDoc 打开现有 PDF 文件的方法。

我确实找到了一种使用 PDFSharp 打开现有 PDF 文件的方法,但我无法成功将 aPDFSharp.Pdf.PdfDocument转换为MigraDoc.DocumentObjectModel.Document对象。到目前为止,我还没有发现 MigraDoc 和 PDFSharp 文档很有帮助。

有没有人有使用这些库来处理现有 PDF 文件的经验?

我在此示例的帮助下编写了以下代码,但是当我的输入 PDF 为 2 页时,结果是一个带有 2 个空白页的输出 PDF。

using MigraDoc.DocumentObjectModel;
using MigraDoc.Rendering;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;

...

public void PrintPDF(string filePath, string outFilePath)
{

    var document = new Document();

    var docRenderer = new DocumentRenderer(document);
    docRenderer.PrepareDocument();

    var inPdfDoc = PdfReader.Open(filePath, PdfDocumentOpenMode.Modify);

    for …
Run Code Online (Sandbox Code Playgroud)

c# printing pdf pdfsharp migradoc

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

为PDF添加数字签名字段

我使用PDFsharp和MigraDoc创建一个新的PDF文件。现在,我想添加一个字段,用户可以在其中单击并选择用于数字签名文件的证书。

我在网上发现,使用AcroForms应该可以做到这一点。但是我无法使用,AcroForm因为它始终为null。

我当前的示例代码:

Document document = new Document();

Section section = document.AddSection();
section.AddParagraph("Signature Test");


PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
pdfRenderer.Document = document;
pdfRenderer.RenderDocument();

// NullPointerException at the following line. AcroForm is null 
pdfRenderer.PdfDocument.AcroForm.Elements.Add(PdfAcroForm.Keys.SigFlags, new PdfInteger(3));

const string filename = "HelloWorld.pdf";
pdfRenderer.PdfDocument.Save(filename);
Process.Start(filename);
Run Code Online (Sandbox Code Playgroud)

为什么此属性为null?我该怎么做才能将其设置为正确的值?

或者更好的是,如何添加一个字段来选择数字证书?

c# pdfsharp digital-signature migradoc

5
推荐指数
1
解决办法
112
查看次数