Aspose for net office转pdf的问题

.Net技术 码拜 5年前 (2016-05-30) 578次浏览
原因是想做一个类百度文库的在线文件浏览系统,所以采用了FlexPaper+SWFTool的方法,并使用Aspose插件来将office转换成pdf。而实际操作中,一直没能成功将office文件转换成pdf,菜鸟程序猿在此求指导。以下是本人在后台(C#)的代码:
class MY_FILEVIEW
{
string pdf2swfToolPath = System.Web.HttpContext.Current.Server.MapPath(“C:/Program Files/SWFTools/pdf2swf.exe”);
#region   word转换pdf
public void ConvertWordToPDF(string wordFolderPath, string pdfFolderPath)
{
pdfFolderPath = wordFolderPath;
Document doc = new Document(wordFolderPath);
doc.Save(pdfFolderPath,Aspose.Words.SaveFormat.Pdf);
}
#endregion
#region   excel转换pdf
//../../filedata/filemanager/201607/2016%E5%B7%A5%E4%BD%9C%E8%AE%A1%E5%88%92_%E6%9D%8E%E9%9F%A920162028112016.xls
public void ConvertExcelToPDF(string excelFolderPath, string pdfFolderPath)
{
Document doc = new Document(excelFolderPath);
doc.Save(pdfFolderPath, Aspose.Words.SaveFormat.Pdf);
}
#endregion
#region   ppt转换pdf
public void ConvertPptToPDF(string pptFolderPath, string pdfFolderPath)
{
Document doc = new Document(pptFolderPath);
doc.Save(pdfFolderPath, Aspose.Words.SaveFormat.Pdf);
}
#endregion

}
}
以下是在前台调用的代码:
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”MY_FILEKIND.aspx.cs” Inherits=”Main_14MY_FM_FILEKIND” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
<title>文件阅览</title>
<script src=”../../js/jquery-1.8.2.js” type=”text/javascript”></script>
<link class=”ui-theme” href=”../../themes/cupertino/jquery-ui-1.9.0.custom.min.css ”
rel=”Stylesheet” type=”text/css” />
<link class=”jquery-myui-theme” href=”../../css/myui.css ” rel=”Stylesheet” type=”text/css” />
<link class=”jquery-lanyoutui-theme” href=”../../themes/jqurylayout.css ” rel=”Stylesheet”
type=”text/css” />
<script src=”../../js/jquery-ui-min.js” type=”text/javascript”></script>
<script src=”../../js/jquery.layout.min.js” type=”text/javascript”></script>
<script src=”../../js/myui/jquery.myui-min.js” type=”text/javascript”></script>
<script src=”../../js/myui/jquery.myui.gridview.js” type=”text/javascript”></script>
<script src=”../../js/flot/jquery.flot.min.js” type=”text/javascript”></script>
<link href=”../../Css/treeview.css” rel=”stylesheet” type=”text/css” />
<script src=”../../js/treeview.js” type=”text/javascript”></script>

<script type=”text/javascript” src=”../../js/swfobject/swfobject.js”></script>

<script type=”text/javascript” src=”../../js/flexpaper_flash.js”></script>
<script type=”text/javascript”>
var levelno = 1;
$(function() {
myLayout = $(“body”).layout({
west__size: .15,
east__size: .52,
onresize__end: autoAdjust
});
///以下为树状图功能///
var treedata = $.myui.invoke(“MY.BLL.MY_FILEKIND.GetTreeView”);
var currid = “-1”, currname = “文件类别”;
var t = eval(treedata);
$(“#tr_mytest”).treeview({
data: t,
theme: “bbit-tree-lines”,
showcheck: false,
onnodeclick: test
, persist: “location”,
collapsed: true,
bgimage: “../../themes/Shared/Images/s.gif”,
cbiconpath: “../../images/icons/”, //checkbox 路径
prerendered: true,
unique: true
})
function test(a, b) {
currid = a.id;
currname = a.text;
levelno = parseInt(a.levelno) + 1;
gv_file.gridview(“setCond”, { dataid: currid });
gv_file.gridview(“query”);
}
//以下是文件列表
var gv_file = $(“#gv_file”);
gv_file.gridview({
fixCols: 1 //固定左边4栏
, pageSize: 50
, name: “附件”//名称
, toolbarSimple: true
, className: “MY.BLL.MY_DOCFILE”
, ExcelShow: true
, readonly: true
, columns: [
{ id: “filesid”, name: “#ID”, type: “string”, iskey: 1, size: 120, hidden: 1 }
, { id: “dataid”, name: “#ID”, type: “string”, size: 120, hidden: 1 }
, { id: “filename”, name: “文件件名称”, type: “string”, size: 300, readonly: 1
}
, { id: “url”, name: “路径”, type: “string”, hidden: 0, min: “1”, hidden: 1, size: 520 }
]
});
var gv_file = $(“#gv_file”);
gv_file.bind(“gridviewrowselected”, {}, function() {
var row = gv_file.gridview(“row”);
$.myui.invoke(“MY.BLL.MY_FILEVIEW.ConvertWordToPDF”, [row.url], { together: false })
alert(row.url);
});
//下面是文件浏览区域
//            <!– For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. –>
var swfVersionStr = “10.0.0”;
//            <!– To use express install, set to playerProductInstall.swf, otherwise the empty string. –>
var xiSwfUrlStr = “playerProductInstall.swf”;
var flashvars = {
SwfFile: escape(“Paper.swf”),
Scale: 0.6,
ZoomTransition: “easeOut”,
ZoomTime: 0.5,
ZoomInterval: 0.1,
FitPageOnLoad: false,
FitWidthOnLoad: true,
PrintEnabled: true,
FullScreenAsMaxWindow: false,
ProgressiveLoading: true,
PrintToolsVisible: true,
ViewModeToolsVisible: true,
ZoomToolsVisible: true,
FullScreenVisible: true,
NavToolsVisible: true,
CursorToolsVisible: true,
SearchToolsVisible: true,
localeChain: “en_US”
};
var params = {
}
params.quality = “high”;
params.bgcolor = “#ffffff”;
params.allowscriptaccess = “sameDomain”;
params.allowfullscreen = “true”;
var attributes = {};
attributes.id = “FlexPaperViewer”;
attributes.name = “FlexPaperViewer”;
swfobject.embedSWF(
“FlexPaperViewer.swf”, “flashContent”,
“650”, “650”,
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
swfobject.createCSS(“#flashContent”, “display:block;text-align:left;”);
function autoAdjust() {
fv_viewer.gridview(“adjust”);
tr_mytest.gridview(“adjust”);
gv_file.gridview(“adjust”);
}
});
</script>
</head>
<body>
<div class=”ui-layout-west” style=”display: none;”>
<div id=”tr_mytest”>
</div>
</div>
<div class=”ui-layout-east” style=”display: none;”>
<div style=”position:absolute;left:10px;top:10px;” id=”fv_viewer”>
<div id=”flashContent”>
<p>
To view this page ensure that Adobe Flash Player version
10.0.0 or greater is installed.
</p>
<script type=”text/javascript”>
var pageHost = ((document.location.protocol == “https:”) ? “https://” : “http://”);
document.write(“<a href=”http://www.adobe.com/go/getflashplayer”><img src=””
+ pageHost + “www.adobe.com/images/shared/download_buttons/get_flash_player.gif” alt=”Get Adobe Flash player” /></a>”);
</script>
</div>
</div>
</div>
<div class=”ui-layout-center” style=”display: none;”>
<div id=”gv_file”>
</div>
</div>
</body>
</html>
本人是在另一个页面上上传文件的,通过通过treeview插件显示到本页面上,在本页面上的treeview获取文件路径并传给后台的。原因是篇幅不够,本人把pdf转swf的代码删除了才发出来的、

解决方案

40

本人在 WinForm 中使用没有问题:
下面是从慧都网下载的示例(部分注释加了中文)

// 将工作簿保存为各种格式的文档
using System.IO;
using Aspose.Cells;
namespace SavingFiles
{
    public class Program
    {
        public static void Main(string[] args)
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");
            //Creating a Workbook object
            Workbook workbook = new Workbook();
            //Your Code goes here for any workbook related operations
            // 您的代码在这里进行任何与工作相关的工作
            //Save in Excel 97 – 2003 format
			// 保存为 Excel 97 至 2003 格式
            workbook.Save(dataDir + "book1.xls");
            //OR
			// 保存为 Excel 97 至 2003 格式
            workbook.Save(dataDir + "book1.xls", new XlsSaveOptions(SaveFormat.Excel97To2003));
            //Save in Excel2007 xlsx format
			// 保存为 Excel 2007 格式
            workbook.Save(dataDir + "book1.xlsx", SaveFormat.Xlsx);
            //Save in Excel2007 xlsb format
			// 保存为 Excel 2007 的二进制工作簿
            workbook.Save(dataDir + "book1.xlsb", SaveFormat.Xlsb);
            //Save in ODS format
			// 保存为 OpenOffice 的数据文档
            workbook.Save(dataDir + "book1.ods", SaveFormat.ODS);
            //Save in Pdf format
			// 保存为 PDF 文档
            workbook.Save(dataDir + "book1.pdf", SaveFormat.Pdf);
            //Save in Html format
			// 保存为 Html 文档
            workbook.Save(dataDir + "book1.html", SaveFormat.Html);
            //Save in SpreadsheetML format
			// 保存为 XML 文档
            workbook.Save(dataDir + "book1.xml", SaveFormat.SpreadsheetML); 
        }
    }
}

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Aspose for net office转pdf的问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)