我有一个C#控制台应用程序,希望将PdfSharp的一些功能添加到其中。
我从Sourceforge下载了两个压缩文件..。程序集和源代码。
似乎有几种添加功能的方法
.dll文件的引用。我试着用后一种方法。
这就是我要做的?
Add>Existing Project...。

我假设项目PdfSharp-ag.csproj;PdfSharp-Hybrid.csproj;PdfSharp-WPF.csproj适用于其他应用程序?我的意思是,对于我的简单控制台应用程序来说,我只需要项目PdfSharp.csproj?
完成上述步骤后,我的解决方案如下所示:

在对原始项目参考部分中的...and进行引用的情况下,扩展为PdfSharp:

然后,我使用以下代码测试了控制台应用程序的所有工作状态:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing; //<< additional reference required
using PdfSharp;
using PdfSharp.Pdf;
using PdfSharp.Drawing;
namespace PDFsharpSolutionQF
{
class Program
{
static void Main(string[] args)
{
PdfDocument pdf = new PdfDocument();
pdf.Info.Title = "My First PDF";
PdfPage pdfPage = pdf.AddPage();
XGraphics graph = XGraphics.FromPdfPage(pdfPage);
XFont font = new XFont("Verdana",20,XFontStyle.Bold);
graph.DrawString("This is my first PDF document",font,XBrushes.Black,new XRect(0,0,pdfPage.Width.Point,pdfPage.Height.Point),XStringFormats.Center);
string pdfFilename = "firstpage.pdf";
pdf.Save(pdfFilename);
//Process.Start(pdfFilename);
}
}
}发布于 2012-09-12 15:33:39
您可以使用PdfSharp.csproj或PdfSharp-WPF.csproj -前者使用GDI+进行图形操作,后者使用WPF函数。-Hybrid是内部的,-ag是SilverLight的(还没有完全功能)。
发布于 2012-09-12 15:09:57
您能详细说明为什么要将程序源代码添加到您自己的应用程序中吗?如果您只想使用库的特性,那么最好只引用项目中的DLL,然后使用它提供的API。
我能想到的接近源代码的唯一原因是:(如果您需要调试它,或者b)如果您打算以某种方式修改功能。您是在尝试这样做,还是只是以通常的方式使用API?
发布于 2015-01-31 01:39:06
将源代码包含在项目中的一个优点是消除了分发DLL的需要。我个人使用DLL。但我能看到只分发EXE的好处。
https://stackoverflow.com/questions/12391244
复制相似问题