ID页面加载 样式渲染慢旋转后如何全部返回原来样式

页面旋转90度在手机怎么正常显示
[问题点数:100分]
本版专家分:0
结帖率 75%
CSDN今日推荐
本版专家分:121739
2017年 总版技术专家分年内排行榜第七
2018年5月 Web 开发大版内专家分月排行榜第一2018年1月 Web 开发大版内专家分月排行榜第一2017年12月 Web 开发大版内专家分月排行榜第一2017年6月 Web 开发大版内专家分月排行榜第一2017年2月 Web 开发大版内专家分月排行榜第一2016年3月 Web 开发大版内专家分月排行榜第一2015年8月 Web 开发大版内专家分月排行榜第一
2018年6月 Web 开发大版内专家分月排行榜第二2018年4月 Web 开发大版内专家分月排行榜第二2018年3月 Web 开发大版内专家分月排行榜第二2018年2月 Web 开发大版内专家分月排行榜第二2017年11月 Web 开发大版内专家分月排行榜第二2017年10月 Web 开发大版内专家分月排行榜第二2017年9月 Web 开发大版内专家分月排行榜第二2017年8月 Web 开发大版内专家分月排行榜第二2017年7月 Web 开发大版内专家分月排行榜第二2017年5月 Web 开发大版内专家分月排行榜第二2017年4月 Web 开发大版内专家分月排行榜第二2017年3月 Web 开发大版内专家分月排行榜第二2017年1月 Web 开发大版内专家分月排行榜第二2016年11月 Web 开发大版内专家分月排行榜第二2016年9月 Web 开发大版内专家分月排行榜第二2016年8月 Web 开发大版内专家分月排行榜第二2016年7月 Web 开发大版内专家分月排行榜第二2016年6月 Web 开发大版内专家分月排行榜第二2016年5月 Web 开发大版内专家分月排行榜第二2016年4月 Web 开发大版内专家分月排行榜第二2016年2月 Web 开发大版内专家分月排行榜第二2015年9月 Web 开发大版内专家分月排行榜第二2015年7月 Web 开发大版内专家分月排行榜第二2015年6月 Web 开发大版内专家分月排行榜第二2015年4月 Web 开发大版内专家分月排行榜第二2015年3月 Web 开发大版内专家分月排行榜第二2015年2月 Web 开发大版内专家分月排行榜第二
2016年12月 Web 开发大版内专家分月排行榜第三2016年10月 Web 开发大版内专家分月排行榜第三2016年1月 Web 开发大版内专家分月排行榜第三2015年12月 Web 开发大版内专家分月排行榜第三2015年11月 Web 开发大版内专家分月排行榜第三2015年10月 Web 开发大版内专家分月排行榜第三2015年5月 Web 开发大版内专家分月排行榜第三2015年1月 Web 开发大版内专家分月排行榜第三2014年12月 Web 开发大版内专家分月排行榜第三
本版专家分:0
结帖率 75%
匿名用户不能发表回复!|
CSDN今日推荐把静态HTML页面转成.jpg格式的图片 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 16时,
把静态HTML页面转成.jpg格式的图片,站在前辈的代码上,稍作一下修改、整理,为了以后还会用到,就做个代码分享。要用的同学可以直接复制下来稍作调整,就可以咯。
代码片段(5)
Test14.java&~&6KB&&&&
import java.awt.C
import java.awt.G
import java.awt.image.BufferedI
import java.io.BufferedR
import java.io.ByteArrayInputS
import java.io.ByteArrayOutputS
import java.io.F
import java.io.FileInputS
import java.io.InputS
import java.io.InputStreamR
import java.util.ArrayL
import java.util.L
import java.util.M
import java.util.regex.M
import java.util.regex.P
import javax.swing.JTextP
import javax.swing.border.EmptyB
import org.apache.commons.io.FileU
import source.JdbcD
import source.JdbcDaoI
import source.MyT
import com.sun.image.codec.jpeg.JPEGC
import com.sun.image.codec.jpeg.JPEGEncodeP
import com.sun.image.codec.jpeg.JPEGImageE
public class Test14 {
public static int DEFAULT_IMAGE_WIDTH = 1024;
public static int DEFAULT_IMAGE_HEIGHT = 1348;
public static int DEFAULT_MAX_LENGTH = 900;
* html转换为图片格式jpg文件
* @param bgColor 图片的背景色
* @param html html的文本信息
* @param width 显示图片的text容器的宽度
* @param height 显示图片的text容器的高度
* @param eb 設置容器的边框
* @throws Exception
public static ArrayList&String& htmlToImg(Color bgColor, String html, int width, int height,String outFileImagePath) throws Exception {
ArrayList&String& ret = new ArrayList&String&();
JTextPane jTextPane = new JTextPane();
jTextPane.setSize(width, height);
EmptyBorder eb = new EmptyBorder(0, 0, 0, 0);
if (bgColor != null) {
jTextPane.setBackground(bgColor);
jTextPane.setBorder(eb);
jTextPane.setContentType("text/html");
jTextPane.setText(html);
PrintView m_printView = new PrintView(jTextPane);
int pageIndex = 1;
boolean bcontinue =
while (bcontinue) {
BufferedImage image = new java.awt.image.BufferedImage(width, height, java.awt.image.BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setClip(0, 0, width, height);
bcontinue = m_printView.paintPage(g, height, pageIndex);
g.dispose();
String path = saveToImg(image,outFileImagePath);
ret.add(path);
pageIndex++;
} catch (Exception ex) {
* 将BufferedImage转换为图片的信息
* @param image
private static String saveToImg(BufferedImage image ,String outFileImagePath) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(baos);
JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(image);
param.setQuality(1.0f, false);
encoder.setJPEGEncodeParam(param);
encoder.encode(image);
byte[] buff = baos.toByteArray();
baos.close();
FileUtils.writeByteArrayToFile(new File(outFileImagePath), buff);
} catch (Exception ex) {
ex.printStackTrace();
return outFileImageP
* 替换模板中的key值
* @param html
* @param map
private static String replaceHtml(String html,Map&String, String& map){
for (Map.Entry&String, String& entry : map.entrySet()) {
if(entry.getValue() != null){
html = html.replace("${" + entry.getKey() + "}", entry.getValue());
html = html.replace("${" + entry.getKey() + "}", " ");
* Img标签的过滤,过滤以"&img"开头以"/img&"结尾的标签
* @param content
* @return String
private static String filterImgTag(String content) {
Pattern pattern = Pattern.compile("&(img|IMG)(.*?)(/&|&&/img&|&)");
Matcher matcher = pattern.matcher(content);
StringBuffer sb = new StringBuffer();
boolean result1 = matcher.find();
while (result1) {
matcher.appendReplacement(sb, "");
result1 = matcher.find();
matcher.appendTail(sb);
return sb.toString();
* 读取本地文件
* @param filepath
* @param encoding
private static String readFile(String filepath,String encoding){
File file = new File(filepath);
String content = "";
if(file.isFile() && file.exists()){ //判断文件是否存在
InputStreamReader read = new InputStreamReader(new FileInputStream(file),encoding);//考虑到编码格式
BufferedReader bufferedReader = new BufferedReader(read);
String lineTxt =
while((lineTxt = bufferedReader.readLine()) != null){
content += lineT
read.close();
System.out.println("[INFO]找不到指定的文件!");
} catch (Exception e) {
System.out.println("[INFO]读取文件内容出错!");
e.printStackTrace();
public static void main(String[] args) {
JdbcDao jdbcDao = new JdbcDaoImpl();
List&Object& para = new ArrayList&Object&();
para.add(29);
Map&String, String& map = jdbcDao.queryBySingle("select * from wcmdocument where id=?", para );
String dochtmlcon = filterImgTag(map.get("dochtmlcon"));
if(dochtmlcon != null && dochtmlcon.length() &= DEFAULT_MAX_LENGTH){
dochtmlcon = dochtmlcon.substring(0, DEFAULT_MAX_LENGTH);
map.put("dochtmlcon", dochtmlcon);
map.put("dochtmlcon", dochtmlcon);
String html = readFile("D:/templet.html", "utf-8");
html = replaceHtml(html, map);
InputStream in = new ByteArrayInputStream(html.getBytes("utf-8"));
MyTools.inputStreamToFile(in, "D:/test.html");
String outFileImagePath = "D:/Test.jpg";
Test14.htmlToImg(null, html, DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT, outFileImagePath);
} catch (Exception e) {
e.printStackTrace();
templet.html&~&747B&&&&
&!-- HTML模板 --&
.body{color: #333;}
.title{font-size: 36font-weight:line-height: 40text-align:padding-top: 10font-family: "微软雅黑";}
.ftitle{font-size: 18line-height: 20text-align:padding-top: 10font-family: "微软雅黑";color:#9b9a9a;}
.content{font-size: 24line-height: 20padding-top: 10padding-left: 50padding-right: 50padding-bottom:20font-family: "宋体";}
&body class="body"&
&div class="title"&${doctitle}&/div&
&div class="ftitle"&
&span&来源:${docsourcename}&/span&
&span&时间:${crtime}&/span&&/div&
&div class="content"&${dochtmlcon}&/div&
test.html&~&3KB&&&&
&!-- HTML模板 --&&style&&!--.body{color: #333;}.title{font-size: 36font-weight:line-height: 40text-align:padding-top: 10font-family: "微软雅黑";}.ftitle{font-size: 18line-height: 20text-align:padding-top: 10font-family: "微软雅黑";color:#9b9a9a;}.content{font-size: 24line-height: 20padding-top: 10padding-left: 50padding-right: 50padding-bottom:20font-family: "宋体";}--&&/style&&body class="body"&
&div class="title"&你必须知道的减肥秘密:为何会轻易反弹?&/div&
&div class="ftitle"&
&span&来源: &/span&
&span&时间: 15:04:14.0&/span&&/div& &div class="content"&&P&&FONT id=Zoom&你一直在减肥,屡败屡战,锲而不舍。关于减肥,你有太多疑惑:为什么这么困难?为什么好容易减下来却又轻易反弹回去?如果你有这种困惑,就要了解减肥的秘密。&/FONT&&/P&
&P align=center&&FONT id=Zoom&&/FONT&&/P&
&P&&FONT id=Zoom& & &STRONG&秘密1:脂肪所处的位置更重要&/STRONG& &/FONT&&/P&
&P&&FONT id=Zoom& & 脂肪是什么?脂肪是人体不可缺少的营养素,我们的脑细胞和神经细胞以及荷尔蒙都需要脂肪的参与。1克脂肪可以产生9卡的热量,而我们的身体根本不用费劲,就能吸收脂肪。现在我们努力要做的,就是怎样去掉这些不受欢迎的多余物质。要知道,有些位置的脂肪是非常危险的。 &/FONT&&/P&
&P&&FONT id=Zoom& & 靠近肝脏和其他腹腔器官的脂肪堆积最为可怕。你感觉不到它、看不到它、摸不到它,它却可以以极快的速度通过血液向肝脏直接注入脂肪酸,危及肝脏在血液中控制胰岛素的能力,从而造成新陈代谢紊乱,诱发糖尿病、高血压等可怕疾病。 &/FONT&&/P&
&P&&FONT id=Zoom& & 作为女人,我们身体中大约有40%-45%的脂肪,其中5%-10%属于腹腔脂肪。我们可以到专门的医疗机构去测量腹腔脂肪,也完全可以通过一种最简单的自助方法来测量,那就是——量腰围。如果你的腰围超过88厘米,就被认为是超高风险了。 &/FONT&&/P&
&P&&FONT id=Zoom&&STRONG&  &/STRONG&&/FONT&&/P&
&P&&FONT&&STRONG& &秘密2:压力会让腹腔脂肪增多&/STRONG& &/FONT&&/P&
&P&&FONT id=Zoom& & 你不懈地减肥,你每天都为身材烦恼,可是你不知道,其实压力也会让腹腔内的脂肪增多。 &/FONT&&/P&
&P&&FONT id=Zoom& & 当你感觉有压力的时候,体内就会产生&/div&&/body&
4.&[图片] test.png&&&&
5.&[代码][Java]代码&&&&
import java.awt.D
import java.awt.G
import java.awt.Graphics2D;
import javax.swing.JTextP
import javax.swing.plaf.basic.BasicEditorPaneUI;
public class PrintView {
public JTextPane panel =
public PrintView(JTextPane panel) {
this.panel =
* 绘制图片的方法
* @param g
* @param hPage
* @param pageIndex
public boolean paintPage(Graphics g, int hPage, int pageIndex) {
Graphics2D g2 = (Graphics2D)
Dimension d = ((BasicEditorPaneUI) panel.getUI()).getPreferredSize(panel);
double panelHeight = d.
double pageHeight = hP
int totalNumPages = (int) Math.ceil(panelHeight / pageHeight);
g2.translate(0f, -(pageIndex - 1) * pageHeight);
panel.paint(g2);
boolean ret =
if (pageIndex &= totalNumPages) {
开源中国-程序员在线工具:
相关的代码(1515)
0回/3290阅
23回/2787阅
1回/1191阅
2楼:杨少_winston 发表于
3楼:杨少_winston 发表于
不过貌似代码没给全
4楼:异常爱 发表于
PrintView 是什么?
5楼:shop1998 发表于
用不了的啊,生成只有一半
6楼:shop1998 发表于
用不了的啊,生成只有一半
7楼:shop1998 发表于
有什么插件可以完美生成
8楼:Discduck_ 发表于
引用来自“shop1998”的评论有什么插件可以完美生成请问。最后有没有解决 生成一半的问题
开源从代码分享开始
零度以上的其它代码JS 或者Jquery怎么实现:点击一个按钮之后鼠标样式改变,然后单击一次之后变回正常形状_百度知道
JS 或者Jquery怎么实现:点击一个按钮之后鼠标样式改变,然后单击一次之后变回正常形状
按钮ID=“1”。style中的cursor变成crosshair。单击一次之后变回default
我有更好的答案
直接修改元素的cursor属性呀!例如你要修改body的cursor属性$(&button#1&).bind('click',function(){&&&&if($(&body&).css('cursor')=='crosshair'){&&&&&&&&(&body&).css('cursor','default');&&&&}else{&&&&&&&&(&body&).css('cursor','crosshair');&&&&}})然后你要将这个鼠标样式应用到哪一个元素上,就修改这个元素的cursor就ok了
采纳率:71%
来自团队:
&input id=&myinput& type=&button& style=&width:150; text-align:& value=&botton&/&&script&document.getElementById(&myinput&).onclick=function(){ if(this.style.cursor==&&)
this.style.cursor=&progress&; else this.style.cursor=&&}&/script&
本回答被网友采纳
为您推荐:
其他类似问题
jquery的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。网页怎么实现鼠标单击后改变样式并且保留样式?_百度知道
网页怎么实现鼠标单击后改变样式并且保留样式?
我对javascript不熟,请问下怎么实现图片中个效果?
因为javascript看懂都难,每个属性方法都要百度,实在吃力。先贴上HTML
&div class=&sidebar&&
&li&&a href=&#& id=&she&&系统桌面&/a&&/li&
我有更好的答案
写了个Demo,样式有可能有出入,但是这个问题不大是不;&!doctype&html&&html&lang=&zh-cn&&&head& &meta&charset=&UTF-8&& &title&Document&/title& &style& /*&实现这样的效果主要是要定位&向右侧便宜一下就可以了&*/ .sidebar&{&position:&&width:&200&height:&500&background:&#DDD;&border:&1px&solid&#F00;&} .sidebar&&&ul&{&position:&&padding:&0;&margin:&0;&width:&160&margin-top:&30&float:&&right:&-1&} .sidebar&li&{&text-align:&&list-style:&&padding:&0;&margin:&0;&font:&12px/3&&Microsoft&YaHei&,SimH&} .sidebar&li&a&{&text-decoration:&&color:ō&} .sidebar&.hover&{&border:&1px&solid&#B4B4B4;&border-right:&&background:&#EEE;&} &/style& &!--&引入jQuery&--& &script&src=& &script& /* //&jQuery方式开始 $(function(){
$('div.sidebar&li').click(function(){
$(this).addClass('hover').siblings('li').removeClass('hover');
}) }) //&jQuery方式结束 */ //&原生Javascript window.onload=function(){
var&obj=document.getElementById('nav');
var&lis=obj.getElementsByTagName('li');
obj.onclick=function(event){
var&e=event||window.
var obj=e.srcElement?e.srcElement:e.
//&去掉其他LI的hover样式
for(var&i=0,&l=lis.&i&&&l;&i++){
lis[i].className=&&;
switch(obj.tagName){
case&'LI':
obj.className=&hover&;
case&'A':
obj.parentNode.className=&hover&;
} } &/script&&/head&&body&&div&class=&sidebar&&&&&&&&& &ul&id=&nav&&
&li&class=&hover&&&&a&href=&#&&系统桌面&/a&&/li&
&li&&a&href=&#&&导航设计&/a&&/li&
&li&&a&href=&#&&风格美化&/a&&/li&
&li&&a&href=&#&&版式布局&/a&&/li&
&li&&a&href=&#&&配置方案&/a&&/li& &/ul&&&/div&&/body&&/html&你这个问题主要有二,第一,HTML页面元素的ID是唯一的,你这个重名了,所以只有第一个好使;第二,那个用定位,之后想列表元素向右偏移一像素就达到类似的效果了,现在这个还有点小遗憾就是会看起来哆嗦一下,把li的默认情况下加个跟外层.sidebar同颜色的边框就好了。
采纳率:44%
为您推荐:
其他类似问题
鼠标的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。HTML做的网页 如何使当前页面跳转到另一页面锚点处,在线等!!_百度知道
HTML做的网页 如何使当前页面跳转到另一页面锚点处,在线等!!
HTML的网页,在当前页面设置了超链接,想跳转到另一个页面设置的锚点处,应该如何设置该超链接及锚点?希望有详细代码哈。。谢谢。。。本人分不多。就给一半吧。。。
烦请大家留意,是要在当前页面跳转到另一页面的锚点处。希望能给个代码看看。。。单读文字理解不来哈。。谢谢谢谢
我有更好的答案
当前页面a.html另一页面b.html当前页面:&a href=&b.html#aaa&&跳转到b页面aaa处&/a&另一页面:&a name=&aaa& id=&aaa&&aaa&/a&
采纳率:20%
比如那么锚点的名字叫abc那么在连接后面写上#abc就行了。
你那样,你可以在视图下做啊,你先插入个锚点,然后,你去想设置超链接的地方,在属性的超链接框里输入#后面跟你的锚点名就ok了!
&!DOCTYPE html PUBLIC &-//W3C//DTD XHTML 1.0 Transitional//EN& &&&&html xmlns=&& xml:lang=&en&&&head&&meta http-equiv=&Content-Type& content=&text/charset=UTF-8&&&title&链接到其他页面锚点&/title&&/head&&body&&table width=&500& border=&0& cellpadding=&10& cellspacing=&0&&&tr&&td colspan=&3&& &p&油服网致力于油气产业链服务,切实解决企业在融资、设备材料采购、项目结算、财税管理等方面的问题,提高企业运行效率,降低管理成本。&/p&&/td&&/tr&&tr&&td&&a href=&锚点链接.html#1& target=&_parent&&平台简介&/a&&/td&&td&&a href=&锚点链接.html#2&&平台特色&/a&&/td&&td&&a href=&锚点链接.html#4&&团队介绍&/a&&/td&&/tr&&/table&&/body&&/html&
2条折叠回答
为您推荐:
其他类似问题
锚点的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 js 打印页面保留样式 的文章

 

随机推荐