【发布时间】:2012-09-12 15:07:14
【问题描述】:
我有一个 C# 控制台应用程序,并想在其中添加一些 PdfSharp 的功能。
我已经从Sourceforge 下载了两个 zip 文件……程序集和源代码。
似乎有几种方法可以添加功能
- 对解压缩程序集文件夹中
.dll文件的引用。 - 实际上将项目添加到我的解决方案中。
我正在尝试使用后一种方法。
这就是我需要做的一切吗?
- 我将解压缩的源代码文件中的文件夹“PdfSharp”复制并粘贴到我的解决方案文件夹中。
- 在 VS 我转到解决方案资源管理器右键单击解决方案并选择
Add>Existing Project... - 然后我选择了以下...
我假设项目PdfSharp-ag.csproj; PdfSharp-Hybrid.csproj; PdfSharp-WPF.csproj 用于其他应用程序?我的意思是我的简单控制台应用程序就是我需要的项目PdfSharp.csproj?
按照上述步骤操作后,我的解决方案如下所示:
...当在原始项目参考部分中参考 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);
}
}
}
【问题讨论】:
标签: c# visual-studio-2010 pdfsharp