Reputation: 35557
I have a C# console application and would like to add some of the functionality of PdfSharp to it.
I've downloaded both zip files from Sourceforge ... both the assemblies and the source code.
There seem to be a couple of ways to add the functionality
.dll
file in the unzipped assemblies folder.I'm trying to use the latter method.
Is this all I need to do?
Add
>Existing Project...
I assume the projects PdfSharp-ag.csproj
; PdfSharp-Hybrid.csproj
; PdfSharp-WPF.csproj
are for some other applications? what I mean is for my simple console application is all I need the project PdfSharp.csproj
?
Once I've followed the above steps my Solution looks like the following:
...and when expanded as so with a reference to PdfSharp in the original Projects reference section:
I then tested all was working ok with a console app using the following code:
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);
}
}
}
Upvotes: 1
Views: 11064
Reputation: 141
One advantage of including the source code in the project would be removing the need of distributing the DLL. I personally use the DLL. But I can see the advantage of only distributing an EXE.
Upvotes: 1
Reputation: 21689
You can either use PdfSharp.csproj or PdfSharp-WPF.csproj - the former uses GDI+ for graphics operations, the latter uses WPF functions. -Hybrid is internal and -ag is for SilverLight (not fully functional yet).
Upvotes: 1
Reputation: 3351
Could you elaborate on why you're trying to add the program source to your own application? If you just want to utilise the features of the library then you're much better off just referencing the DLL in your project and then using the API it provides.
The only reasons I could think of to go anywhere near the source code would be a) if you needed to debug into it or b) if you were intending to modify the functionality in some way. Are you trying to do that, or just utilise the API in the usual fashion?
Upvotes: 1