标签: pdfsharp

将 PDF 与 PDFSharp 丢失表单字段相结合

我正在尝试使用 PDFSharp 和此代码(我在此处找到)将两个创建的 PDF 文件连接到一个新的 PDF :

        // Open the output document
        PdfDocument outputDocument = new PdfDocument();
        // Iterate files
        foreach (string file in files)
        {
            // Open the document to import pages from it.
            PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);

            // Iterate pages
            int count = inputDocument.PageCount;
            for (int idx = 0; idx < count; idx++)
            {
                // Get the page from the external document...
                PdfPage page = inputDocument.Pages[idx];
                // ...and add it to the output document.
                outputDocument.AddPage(page); …
Run Code Online (Sandbox Code Playgroud)

.net merge pdfsharp

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

PDFsharp - 如何创建第2页

我在PDFsharp中找不到文档来展示如何使用C#添加第二页!

例如,在VB6中,我使用名为mjwPDF的PDF创建方法.表示页面已完成

objPDF.PDFEndPage
Run Code Online (Sandbox Code Playgroud)

并开始一个新的页面:

objPDF.PDFNewPage
Run Code Online (Sandbox Code Playgroud)

我的PDFsharp初始设置:

// Create a new PDF document
PdfDocument document = new PdfDocument();

// Create an empty page
PdfPage page = document.AddPage();
//page.Contents.CreateSingleContent().Stream.UnfilteredValue;

// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
Run Code Online (Sandbox Code Playgroud)

不幸的是,在PDFsharp中我无法找到如何在新页面上开始/写入.我看到这些命令但无法启动第二页.

document.AddPage();
document.InsertPage();
Run Code Online (Sandbox Code Playgroud)

我已尝试过这两种方法,但我的输出继续写在第1页,而不是第2页.

任何想法将不胜感激.

这是实际的代码:

private void buttonPrint_Click(object sender, EventArgs e)
{
    // Create a new PDF document
    PdfDocument document = new PdfDocument();

    // Create an empty page
    PdfPage page = document.AddPage();
    //page.Contents.CreateSingleContent().Stream.UnfilteredValue;

    // Get an XGraphics object for drawing
    XGraphics …
Run Code Online (Sandbox Code Playgroud)

c# pdfsharp

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

MigraDoc - 获取页码

请帮忙!如何在渲染前获取页数?我需要在我的文档中将数字写为单词。对不起我的英语不好

pdfsharp migradoc

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

如何使用 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万
查看次数

PdfSharp - 在 PDF 文档中注入的 Javascript 在 Firefox 中不起作用

我有用于从文件流打印 PDF 文档的代码(使用 PdfSharp 库):

private HttpResponseMessage PrintPdfDocument2(MemoryStream fileStream)
    {
        HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);


        PdfSharp.Pdf.PdfDocument document = PdfSharp.Pdf.IO.PdfReader.Open(fileStream);
        PdfSharp.Pdf.PdfDictionary dict = new PdfSharp.Pdf.PdfDictionary(document);

        dict.Elements["/S"] = new PdfSharp.Pdf.PdfName("/JavaScript");
        dict.Elements["/JS"] = new PdfSharp.Pdf.PdfString("this.print(true);\r");

        document.Internals.AddObject(dict);
        document.Internals.Catalog.Elements["/OpenAction"] = PdfSharp.Pdf.Advanced.PdfInternals.GetReference(dict);

        var outputStream = new MemoryStream();
        document.Save(outputStream);
        result.Content = new ByteArrayContent(outputStream.ToArray());
        result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

        return result;
    }
Run Code Online (Sandbox Code Playgroud)

它在 chrome 和 ie 中运行良好,但在 Firefox 中不起作用

对这个问题有什么想法吗????

谢谢你们的阅读!

javascript c# pdf asp.net pdfsharp

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

是否可以在 Azure 应用服务上安装字体?

我们正在使用 MigraDoc/PDFsharp GDI+,它依赖于将字体安装到系统以进行渲染。我们已尝试嵌入字体,但 MigraDoc 的 GDI+ 版本似乎不支持此功能。

尝试将此组件移动到 Azure 应用服务时,它找不到字体。有没有办法在本地将字体“安装”到应用服务,以便 GDI 可以看到它们?

fonts azure pdfsharp migradoc azure-web-app-service

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

PDFsharp 图像到 XImage

我在 ASP.NET MVC 应用程序中创建了一个条形码作为图像。

BarcodeLib.Barcode barcode = new BarcodeLib.Barcode()                   
{                        
    IncludeLabel = false,
    Alignment = AlignmentPositions.LEFT,
    Width = element.BarcodeWidth,
    Height = element.BarcodeHeight,
    RotateFlipType = RotateFlipType.RotateNoneFlipNone,
    BackColor = Color.Transparent,
    ForeColor = Color.Black,
    ImageFormat = System.Drawing.Imaging.ImageFormat.Png
 };
Run Code Online (Sandbox Code Playgroud)

这将使用 BarcodeLib 创建条形码。
如何将其转换为 PDFsharp 的 XImage?

Image img = barcode.Encode(TYPE.CODE128, "123456789");
gfx.DrawImage(xImage, 0, 0, 100, 100);
Run Code Online (Sandbox Code Playgroud)

c# asp.net pdfsharp

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

PDFsharp - 更改页面大小和缩放内容

是否可以使用 PDFsharp 将页面从 A2 缩放到 A1?我可以通过“大小”、“宽度”和“高度”来设置页面的大小。但是如何缩放页面内容呢?

scale pdfsharp

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

PDFsharp:对类型“FontFamily”的引用声称它是在“System.Drawing”中定义的,但可以找到

我在我的 Web 应用程序(ASP.NET Core 2)中使用PDFsharp 1.50rc2来生成 PDF。我已经按照PDFsharp 站点上的示例进行操作。但是生成它时遇到了问题,可能与 System.Drawing 中的 FontFamily 有关。没有把握。下面是我生成PDF的代码。

using PdfSharp.Pdf;
using PdfSharp.Drawing;

namespace WebApp.Controllers
{
  public class HomeController : Controller {
    public IActionResult Index()
    {
      // creating the PDF
      CreatePDF();

      return View();
    }

    public void CreatePDF()
    {
      // Create a new PDF document
      PdfDocument document = new PdfDocument();
      document.Info.Title = "Created with PDFsharp";

      // Create an empty page
      PdfPage page = document.AddPage();

      // Get an XGraphics object for drawing
      XGraphics gfx = …
Run Code Online (Sandbox Code Playgroud)

pdf pdf-generation pdfsharp asp.net-core

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

为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
查看次数