`
daoger
  • 浏览: 524091 次
  • 性别: Icon_minigender_1
  • 来自: 山东济南
社区版块
存档分类
最新评论

WEB Page to PDF

阅读更多

现在有很多网页页面转换成PDF文档的支持项目,我使用的是pd4ml;一个支持.net和java语言的项目。

这是主页:http://pd4ml.com/ . 有免费版和收费版,看了看免费版,感觉还不错,文档也比较详细。

web应用中需要添加pd4ml.jar和ss_css2,jar;

贴个例子:

ServletContext app;

	protected Dimension format = PD4Constants.A4;

	protected boolean landscapeValue = false;

	protected int topValue = 10;

	protected int leftValue = 10;

	protected int rightValue = 10;

	protected int bottomValue = 10;

	protected String unitsValue = "mm";

	protected String proxyHost = "";

	protected int proxyPort = 0;

	protected int userSpaceWidth = 780;


public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String httpurl = request.getParameter("httpurl");
		// String urlstring = "http://localhost:8080/Itinerary/ProcessPOIs.jsp";
		ItineraryWebSession iws = (ItineraryWebSession) request.getSession().getAttribute("iws");
		if (iws != null && request.getSession().getAttribute("email") != null)
		{
			String email = (String) request.getSession().getAttribute("email");
			app.setAttribute("iws_" + email, iws);
			httpurl = httpurl + "?pdf=true&email=" + email;
			// request.getSession().setAttribute("iws", iws);
		}
		try
		{
			response.reset();
			response.addHeader("Content-Disposition", "attachment;filename=" + new String("result".getBytes(), "8859_1"));
			// response.addHeader("Content-Length", "" + file.length());
			BufferedOutputStream output = null;
			try
			{
				output = new BufferedOutputStream(response.getOutputStream());
				this.runConverter(httpurl, output);
				response.flushBuffer();
			} catch (Exception e)
			{
				e.printStackTrace();
			} finally
			{
				if (output != null)
					output.close();
			}
		} catch (Exception e)
		{
			e.printStackTrace();
			// TODO: handle exception
		}
	}
public void runConverter(String urlstring, BufferedOutputStream output) throws IOException
	{
		if (urlstring.length() > 0)
		{
			if (!urlstring.startsWith("http://") && !urlstring.startsWith("file:"))
			{
				urlstring = "http://" + urlstring;
			}
			if (proxyHost != null && proxyHost.length() != 0 && proxyPort != 0)
			{
				System.getProperties().setProperty("proxySet", "true");
				System.getProperties().setProperty("proxyHost", proxyHost);
				System.getProperties().setProperty("proxyPort", "" + proxyPort);
			}
			PD4ML pd4ml = new PD4ML();
			try
			{
				pd4ml.setPageSize(landscapeValue ? pd4ml.changePageOrientation(format) : format);

			} catch (Exception e)
			{
				e.printStackTrace();
			}
			if (unitsValue.equals("mm"))
			{
				pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));
			} else
			{
				pd4ml.setPageInsets(new Insets(topValue, leftValue, bottomValue, rightValue));
			}
			pd4ml.setHtmlWidth(userSpaceWidth);
			pd4ml.render(urlstring, output);
		}
	}

 我在一个servlet中使用的时候,通过url新建的访问链接,发现session无法和浏览器中的共享,无奈把一部分数据放到了application中,访问完了之后再删掉。 当然,这只是pd4ml的应用方式之一,感兴趣的朋友可以深入研究一下。

 

 

3
0
分享到:
评论
5 楼 手心手背 2011-01-11  
楼主中文乱码怎么解决啊!不胜感激!
4 楼 zdtwyjp 2010-07-19  
你好呀!这两天在弄一个html转pdf的功能!头都弄晕了,试了好多插件都不行!
itext只能显示一种字符格式;
flying sauser纠错能力太差了,很多网页上的标签它不认识,显示不出来;
今天在网上搜到了PD4ML感觉还不错,比较合我的心意,不过还是有一个比较大的问题,哪就是如何处理中文问题?

LZ能否将处理中文的代码贴出来呀!

不胜感激呀!
3 楼 cris_jxg 2009-08-21  
谢谢,编码现在正确了
这个还是很不错的,只可惜不开源
2 楼 daoger 2009-08-11  
cris_jxg 写道
楼主中文怎么处理的,怎么发现中文乱码?

自己进行以下编码转化试试!
1 楼 cris_jxg 2009-08-11  
楼主中文怎么处理的,怎么发现中文乱码?

相关推荐

    CSS Web Design For Dummies.pdf

    Cascading Style Sheets (CSS) is a Web markup standard that allows Web designers to define the appearance and position of a Web page using special dynamic effects This book is the perfect beginner ...

    Single Page Web Applications

    Single page web applications are your next step: pushing UI rendering and business logic to the browser and communicating with the server only to synchronize data, they provide a smooth user ...

    Learning Web Design: A Beginner’s Guide to HTML... ..., 5th Edition

    Learn the ins and outs of Responsive Web Design to make web pages look great on all devices NEW! Become familiar with the command line, Git, and other tools in the modern web developer’s toolkit NEW...

    Building Web Applications with Flask.pdf 最新 原版

    From the beginning, Building Web Applications with Flask shows you how to utilize Flask's concepts, extensions, and components to create engaging, full-featured web projects. You'll learn how to ...

    Angular 5 Projects Learn to Build Single Page Web Applications Using 无水印原版pdf

    Angular 5 Projects Learn to Build Single Page Web Applications Using 70+ Projects 英文无水印原版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自...

    Adobe.Press.CSS.Animations.and.Transitions.for.the.Modern.Web.0133980502.pdf

    date information on current browser support for CSS animations and transitions An introduction to manipulating web page objects in both 2D ...creating realistic animation and how they apply to web page designs

    Expert ASP.NET Web API 2 for MVC Developers(英文pdf)

    Author: Adam Freeman ISBN-10: 978-1-484200-86-5 Year: 2014 Pages: 688 Language: English File size: ...PDF Web API 2 is the latest evolution of Microsoft’s web services ...page applications to consume them.

    Web Components in Action

    A Web Component is well-encapsulated, keeping its internal structure separate from other page elements so they don't collide with the rest of your code. In Web Components in Action you'll learn to ...

    Beginning JSP JSF and Tomcat Web Development From Novice to Professional.pdf

    NULL 博文链接:https://zhangxing119.iteye.com/blog/552400

    Web Development Recipes 2nd Edition pdf

    You'll learn how to use Grunt to script the deployment of your web project, and use Angular to build a single-page app. You'll learn how to make content stand out with simple cross-browser styles; ...

    Isomorphic+JavaScript+Web+Development-Packt+Publishing(2017).pdf

    Chapter 7, Implementing Routing and Navigation, describes how you can implement routing and navigation from scratch, and also how to integrate an existing library to fit into your isomorphic web app. ...

    Using Perl For Web Programming.pdf

    Referring the User to Browser-Specific Web Pages G Using Client Pull with Perl G Using Server Push with Perl G From Here G Chapter 7 Dynamic and Interactive HTML Content in Perl and CGI Creating ...

    PHP Web 2.0 Mashup Projects.pdf

    A mashup is a web page or application that combines data from two or more external online sources into an integrated experience. This book is your entryway to the world of mashups and Web 2.0. You ...

    HTML,XHTML,and.CSS.Bible,5th.Edition.pdf

    Serving as a tutorial and reference, this comprehensive resource explains the basic structure and necessary formatting to create a static (non-changing) and dynamic (changing) page on the Internet. ...

    网页保存为PDF文档工具

    软件的操作非常简单,双击软件压缩包中的“wnvhtml2pdf.exe”,在“Enter Web Page URL or File Path”后面输入网页的地址,然后勾选“Convert to PDF with selectable text onvert to PDF with embedded image”前...

    Solid.Converter.PDF v7.1

    Select the content you wish to convert to Word directly from the PDF page. Formatting, styles, layout preserved. - WYSIWYG 内容提取。 转换从 PDF 文件选出的表格或图象。在 Word 或 Excel 中创建表格或...

    The Essential Guide to HTML5.pdf

    Important new features such as the Canvas tag enable drawing directly onto the web page, the Audio tag allows sounds to be triggered and played from within your HTML code, the web sockets API brings ...

    Learning React (2nd Edition)

    In Learning React , author Kirupa Chinnathambi brings his fresh, clear, and very personable writing style to help web developers new to React understand its fundamentals and how to use it to build ...

    A Programmer's Guide to C# 5.0 pdf

    This book is for software developers who want to understand why C# 5 is designed the way it is and how to ...link on the book’s information page. Scroll down and click on the Source Code/Downloads tab.

    Learning React: Functional Web Development with React and Redux 英文版.azw3格式电子书

    Authors Alex Banks and Eve Porcello show you how to create UIs with this small JavaScript library that can deftly display data changes on large-scale, data-driven websites without page reloads....

Global site tag (gtag.js) - Google Analytics