PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

FontStyle
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1269
Page 1 of 1

Author:  jccapps [ Mon Jul 19, 2010 7:39 pm ]
Post subject:  FontStyle

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

Author:  Antonias [ Tue Jul 20, 2010 2:41 am ]
Post subject:  Re: FontStyle

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>

Author:  jccapps [ Tue Jul 20, 2010 1:28 pm ]
Post subject:  Re: FontStyle

Thanks Antonias!

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

Author:  hoylemd [ Wed Feb 22, 2012 4:03 pm ]
Post subject:  Re: FontStyle

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?

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/