PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jul 19, 2024 3:25 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
 Post subject: FontStyle
PostPosted: Mon Jul 19, 2010 7:39 pm 
Offline

Joined: Tue Jun 08, 2010 6:12 pm
Posts: 13
Ok, this question probably has a very simple answer but I can't seem to find it. I need to be able to have a font that is underlined and italic. I thought I could do the following with XFontStyle, and then set the XFontStyle on the XFont, but the compiler didn't like it:

XFontStyle s = XFontStyle.Italic + XFontStyle.Underline;

Also, while I'm here. How do you set the weight of a font? I found the XFontWeight and XFontWeights object, but what property on XFont do you set this on?

Thanks
Craig


Top
 Profile  
Reply with quote  
 Post subject: Re: FontStyle
PostPosted: Tue Jul 20, 2010 2:41 am 
Offline
User avatar

Joined: Sat Jul 17, 2010 4:58 am
Posts: 3
This sample works for me
I hope this can help you

Code:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="PdfSharp" %>
<%@ Import Namespace="PdfSharp.Pdf" %>
<%@ Import Namespace="PdfSharp.Drawing" %>
<html>
<head runat="server">
<title>Gabriel Diaz</title>
<script runat="server">
   
    Sub Page_Load()
        Dim document As PdfDocument = New PdfDocument
        Dim page As PdfPage = document.AddPage
        Dim gfx As XGraphics = XGraphics.FromPdfPage(page)
        Const facename As String = "Verdana"
        Dim options As New XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.[Default])
        Dim fontItalic As New XFont(facename, 20, XFontStyle.Underline & XFontStyle.Italic, options) 'here is the magic
        gfx.DrawString("Hola", fontItalic, XBrushes.DarkSlateGray, 10, 100)

        Dim stream As New MemoryStream()
        document.Save(stream, False)
        Response.Clear()
        Response.ContentType = "application/pdf"
        Response.AddHeader("content-length", stream.Length.ToString())
        Response.BinaryWrite(stream.ToArray())
        Response.Flush()
        stream.Close()
        Response.[End]()
 
    End Sub
</script>
</head>
<body>
</body>
</html>


Top
 Profile  
Reply with quote  
 Post subject: Re: FontStyle
PostPosted: Tue Jul 20, 2010 1:28 pm 
Offline

Joined: Tue Jun 08, 2010 6:12 pm
Posts: 13
Thanks Antonias!

As soon as I saw that I wanted to kick myself :roll:. I knew it was something little I was doing wrong.


Top
 Profile  
Reply with quote  
 Post subject: Re: FontStyle
PostPosted: Wed Feb 22, 2012 4:03 pm 
Offline

Joined: Thu Feb 09, 2012 4:59 pm
Posts: 14
I had a similar problem to this. Instead of that, I went into the source file for XFontStyles and added an explicit enum entry for all 16 combinations and recompiled. It might not be as elegant as ANDing the flags together, but it serves the same purpose and is probably easier to figure out. Are there any plans to do this to the main project?


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 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:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group