小编Je *_*not的帖子

PDFsharp页面大小和设置保证金问题c#

我正在使用PDFsharp lib将图像转换为pdf.我需要设置保证金和页面大小,所以我从这个论坛得到一个技巧来设置页面大小和页边距.从这里我得到了我用过的代码但是两个区域的错误.这是我得到的代码.

page = document.AddPage();
//page.Size = PdfSharp.PageSize.A4;
XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.A4);
if(page.Orientation == PageOrientation.Landscape)
{
   page.Width  = size.Height;
   page.Height = size.Width;
}
else
{
   page.Width  = size.Width;
   page.Height = size.Height;
}

// default unit in points 1 inch = 72 points
page.TrimMargins.Top = 5;
page.TrimMargins.Right = 5;
page.TrimMargins.Bottom = 5;
page.TrimMargins.Left = 5;
Run Code Online (Sandbox Code Playgroud)

这条线路出错了

XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.A4);
Run Code Online (Sandbox Code Playgroud)

所以我需要改变它

System.Drawing.Size size = PageSizeConverter.ToSize(PdfSharp.PageSize.A4);
Run Code Online (Sandbox Code Playgroud)

现在我的程序编译,但当我设置边距然后我得到错误称为 PdfSharp不包含TrimMargins的定义

这些下面的行不能编译设置保证金.

    pdfPage.TrimMargins.Top = 5;
    pdfPage.TrimMargins.Right = 5;
    pdfPage.TrimMargins.Bottom = 5;
    pdfPage.TrimMargins.Left = 5;
Run Code Online (Sandbox Code Playgroud)

我使用的是pdf …

c# pdfsharp

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

如何减少 MigraDoc 文档的上边距?

如何减少 MigraDoc 文档的上边距?

我在文档的右上角添加了一个图像,但是文档顶部和图像之间的空间太大。

这是我设置图像的方法:

Section section = document.AddSection();
Image image = section.AddImage(@"C:\img\mentSmallLogo.png");
image.Height = "1.5cm";
image.Width = "4cm";
image.LockAspectRatio = true;
image.RelativeVertical = RelativeVertical.Line;
image.RelativeHorizontal = RelativeHorizontal.Margin;
image.Top = ShapePosition.Top;
image.Left = ShapePosition.Right;
image.WrapFormat.Style = WrapStyle.Through;
Run Code Online (Sandbox Code Playgroud)

以及文档样式:

Style style = document.Styles["Normal"];
style.Font.Name = "Verdana";

style = document.Styles[StyleNames.Header];
style.ParagraphFormat.AddTabStop("16cm", TabAlignment.Right);

style = document.Styles[StyleNames.Footer];
style.ParagraphFormat.AddTabStop("8cm", TabAlignment.Center);

// Create a new style called Table based on style Normal
style = document.Styles.AddStyle("Table", "Normal");
style.Font.Name = "Verdana";
style.Font.Name = "Times New Roman";
style.Font.Size = …
Run Code Online (Sandbox Code Playgroud)

migradoc

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

是否可以在 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水印

我正在创建一个应用程序,在用户选择的PDF上创建水印,我似乎无法在所选PDF上显示水印,但我也没有错误.任何帮助,将不胜感激.

我使用的是PDFsharp版本1.50.4000

public void WaterMarkPDF(string sourceFileName)
    {
        try
        {
            string watermark = "watermark";
            int emSize = 100;
            string file ="test.pdf";

            File.Copy(sourceFileName, file, true);
            File.SetAttributes(file, File.GetAttributes(file) & ~FileAttributes.ReadOnly);

            // Take in pdf from the form
            PdfDocument document = PdfReader.Open(file);

            // change the version cause sometimes newer versions break it
            if (document.Version < 14)
                document.Version = 14;

            XFont font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic);
            for (int idx = 0; idx < document.Pages.Count; idx++)
            {
                var page = document.Pages[idx];

                // Get …
Run Code Online (Sandbox Code Playgroud)

c# pdfsharp

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

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

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

scale pdfsharp

5
推荐指数
2
解决办法
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
查看次数

使用 PDFSharp 将文本转换为 PDF

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

converter pdfsharp

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

使用MigraDoc将图像拟合到一个PDF页面上

我可以使用MigraDoc轻松地将图像添加到PDF文件的某个部分.但是,图像按页面宽度减半.

有没有办法强制图片调整大小以使其完全适合一页?或者必须手动完成吗?

如果必须手动完成,是否有人知道MigraDoc中PDF页面的尺寸?

migradoc

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

MigraDoc 是否支持国家字符/Unicode 字符?

我正在使用 MigraDoc 生成 PDF 文档。它工作得很好,但我有两个问题:

  1. 我无法将波兰语字符(尤其是?)添加到文本中。
  2. 我无法在文本中添加磅字符 (?)。

我试图改变字体,但没有结果。

c# pdf-generation migradoc

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