PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Apr 27, 2024 1:09 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Nov 18, 2009 3:23 pm 
Offline

Joined: Tue Nov 03, 2009 8:01 pm
Posts: 2
I need to render the pdf without saving it first. Here's the code. THANKS!

Code:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Web;
using ToolboxFacade;
using ToolboxFacade.Enumerators;
using PdfLib;
using PdfSharp;
using PdfSharp.Drawing.Pdf;
using PdfSharp.Drawing;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using MigraDoc;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
using MigraDoc.RtfRendering;

namespace MCSPortal
{
    public static class PdfBuilder
    {
        static SessionStateManager SessionManager = new SessionStateManager(System.Web.HttpContext.Current.Session);
       

        public static void GetPdfStarted()
        {
             
            Document document = CreateDocument();

             PdfDocumentRenderer renderer = new PdfDocumentRenderer(false, PdfSharp.Pdf.PdfFontEmbedding.Always);

            renderer.Document = document;
            renderer.RenderDocument();
            string fileName = "Resume_" + System.DateTime.Now.Millisecond + ".pdf";
   
            renderer.PdfDocument.Save(fileName);
            Process.Start(fileName);
        }
        public static Document CreateDocument()
        {
            // Create a new MigraDoc document
            MigraDoc.DocumentObjectModel.Document document = new Document();

           
            document.Info.Title = "Resume";
            document.Info.Subject = "Resume";
            document.Info.Author = "Job Seeker";

           
           

            return document;
        }


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 19, 2009 9:02 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
What's the question?
You can render to a file or render to a memory stream (used for example in our WebClock sample).

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 19, 2009 2:52 pm 
Offline

Joined: Tue Nov 03, 2009 8:01 pm
Posts: 2
Thanks for your response. Please bear with me as this is all very new to me.

I looked at the Web clock sample that you pointed to. That code appears to have been written on an .aspx page while I am working within a class. Because of this, I can't figure out how to get to the Response. parameters.

Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
Response.End();

I also see that you are using memory stream in your example but you are also using a pdf document while I am using a migraDoc document.

I will research these issues to educate myself but any help you can provide in the meantime would be greatly appreciated.


Top
 Profile  
Reply with quote  
PostPosted: Thu Nov 19, 2009 4:05 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3096
Location: Cologne, Germany
The MigraDoc renderer creates a PdfDocument for you.
You can save that to a file or to a memory stream (from HelloMigraDoc):
Code:
renderer.PdfDocument.Save(filename);

To keep the stream open, pass false:
Code:
renderer.PdfDocument.Save(stream, false);


The MixMigraDocAndPdfSharp sample shows a different way how to get a PdfDocument from a MigraDoc document.

If your code is in a class, but for use on a web server, then pass Response (class HttpResponse) as a parameter.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 429 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group