汉化FreeTextBox的ImageGallery

 汉化ImageGallery

  protected override void Render(HtmlTextWriter writer)
  {
   writer.Write(this.ChineseGallery());
  }
        /// <summary>
        /// 获取控件,汉化之
        /// </summary>
        /// <returns></returns>
  private string ChineseGallery()
  {
   StringWriter writer = new StringWriter(); //提供一个可以写的文本区域
   HtmlTextWriter buffer = new HtmlTextWriter(writer); //让htmlWriter操作这个区域,我们就可以获得这个区域里的内容
   base.Render(buffer); //先让页面画一遍,让我们得到初始的页面html代码
   string html = writer.ToString(); //找到这段代码,我们来处理它,把英文变成汉字
   //
   html=html.Replace("There are no images:","现在还没有图片");
   html=html.Replace("Upload File","上传图片");
   html=html.Replace("Status</div>","状态</div>");
   html=html.Replace("Selected Image","选中的图片");
   html=html.Replace("Create Folder","创建目录");
   html=html.Replace("Delete Image","删除该图片");
   html=html.Replace("/"Upload/"","'上传'");
   html=html.Replace("<legend>Preview","<legend>预览图片");
   html=html.Replace("<legend>Dimensions","<legend>设置显示尺寸");
   html=html.Replace("Original Size","原图大小");
   html=html.Replace("Custom Size","设置为");
   html=html.Replace("Lock image ratio","锁定尺寸比例");
   html=html.Replace("Percentage","百分比");
   html=html.Replace("Image Gallery","我的像册");
   html=html.Replace("<legend>Properties","<legend>图片属性");
   html=html.Replace("Align","横向排列");
   html=html.Replace("Border","边框");
   html=html.Replace("VSpace","左边距");
   html=html.Replace("HSpace","上边距");
   html=html.Replace("Alt","转换文字");
   html=html.Replace("Title","图片标题");
   html=html.Replace("value=/"Insert/"","value='插入到编辑器中'");
   //
   return html;
  }

 

 

引用一个所谓“ImageGallery汉化无错版”的:保存为Ftb.Imagegallery.aspx就可以了:
-----------------------------------------------------------------
<%@ Page Language="C#" ValidateRequest="false" Trace="false" %>
<%@ Register TagPrefix="FTB" Namespace="FreeTextBoxControls" Assembly="FreeTextBox" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
protected void Page_Load(Object Src, EventArgs E) {

// *** remove this return statement to use the following code ***
return;

string currentFolder = ImageGallery1.CurrentImagesFolder;

// modify the directories allowed
if (currentFolder == "~/images") {

// these are the default directories FTB:ImageGallery will find
string[] defaultDirectories = System.IO.Directory.GetDirectories(Server.MapPath(currentFolder),"*");

// user defined custom directories
string[] customDirectories = new string[] {"folder1","folder2"};

// the gallery will use these images in this instance
ImageGallery1.CurrentDirectories = customDirectories;
}


// modify the images allowed
if (currentFolder == "~/images") {

System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(Server.MapPath(currentFolder));

// these are the default images FTB:ImageGallery will find
System.IO.FileInfo[] defaultImages = directoryInfo.GetFiles("*");

// user defined custom images (here, we're just allowing the first two)
System.IO.FileInfo[] customImages = new System.IO.FileInfo[2] {defaultImages[0], defaultImages[1]};

// the gallery will use these images in this instance
ImageGallery1.CurrentImages = customImages;
}

}


protected override void Render(HtmlTextWriter writer)
{
writer.Write(this.ChineseGallery());
}
private string ChineseGallery()
{
StringWriter writer = new StringWriter(); //提供一个可以写的文本区域
HtmlTextWriter buffer = new HtmlTextWriter(writer); //让htmlWriter操作这个区域,我们就可以获得这个区域里的内容
base.Render(buffer); //先让页面画一遍,让我们得到初始的页面html代码
string html = writer.ToString(); //找到这段代码,我们来处理它,把英文变成汉字
//
html=html.Replace("There are no images:","现在还没有图片");
html=html.Replace("Upload File","上传图片");
html=html.Replace("Status</div>","状态</div>");
html=html.Replace("Selected Image","选中的图片");
html=html.Replace("Create Folder","创建目录");
html=html.Replace("Delete Image","删除该图片");
html=html.Replace("/"Upload/"","'上传'");
html=html.Replace("<legend>Preview","<legend>预览图片");
html=html.Replace("<legend>Dimensions","<legend>设置显示尺寸");
html=html.Replace("Original Size","原图大小");
html=html.Replace("Custom Size","设置为");
html=html.Replace("Lock image ratio","锁定尺寸比例");
html=html.Replace("Percentage","百分比");
html=html.Replace("Image Gallery","我的像册");
html=html.Replace("<legend>Properties","<legend>图片属性");
html=html.Replace("Align","横向排列");
html=html.Replace("Border","边框");
html=html.Replace("VSpace","左边距");
html=html.Replace("HSpace","上边距");
html=html.Replace("Alt","转换文字");
html=html.Replace("Title","图片标题");
html=html.Replace("value=/"Insert/"","value='插入到编辑器中'");
//
return html;
}
</script>
<html xmlns=" http://www.w3.org/1999/xhtml" >
<head>
<title>Image Gallery</title>
</head>
<body>
<form id="Form1" runat="server" enctype="multipart/form-data">
<FTB:ImageGallery id="ImageGallery1"
JavaScriptLocation="InternalResource"
UtilityImagesLocation="InternalResource"
SupportFolder="../images/"
AllowImageDelete="true" AllowImageUpload="true" AllowDirectoryCreate="false" AllowDirectoryDelete="false" runat="Server" />
</form>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要将 HTML 中的 FreeTextbox 和文本框转换成 PDF,可以使用 iText 这个开源的 Java PDF 库。 首先,需要将 HTML 字符串转换成 PDF 文档对象。iText 提供了 `HtmlConverter.convertToPdf()` 方法可以实现这个功能,示例如下: ```java // 假设 html 为包含 FreeTextbox 和文本框的 HTML 字符串 ByteArrayOutputStream pdf = new ByteArrayOutputStream(); PdfDocument pdfDoc = new PdfDocument(new PdfWriter(pdf)); ConverterProperties props = new ConverterProperties(); HtmlConverter.convertToPdf(html, pdfDoc, props); ``` 这段代码将 HTML 字符串转换成 PDF 文档对象,并将结果输出到 `ByteArrayOutputStream` 中,可以通过 `pdf.toByteArray()` 获取转换后的 PDF 字节数组。 接下来,需要将 PDF 文档对象中的文本框和图片元素替换成 iText 中的对应元素。iText 提供了 `PdfAcroForm` 类和 `Image` 类分别表示 PDF 中的表单和图片,可以通过 `pdfDoc.getAcroForm()` 获取 PDF 文档的表单对象,然后使用 `PdfAcroForm.addField()` 方法添加文本框,使用 `Image.getInstance()` 方法添加图片,示例如下: ```java // 获取表单对象 PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDoc, true); // 替换 FreeTextbox 中的文本框 Elements textboxes = doc.select("div.FreeTextbox input[type=text]"); for (Element textbox : textboxes) { String name = textbox.attr("name"); float left = Float.parseFloat(textbox.attr("data-left")); float top = Float.parseFloat(textbox.attr("data-top")); float width = Float.parseFloat(textbox.attr("data-width")); float height = Float.parseFloat(textbox.attr("data-height")); PdfTextFormField field = PdfFormField.createText(pdfDoc, new Rectangle(left, top, width, height), name, ""); form.addField(field); } // 替换 FreeTextbox 中的图片 Elements imgs = doc.select("div.FreeTextbox img"); for (Element img : imgs) { String src = img.attr("src"); float left = Float.parseFloat(img.attr("data-left")); float top = Float.parseFloat(img.attr("data-top")); float width = Float.parseFloat(img.attr("data-width")); float height = Float.parseFloat(img.attr("data-height")); Image image = Image.getInstance(new URL(src)); image.setAbsolutePosition(left, top); image.scaleToFit(width, height); pdfDoc.addNewPage().add(image); } ``` 这段代码中,`doc.select("div.FreeTextbox input[type=text]")` 通过 CSS 选择器查找所有 `<div>` 元素中 class 属性为 `FreeTextbox` 的子元素中的输入框元素,然后遍历所有输入框元素,通过 `PdfFormField.createText()` 方法创建对应的 PDF 文本框,将其添加到 PDF 表单对象中。 `doc.select("div.FreeTextbox img")` 通过 CSS 选择器查找所有 `<div>` 元素中 class 属性为 `FreeTextbox` 的子元素中的图片元素,然后遍历所有图片元素,通过 `Image.getInstance()` 方法创建对应的 iText 图片对象,并设置其位置和大小,将其添加到新建的 PDF 页面中。 最后,需要关闭 PDF 文档对象并输出结果: ```java pdfDoc.close(); response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=test.pdf"); response.setContentLength(pdf.size()); ServletOutputStream out = response.getOutputStream(); out.write(pdf.toByteArray()); out.flush(); ``` 这段代码中,通过 `pdfDoc.close()` 方法关闭 PDF 文档对象,然后将 PDF 内容写入 HTTP 响应输出流中,浏览器会自动下载名为 `test.pdf` 的 PDF 文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值