PDFsharp & MigraDoc Foundation

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

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Feb 06, 2009 12:28 am 
Offline

Joined: Fri Feb 06, 2009 12:24 am
Posts: 1
I'm trying to just create a page with some text on it (just like the hello world example, but my string is a lot longer. I put some newlines in there, but it didn't work right, the text just went off the page and newlines appeared as the block character.

Is there anything i can do? Should i use some other API method to do this?



Code:
// Create a new PDF document
            PdfDocument document = new PdfDocument();

            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
            XFont font = new XFont("Arial", 20, XFontStyle.Bold, options);

            string text = this.Name;

            //Make multiline if longer than 10 characters
            if (text.Length > 10)
            {
               text = text.Replace(" ", "\n");
            }

            for (int i = 1; i <= this.Pages; i++)
            {

               PdfPage page = document.AddPage();
               
               XGraphics gfx = XGraphics.FromPdfPage(page);

               gfx.DrawString(text + "\nPage " + i.ToString(), font, XBrushes.Black,
                 new XRect(0, 0, page.Width, page.Height),
                 XStringFormats.Center);

            }

            document.Save(targetdirectory + "\\" + filename);



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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 359 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