higcharts导出中文乱码 highcharts导出导出图片 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以试试这个需要引用svg.dll 一个开源项目连接自己找itextsharp.dll 提供中文支持using System;using System.Collections.Generic;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.IO;using Svg;using System.Drawing.Imaging;using iTextSharp.text;using iTextSharp.text.pdf;using System.Text;namespace ExportServer{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { if (Request.Form["type"] != null && Request.Form["svg"] != null && Request.Form["filename"] != null) { string tType = Request.Form["type"].ToString(); string tSvg = Request.Form["svg"].ToString(); string tFileName = Request.Form["filename"].ToString(); if (tFileName == "") { tFileName = "chart"; } MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg)); MemoryStream tStream = new MemoryStream(); string tTmp = new Random().Next().ToString(); string tExt = ""; string tTypeString = ""; switch (tType) { case "image/png": tTypeString = "-m image/png"; tExt = "png"; break; case "image/jpeg": tTypeString = "-m image/jpeg"; tExt = "jpg"; break; case "application/pdf": tTypeString = "-m application/pdf"; tExt = "pdf"; break; case "image/svg+xml": tTypeString = "-m image/svg+xml"; tExt = "svg"; break; } if (tTypeString != "") { string tWidth = Request.Form["width"].ToString(); Svg.SvgDocument tSvgObj = SvgDocument.Open(tData); switch (tExt) { case "jpg": tSvgObj.Draw().Save(tStream, ImageFormat.Jpeg); break; case "png": tSvgObj.Draw().Save(tStream, ImageFormat.Png); break; case "pdf": PdfWriter tWriter = null; Document tDocumentPdf = null; try { tSvgObj.Draw().Save(tStream, ImageFormat.Png); tDocumentPdf = new Document(new Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height)); tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f); iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(tStream.ToArray()); tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height); tStream = new MemoryStream(); tWriter = PdfWriter.GetInstance(tDocumentPdf, tStream); tDocumentPdf.Open(); tDocumentPdf.NewPage(); tDocumentPdf.Add(tGraph); tDocumentPdf.CloseDocument(); } catch (Exception ex) { throw ex; } finally { tDocumentPdf.Close(); tDocumentPdf.Dispose(); tWriter.Close(); tWriter.Dispose(); tData.Dispose(); tData.Close(); } break; case "svg": tStream = tData; break; } Response.ClearContent(); Response.ClearHeaders(); Response.ContentType = tType; Response.AppendHeader("Content-Disposition", "attachment; filename=" + tFileName + "." + tExt + ""); Response.BinaryWrite(tStream.ToArray()); Response.End(); } } } } }} 导出的PDF文件图片倒是蛮清楚的,就不知道为什么直接导出图片不行 编码两次,在解码,记得编码两次; UrlEncode ,UrlDecode 在js或者jquery里面能使用el表达式吗? 初学jquery,求教下一步的学习方向 [求助] ExtJs问题,Ext.FormPanel中删除一个Item,整个对象都无效了。 急问做一个这样的网站用的何种语言!需要多少费用! 单击浏览器的刷新按钮为什么不触发window.location.reload呢? 链接点入页面,IE6下以src引入的脚本不执行?!FF,IE7倒都没事! 图片预览问题 在线等 [REQ]急!需MzTreeView 1.0,梅花雪的网站今天打不开。 如何动态改变frame的高度 高手帮忙啊! js或者其它程序的一个算法问题 js 能不能实现图片下载到本地
itextsharp.dll 提供中文支持using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Svg;
using System.Drawing.Imaging;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Text;
namespace ExportServer
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.Form["type"] != null && Request.Form["svg"] != null && Request.Form["filename"] != null)
{
string tType = Request.Form["type"].ToString();
string tSvg = Request.Form["svg"].ToString();
string tFileName = Request.Form["filename"].ToString();
if (tFileName == "")
{
tFileName = "chart";
}
MemoryStream tData = new MemoryStream(Encoding.UTF8.GetBytes(tSvg));
MemoryStream tStream = new MemoryStream();
string tTmp = new Random().Next().ToString(); string tExt = "";
string tTypeString = ""; switch (tType)
{
case "image/png":
tTypeString = "-m image/png";
tExt = "png";
break;
case "image/jpeg":
tTypeString = "-m image/jpeg";
tExt = "jpg";
break;
case "application/pdf":
tTypeString = "-m application/pdf";
tExt = "pdf";
break;
case "image/svg+xml":
tTypeString = "-m image/svg+xml";
tExt = "svg";
break;
} if (tTypeString != "")
{
string tWidth = Request.Form["width"].ToString();
Svg.SvgDocument tSvgObj = SvgDocument.Open(tData);
switch (tExt)
{
case "jpg":
tSvgObj.Draw().Save(tStream, ImageFormat.Jpeg);
break;
case "png":
tSvgObj.Draw().Save(tStream, ImageFormat.Png);
break;
case "pdf":
PdfWriter tWriter = null;
Document tDocumentPdf = null;
try
{
tSvgObj.Draw().Save(tStream, ImageFormat.Png);
tDocumentPdf = new Document(new Rectangle((float)tSvgObj.Width, (float)tSvgObj.Height));
tDocumentPdf.SetMargins(0.0f, 0.0f, 0.0f, 0.0f);
iTextSharp.text.Image tGraph = iTextSharp.text.Image.GetInstance(tStream.ToArray());
tGraph.ScaleToFit((float)tSvgObj.Width, (float)tSvgObj.Height); tStream = new MemoryStream();
tWriter = PdfWriter.GetInstance(tDocumentPdf, tStream);
tDocumentPdf.Open();
tDocumentPdf.NewPage();
tDocumentPdf.Add(tGraph);
tDocumentPdf.CloseDocument();
}
catch (Exception ex)
{
throw ex;
}
finally
{
tDocumentPdf.Close();
tDocumentPdf.Dispose();
tWriter.Close();
tWriter.Dispose();
tData.Dispose();
tData.Close(); }
break; case "svg":
tStream = tData;
break;
} Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = tType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + tFileName + "." + tExt + "");
Response.BinaryWrite(tStream.ToArray());
Response.End();
}
}
}
}
}
}