使用uploadfile按钮上载文件时如何计算PDF和.docx文件中的页数 [英] How to count the number of pages in a PDF and .docx file when the file is uploaded using the uploadfile button

查看:95
本文介绍了使用uploadfile按钮上载文件时如何计算PDF和.docx文件中的页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个项目,系统允许用户上传PDF文件或.docx文件。我想要的是,当上传文件时,系统应该能够计算并显示上传文件的页数。它是一个webform应用程序。



我尝试过:



Don我不知道代码是怎么样的。

I am working on a project and I the system allows a user to upload either a PDF file or a .docx file. What I want is that when a file is uploaded, the system should be able to count and display the number of pages the uploaded file has. It a webform application.

What I have tried:

Don't have any idea on how the code looks like.

推荐答案

这不简单:你需要将文件传递给可以读取PDF(或DOCX)的东西并计算出页数(这并不简单,因为在很多情况下它会根据当前所选打印机的纸张大小而有所不同!)



然后你必须询问应用程序有多少页面。

对于PDF,请从iTextSharp API开始。

对于DOCX,您将掌握在Google手中 - 但大部分是您会发现的解决方案将引用Word Interop,这可能无法在您的网络服务器上运行,因为它几乎肯定不会安装Office!
That's not simple: you will need to pass the file to something that can read a PDF (or DOCX) and work out the pages count (And that's not simple, because in many cases it will vary according to the currently selected printer's paper size!)

Then you have to ask the app how many pages.
For PDF, start with the iTextSharp API.
For DOCX, you are going to be in the hands of Google - but most of the solutions you will find will reference Word Interop, and that probably won't work on your webserver as it will almost certainly not have Office installed!


这篇关于使用uploadfile按钮上载文件时如何计算PDF和.docx文件中的页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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