如何使用ASP.NET MVC创建动态论坛签名生成器。我目前有一个Stats抓取器,用于检索要在论坛签名中使用的用户信息。

我正在尝试创建一个论坛签名生成器,用户可以在其中输入用户名并生成一个可以放入论坛签名的图像,以便向所有人显示用户统计信息。

类似这样的内容 http://www.xfire.com/miniprofile

我一定忘记了我在做什么我并不是说提供这么少的信息,但我想你会知道我现在想做什么..

有帮助吗?

解决方案

我会使用abcPdf组件,图像将是高分辨率的pdf文档。

然后你需要传递文字,字体,颜色,x,y,w,h

然后将PDF渲染为jpg流

让你前进的基本想法可能就是这样;

        private void addTextToPDF(string cmyk, int fs, string fontname, Double posx,
    Double posY, Double mWidth, Double mHeight, String text, Double hpos)
    {
        text = secure.reverseCleanup(text);
        int lettercount1 = 0;
        foreach (char c in text)
        { lettercount1 ++; }

        TheDoc.Color.String = cmyk;
        TheDoc.FontSize = fs;
        var theFont = fontname;
        TheDoc.Rect.Position(posx, posY);
        TheDoc.Rect.Width = mWidth;
        TheDoc.Rect.Height = mHeight;
        TheDoc.HPos = hpos;
        TheDoc.Font = TheDoc.EmbedFont(theFont, "Latin", false, true, true);
        int didwrite = TheDoc.AddText(text);
        string addedchars = TheDoc.GetInfo(didwrite, "Characters");
        var oldid = didwrite;

        if (addedchars != lettercount1.ToString())
            didwrite = 0;

        while (didwrite==0) // hits this if first run did not add text
        {
            TheDoc.Delete(oldid);
            fs = fs - 2;
            TheDoc.Color.String = cmyk;
            TheDoc.FontSize = fs;
            theFont = fontname;
            TheDoc.Rect.Position(posx, posY);
            TheDoc.Rect.Width = mWidth;
            TheDoc.Rect.Height = mHeight;
            TheDoc.HPos = hpos;
            TheDoc.Font = TheDoc.EmbedFont(theFont, "Latin", false, true, true);
            didwrite = TheDoc.AddText(secure.reverseCleanup(text));
            addedchars = TheDoc.GetInfo(didwrite, "Characters");
            oldid = didwrite;

            if (addedchars != lettercount1.ToString())
                didwrite = 0;
        }

    }

    public byte[] convertPDFToImageStream()
    {
        byte[] jpgBytes = null;
        byte[] theData = null;
        theData = TheDoc.GetData();
        TheDoc.Clear();
        TheDoc.Read(theData);
        TheDoc.Rendering.DotsPerInch = getDPI();
        TheDoc.Rendering.ColorSpace = "RGB";
        jpgBytes = TheDoc.Rendering.GetData("preview.jpg");

        return jpgBytes;
     }

这是添加文本的代码,也是将PDF作为流JPG呈现的代码 非常好的组件。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top