从DIV标签的内容生成PDF [英] Generating PDF from content of DIV tag

查看:163
本文介绍了从DIV标签的内容生成PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个带有div控件的页面,我想从该div控件中生成pdf,而无需使用第三方工具(例如ItextSharp或任何其他工具).

谢谢

Hello Everyone,

I have page with a div control , i want to generate pdf from that div control without using third party tool like ItextSharp or any other.

Thanks

推荐答案

你好,
我写了一个教程,解释了如何将.doc转换为pdf文件.我没有使用第三方,但必须安装Microsoft Office.

如果您可以生成doc或任何形式的办公室"文件,则可以将其转换为pdf.

我用来转换的代码是:

Hello,
I wrote a tutorial explaining how to convert a .doc in a pdf file. I didn''t use third party, but Microsoft Office must be installed.

If you can generate a doc, or any sort of "office" file, it can be converted to pdf.

The code I used to convertion is:

private void ConvertWord2PDF(string inputFile, string outputPath)
{
	try
	{
		if (outputPath.Equals("") || !File.Exists(inputFile))
		{
			throw new Exception("Either file does not exist or invalid output path");
		}

		// app to open the document belower
		Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
		Document wordDocument = new Document();

		// input variables
		object objInputFile = inputFile;
		object missParam = Type.Missing;                
		
		wordDocument = wordApp.Documents.Open(ref objInputFile, ref missParam, ref missParam, ref missParam,
			ref missParam, ref missParam, ref missParam, ref missParam, ref missParam, ref missParam,
			ref missParam, ref missParam, ref missParam, ref missParam, ref missParam, ref missParam);

		if (wordDocument != null)
		{
			// make the convertion
			wordDocument.ExportAsFixedFormat(outputPath, WdExportFormat.wdExportFormatPDF, false,
				WdExportOptimizeFor.wdExportOptimizeForOnScreen, WdExportRange.wdExportAllDocument,
				0, 0, WdExportItem.wdExportDocumentContent, true, true, 
				WdExportCreateBookmarks.wdExportCreateWordBookmarks, true, true, false, ref missParam);                                                    
		}

		// close document and quit application
		wordDocument.Close();
		wordApp.Quit();

		MessageBox.Show("File successfully converted");
		ClearTextBoxes();
	}
	catch (Exception e)
	{                
		throw e;
	}
}



但是整个教程可以在这里找到
http://codeabout.wordpress.com/2012 /03/20/convert-a-word-file-to-pdf-with-c/ [



But the entire tutorial can be found here
http://codeabout.wordpress.com/2012/03/20/convert-a-word-file-to-pdf-with-c/[^]

I don''t know if this is exactly what you are looking for, but i hope it helps.
Regards,
Felipe


这篇关于从DIV标签的内容生成PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆