标签: pdfsharp

使用PDFSharp打印PDF

我有以下代码:

using System;
using System.Diagnostics;
using System.IO;
using PdfSharp.Pdf.Printing;

namespace PrintPdfFile
{

  class Program
  {
    [STAThread]
    static void Main(string[] args)
    {
      // Set Acrobat Reader EXE, e.g.:
        PdfFilePrinter.AdobeReaderPath = @"C:\\Documents and Settings\\mike.smith\\Desktop\\Adobe Reader 9.0.exe";
      // -or-
        //PdfPrinter.AdobeReaderPath = @"C:\Program Files\Adobe\[...]\AcroRd32.exe";

      //// Ony my computer (running a German version of Windows XP) it is here:
        //PdfFilePrinter.AdobeReaderPath = @"C:\\Documents and Settings\\mike.smith\\Desktop\\Adobe Reader 9.0.exe";

      // Set the file to print and the Windows name of the printer.
      // At my home office I …
Run Code Online (Sandbox Code Playgroud)

c# printing pdf pdfsharp

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

单声道上的PdfSharp

有没有人试图将PdfSharp库移植到Mono?我刚刚针对PdfSharp.dll v1.2 beta 运行MoMA,我得到大约12个P/Invoke错误和10个左右的Mono TODO.只是想知道是否有人将PdfSharp移植到Linux和OSX,如果是这样,它是怎么回事?试着评估PdfSharp是否适合我.

.net linux macos mono pdfsharp

7
推荐指数
1
解决办法
2064
查看次数

有没有办法在MigraDoc/PDFsharp中有背景图像?

我想创建一个在背景图像上有文本的封面.这可能在MigraDoc/PDFsharp中吗?

c# pdfsharp migradoc

7
推荐指数
1
解决办法
4681
查看次数

PdfSharp:在文档中旋转页面

我正在创建一个Web应用程序,用于在我们的数据库中维护PDF文档,这些文档在我们接收传真时通过自动系统进入.用户需要能够查看这些文档,并且当他们以错误的方式放入传真机时,他们需要能够对这些文档执行的一个更常见的事情是翻转/旋转单个页面.这几乎总是180度旋转页面.我已经创建了一个函数来执行此操作,这似乎有效,但只是第一次调用它.对此功能的任何后续调用似乎都不再起作用.与此函数相关的另一个奇怪的事情是,我还有另一个被调用的方法,它会在选定位置向文档添加一些文本.我传入文本和一些坐标,并将文本写入文档中的那些坐标,一切都很好.这里的问题是,该文件被旋转(在一个时间它旋转),如果用户试图将文本添加到某个文档,似乎扭转它放置在文字的坐标,文字倒置.

所有这些告诉我,最终,我正在以某种方式错误地进行页面轮换.我似乎无法找到任何关于如何以正确的方式在PdfSharp文档中旋转页面的好样本,因此一些指导将非常有用并且非常感激.提前致谢.

这是我目前用于旋转页面和向页面添加文本的代码:

// This is how I'm rotating the page...
public PdfDocument FlipPage(byte[] documentSource, int pageNumber)
{
    using (var stream = new MemoryStream())
    {
        stream.Write(documentSource, 0, documentSource.Length);
        var document = PdfReader.Open(stream);
        var page = document.Pages[pageNumber - 1];
        page.Rotate = 180;

        return document;
    }
}

// This is how I'm adding text to a page...
public static void AddTextToPage(this PdfDocument document, int pageNumber, Annotation annotation)
{
    var page = document.Pages[pageNumber - 1];
    annotation.TargetHeight = …
Run Code Online (Sandbox Code Playgroud)

c# pdfsharp

7
推荐指数
1
解决办法
5325
查看次数

PDF文件是否包含iref流?

我仍然与PDF文件中的读取数据作斗争.
我使用PDFsharp,如何在不使用方法Open的情况下检查文件是否包含iref流.如果文件包含iref流,则方法Open抛出异常.

c# pdf pdfsharp

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

如何在保留书签的同时向现有pdf添加其他页面?(PDFSharp等)

我有一个PDF,我想添加一个额外的页面,理想情况下作为第一页.我已经能够用PDFSharp实现这一点,但问题是原始PDF包含书签,我想维护.使用PDFSharp似乎删除书签,或者至少我不知道使用包含附加页面的新创建的PDF保存原始TOC的任何选项或命令.

有没有人知道如何保持TOC与PDFSharp或任何其他.NET库,理想是免费的,这将允许我添加页面到现有的PDF并维护其书签?(我知道添加页面作为第一页会使页面引用无效,这就是为什么在最后一页添加页面也没问题.)

谢谢大家!

.net pdf-generation bookmarks pdfsharp

7
推荐指数
1
解决办法
5179
查看次数

MigraDoc C#在同一条线上左右对齐

我有一个带有单元格的表格,我想要两个文本,第一个在左边对齐,第二个在右边,在同一个单元格中,在同一行上.

我试图用MigraDoc重现这个细胞而没有成功.我只能添加两个左右对齐但不在同一行的文本.

这是我的代码:

Cell cellFooter1 = rowFooter.Cells[0];
Paragraph paraphTot = new Paragraph();
paraphTot.Format.Alignment = ParagraphAlignment.Left;
paraphTot.AddText("Left text");
cellFooter1.Add(paraphTot);
Paragraph paraphDetails = new Paragraph();
paraphDetails.Format.Alignment = ParagraphAlignment.Right;
paraphDetails.AddText("Right text");
cellFooter1.Add(paraphDetails);
Run Code Online (Sandbox Code Playgroud)

这里提供了一个解决方案(http://forum.pdfsharp.net/viewtopic.php?f=2&t=2373),但我无法对我的表做同样的事情.我不明白它是如何工作的.

编辑:部分解决方案:

在努力了解它是如何工作之后,我的代码部分正常工作.部分因为我发现右对齐的唯一方法是创建一个具有近似值的TabStop ...不好.

Table table = new Table();
table.Borders.Width = 0.75;
Column myColumn = table.AddColumn(Unit.FromCentimeter(7));
Row myRow = table.AddRow();
Cell myCell = myRow.Cells[0];
Paragraph myParagraph = new Paragraph();
Style myStyle = doc.AddStyle("myStyle", "Normal");
myStyle.ParagraphFormat.Font.Size = 6.5;
myStyle.ParagraphFormat.Font.Bold = true;
myStyle.ParagraphFormat.TabStops.Clear();
myStyle.ParagraphFormat.AddTabStop(Unit.FromMillimeter(67), TabAlignment.Right);
myParagraph.Style = "myStyle";
myParagraph.Format.Alignment = ParagraphAlignment.Left; …
Run Code Online (Sandbox Code Playgroud)

c# pdf pdf-generation pdfsharp migradoc

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

如何绘制正方形并动态分配颜色属性(PDFsharp)?

我正在使用PDFsharp导出图表图例.我使用for循环和表来显示属性.实际上只有一个属性:Subdivision名称.该对象具有正确的RGB颜色.如图表图例显示系列那样,如何在它旁边绘制正方形?请原谅我的变量名,我要举个例子.

//Writting Table Header Text
textformater.DrawString(" Color", tableheader, XBrushes.Black, snoColumn);
textformater.DrawString(" Subdivision Name", tableheader, XBrushes.Black, snoStudentName);

foreach (var item in data)
{
    y = y + 30;
    XRect snoColumnVal = new XRect(35, y, 70, height);
    XRect snoStudentNameVal = new XRect(100, y, 250, height);
    textformater.DrawString(item.Color, tableheader, XBrushes.Black, snoColumnVal);
    textformater.DrawString(item.Name, tableheader, XBrushes.Black, snoStudentNameVal);

}
Run Code Online (Sandbox Code Playgroud)

这是输出:

PDF格式

这就是我需要的样子 PIC

c# pdfsharp

7
推荐指数
1
解决办法
4593
查看次数

PDFSharp转换问题

使用缩放变换在不同比例下绘制时发现了PDFSharp的问题.

在此示例中,我们绘制了两个不同比例的矩形,从中生成XPS FixedDocumentSequence,最后使用PDFsharps XPS转换器将XPS转换为PDF.

var visual = new DrawingVisual();
DrawingContext dc = visual.RenderOpen();

// Setup transformations.
dc.PushTransform(new TranslateTransform(0, 1122.0));
dc.PushTransform(new ScaleTransform(3.77857136726379, -3.77857136726379));
dc.PushTransform(new TranslateTransform(-1719.41186523438, -1410.32360839844));
dc.PushTransform(new ScaleTransform(0.0117647061124444, 0.0117647061124444));

// Draw red rectangle.
var redPen = new Pen(Brushes.Red, 1);
var rectGeo1 = new RectangleGeometry(new Rect(160000, 130000, 8000, 5000));
dc.DrawGeometry(Brushes.Transparent, redPen, rectGeo1);

// Pop two transformations.
dc.Pop();
dc.Pop();

// Draw blue rectangle.
var bluePen = new Pen(Brushes.Blue, 0.5);
var rectGeo2 = new RectangleGeometry(new Rect(12, 12, 150.9408, 107.088539));
dc.DrawGeometry(Brushes.Transparent, bluePen, rectGeo2);
dc.Close(); …
Run Code Online (Sandbox Code Playgroud)

pdfsharp

7
推荐指数
1
解决办法
477
查看次数

PDFSharp 可以从 Net Core 中的 Html 字符串创建 Pdf 文件吗?

这可能听起来“容易”,但我还没有找到真正的解决方案。我需要从 .Net Core 上的 API 的 Html 字符串创建 Pdf 文件。图书馆必须是免费的(不是付款或任何相关的东西)。我发现 PDFSharp 是一个不错的选择,但现在我发现 PDFSharp 不适用于 .Net Core 并且它不允许注入 Html 字符串。

那么,对于这种情况,PDFSharp 是一个不错的选择吗?或者你会推荐我什么其他图书馆?

非常感谢。

pdf-generation pdfsharp .net-core

7
推荐指数
3
解决办法
7608
查看次数

标签 统计

pdfsharp ×10

c# ×6

pdf ×3

pdf-generation ×3

.net ×2

migradoc ×2

.net-core ×1

bookmarks ×1

linux ×1

macos ×1

mono ×1

printing ×1