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
- a reference to the
.dll
file in the unzipped assemblies folder. - actually add the projects to my solution.
I'm trying to use the latter method.
Is this all I need to do?
- I copied and pasted the folder "PdfSharp" from the unzipped source code file into my solution folder.
- In VS I went to Solution Explorer right-clicked the solution and chose
Add
>Existing Project...
- Then I chose the following ...
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);
}
}
}