SharpPDF create PDF in Serverside asp .Net C#

3.2k Views Asked by At

I have samples to create PDF, however for the server side creation of PDF there is no documentation about SharpPDF. I think it is about stream concept, which I have no information about it.

pdfDocument myDoc = new pdfDocument("TUTORIAL", "ME");
pdfPage myPage = myDoc.addPage();

myPage.addText("Hello World!", 200, 450, sharpPDF.Enumerators.predefinedFont.csHelvetica, 12);
myDoc.createPDF(@"c:\test.pdf");
myDoc.
myPage = null;
myDoc = null; 
1

There are 1 best solutions below

0
On BEST ANSWER

There is an overload for createPDF that takes a Stream. You can use this to create the PDF in memory on the server and then stream it back to the client.

Here is an example (tried with ShartPDF version 1.3.1):

PdfDocument myDoc = new pdfDocument("TUTORIAL", "ME");
pdfPage myPage = myDoc.addPage();
myPage.addText("Hello World!", 200, 450, predefinedFont.csHelvetica, 12);

Response.ContentType = "application/pdf";
myDoc.createPDF(Response.OutputStream);
Response.Flush();