PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sun Jul 14, 2024 3:38 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Feb 02, 2009 6:49 am 
Offline

Joined: Mon Feb 02, 2009 6:32 am
Posts: 3
Location: Mumbai, India
Hi, I'm a PDFSharp (and asp.net) newbie. I've just got pdfsharp.dll and toyed around with a few things, like converting some text on my .aspx web page to pdf. I have a couple of questions:

1) Whenever I need to convert some text to pdf, I first create a blank pdf page, add it to my pdf document and then use DrawString (or some form of it, a wrapper) to paint my text on it. However, if the text is say, 10 pages, then using the same method, how do I ensure that I get a pdf document that is 10 pages long? do I have to check if the text will fit in one page, or two pages and manually do everything.. or is there a way with which I can just give the text, the font, the size etc, get pdfsharp to compute the no. of pages it'll need to fit the text in and give me a multi-page pdf document?

2) I have a textbox on my .aspx page and a button next to it which says 'Export to pdf'. the end user has to enter some text in the textbox and then click on the button to see his text in pdf format. right now, my browser (internet explorer 7) is converting the text to pdf in the same window. how do I get it to open the pdf in a new browser window?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Mon Feb 02, 2009 10:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
Hi!

Re 1)
Use MigraDoc.

Re 2)
Look here:
viewtopic.php?t=353&highlight=contenttype&mforum=pdfsharp
The keywords are 'target="_blank"', "Response.ContentType" and "Content-Disposition".

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 03, 2009 6:57 am 
Offline

Joined: Mon Feb 02, 2009 6:32 am
Posts: 3
Location: Mumbai, India
Hi Thomas, thanks a lot for your prompt reply, you're a legend!

Question no. 2 has been resolved :)

However, I'm still having some trouble creating multi-page pdf documents. I checked out your MixMigraDocAndPdfSharp sample, and its got the following 2 snippets of code:

// code snippet #1
static void SamplePage1(PdfDocument document)
{
PdfPage page = document.AddPage();
XGraphics gfx = XGraphics.FromPdfPage(page);


// code snippet #2
// You need always a MigraDoc document for rendering.
Document doc = new Document();
Section sec = doc.AddSection();
// Add a single paragraph with some text and format information.
Paragraph para = sec.AddParagraph();

This still renders the document page by page, one paragraph at a time. What I'm looking for is to just input something like 10 pages of text, and get a 10-page pdf document in return.

My final objective is to export some content on a sharepoint portal to PDF. The challenge is to export it while keeping the look and feel (.aspx page in sharepoint, rendered using html and css) as similar to the original sharepoint page as possible. I'm not sure about the best approach to do this. Is there a way to export html+css to pdf directly (by parsing html+css to preserve the look and feel and then converting the required text to pdf)?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 03, 2009 9:24 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
When you create a MigraDoc document, you add paragraphs and manual page breaks.

When the document is rendered, MigraDoc determines the number of pages that is needed.

You're dealing with a "pageless" MigraDoc document and the "layouted" PdfDocument - and MigraDoc tells you how many pages are needed.
And you only have to go this way if you want to improve the pages created by MigraDoc with some PDFsharp calls.

I thought that's what you need.

You can call AddSection in a loop from 1 through 10,000 and see how many pages MigraDoc will create.

If you add nine manual page breaks you'll get at least 10 pages. Maybe more if one logical page has too much text for a physical page.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Feb 03, 2009 10:14 am 
Offline

Joined: Mon Feb 02, 2009 6:32 am
Posts: 3
Location: Mumbai, India
Hi Thomas, thanks for clearing that up! It worked great. :):):)


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 40 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:  
cron
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group