如何使用 ASP.NET MVC 创建动态论坛签名生成器。我目前有一个 Stats 提取器,用于检索要在论坛签名中使用的用户信息。
我正在尝试创建一个论坛签名生成器,用户可以在其中输入他们的用户名并生成他们可以放入论坛签名中的图像,该图像将向所有人显示用户统计信息。
像这样http://www.xfire.com/miniprofile
我一定忘记了我在做什么我不是说提供这么少的信息,但我想你会知道我现在想做什么。
如何使用 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 非常非常好的组件的代码。