问题
I have been trying to install the PDFsharp library for the purpose of writing PDF records and came across a problem. It keeps saying that the Process does not exist in current context. I did a google and had no luck and a tinker to see if I can get it to work and no luck either. Below is the code I am using to test the library (pulled from the PDFsharp wiki)
PdfDocument document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);
XFont font = new XFont("Verdana", 20, XFontStyle.BoldItalic);
gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
string filename = "HelloWorld.pdf";
document.Save(filename);
process.Start(filename);
And these are the components I currently have in use.
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using PdfSharp;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
I am probably being daft but can anyone see what I am doing wrong to throw this error?
回答1:
This line is wrong
process.Start(filename);
and it has nothing to do with PDFsharp
. You have to resolve that
using System.Diagnostics;
...
Process.Start(filename);
回答2:
If you don't want to add the "using" Directive:
System.Diagnostics.Process.Start(filename);
来源:https://stackoverflow.com/questions/31605767/pdfsharp-the-name-process-does-not-exist-in-current-context