PDF 和 Silverlight,它们可以一起工作吗?
我有一个项目,我在其中创建示例文档。此处的代码:
private void btnExcel_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (AutomationFactory.IsAvailable)
{
dynamic excel = AutomationFactory.CreateObject("Excel.Application");
excel.Visible = true;
dynamic workbook = excel.workbooks;
workbook.Add();
dynamic sheet = excel.ActiveSheet;
dynamic cell = null;
int i;
int z = 20;
for (i = 1; i <= 20; i++)
{
cell = sheet.Cells[i, 1];
cell.Value = i.ToString();
cell = sheet.Cells[i, 2];
cell.Value = z.ToString();
z--;
}
}
}
如您所见,这是针对 Excel 文档的。有什么办法可以将类似的内容导出为 PDF 文件吗?感谢您的见解。
I have a project where I create sample documents. Code here :
private void btnExcel_Click(object sender, System.Windows.RoutedEventArgs e)
{
if (AutomationFactory.IsAvailable)
{
dynamic excel = AutomationFactory.CreateObject("Excel.Application");
excel.Visible = true;
dynamic workbook = excel.workbooks;
workbook.Add();
dynamic sheet = excel.ActiveSheet;
dynamic cell = null;
int i;
int z = 20;
for (i = 1; i <= 20; i++)
{
cell = sheet.Cells[i, 1];
cell.Value = i.ToString();
cell = sheet.Cells[i, 2];
cell.Value = z.ToString();
z--;
}
}
}
As you can see, this is for Excel documents. Is there any way I can something like this and export in to PDF files? Thanks for the insights.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,你可以。
您可以调用 WCF 服务操作并向其传递所需的所有数据。然后执行生成 PDF 文件所需的所有操作。完成此操作后,您有两个选择:
SaveDialog
,以将文件保存到本地磁盘。我希望这就是您正在寻找的。
Yes you can.
You can call a WCF service operation passing it all the data that it needs. Then do all what is required to generate the PDF file. After you've done that, you have two options:
SaveDialog
to save the file to his local disk.I hope that was what you're looking for.
当然,你可以。但为什么?!据我了解,使用 AutomationFactory.CreateObject,您可以在客户端计算机上安装 Excel 或 PDF 时执行此操作。
但是处理 Web 应用程序(特别是当它不是企业应用程序时),您希望在任何地方看到 pdf/xls/xlsx/...,并且您可以中继客户端计算机上安装的内容或不安装的内容。
我的一个项目也有类似的情况。我们使用 XPS 格式在 silverlight 中显示,因为它具有本机支持。而其他格式则转换为xps。
转换中存在细微差别,例如对于 Excel 文档,我认为最好的方法是单独转换每个工作表,并实现与查看器不同的特殊类型查看器,例如对于 Word 文档或 pdf 文件。
有 3rd 方查看器不仅允许在 silverlight 上查看 xps,还允许查看 pdf。但如果没有它们,您只能让用户下载 PDF 文件而不能查看该文件,因为这些第三部分查看器很可能在幕后将 pdf 转换为 xps。
无论如何,尤其是在没有第三方的情况下,在 silverlight 上实现 PDF 查看器将需要付出巨大的努力。所以我建议你使用xps来查看。但是,当您需要下载 pdf 文件时,请使用 XPS 进行查看并使用 PDF 进行下载。在这种情况下,您的转换器将为每个站点生成 2 种格式。
例如,请查看
http://firstfloorsoftware.com/blog/announcement-document -toolkit-for-silverlight/
http://silverpdf.codeplex.com/
http://www.componentone.com/SuperProducts/PdfViewerSilverlight/
Sure, you can. But why?! As I understand with AutomationFactory.CreateObject you can do it when on client machine Excel or PDF are installed.
But dealing with web application (especially when it's not an enterprise applications) you want to see pdf/xls/xlsx/... anywhere and you can relay on what is installed on client machine or not.
I have similar situation for one of my projects. We are using XPS format to show in silverlight because it has native support. And other formats are converted to xps.
There nuances in conversion, e.g. for excel documents I think best way is to convert each sheet separately, and implement special kind viewer that differs from viewer, for example, for word documents or pdf's.
There are 3rd party viewers that allow to view not only xps on silverlight but pdf too. But without them you can only let user to download PDF file not to view that, because these 3rd part viewer most likely convert pdf to xps under the hood.
Any way, especially without 3rd parties, it will take huge efforts to implement PDF viewer on silverlight. So I suggest you to use xps for viewing. But when you need to have pdf files for downloads than use XPS for viewing and PDF on download. In such case your converters will produce 2 formats for each sitation.
For example, look at
http://firstfloorsoftware.com/blog/announcement-document-toolkit-for-silverlight/
http://silverpdf.codeplex.com/
http://www.componentone.com/SuperProducts/PdfViewerSilverlight/