PPT,Word,Excel,PDF,TXT转换图片

Aspose组件下载连接:http://pan.baidu.com/s/1slG2SdJ

1.所有的转换图片都要调用Aspose组件,在执行线程之前要先加上  LicenseHelper.ModifyInMemory.ActivateMemoryPatching();

//进入线程执行转换图片的方法
UploaderCalculators.Add(filePath, fileType, Id.ToString(), UId.ToString(), Server.MapPath(imgUrl), imgUrl);

类名:UploaderCalculators

 public class UploaderCalculators
    {

        //存入任务的队列
        private static Queue<string> _urlQueue;
        private static Queue<string> _typeQueue;
        private static Queue<string> _KcidQueue;
        private static Queue<string> _UserIdQueue;
        private static Queue<string> _imgUrlQueue;
        private static Queue<string> _imgQueue;
        private static ManualResetEvent _hasNew;
        private static bool isFirst = true;

        static UploaderCalculators()
        {
            _urlQueue = new Queue<string>();
            _typeQueue = new Queue<string>();
            _KcidQueue = new Queue<string>();
            _UserIdQueue = new Queue<string>();
            _imgUrlQueue = new Queue<string>();
            _imgQueue = new Queue<string>();
            _hasNew = new ManualResetEvent(false);

            //这里创建一个线程,使其执行Process方法。
            Thread thread = new Thread(Process);

            //设置当前线程为后台线程。
            thread.IsBackground = true;

            //开启线程
            thread.Start();
        }

        private static void Process()
        {
            while (true)
            {
                //等待接受信号,阻塞线程
                _hasNew.WaitOne();

                //接收信号,重置 信号器,信号关闭。
                _hasNew.Reset();

                threadStart();
            }
        }

        private static void threadStart()
        {
            CommonBll comm = new CommonBll();
            BaseController Base = new BaseController();
            while (true)
            {
                if (_urlQueue.Count > 0 && _typeQueue.Count > 0 && _KcidQueue.Count > 0 && _UserIdQueue.Count > 0)
                {
                    try
                    {
                        //文件路径
                        string Url = _urlQueue.Count > 0 ? _urlQueue.Dequeue() : "";//从队列的开始出返回一个对象;
                        //文件后缀名
                        string fileType = _typeQueue.Count > 0 ? _typeQueue.Dequeue() : "";//从队列的开始出返回一个对象;//转换图片后的存入路径
                        string imgUrl = _imgUrlQueue.Count > 0 ? _imgUrlQueue.Dequeue() : "";//从队列的开始出返回一个对象;
                        //
                        string img = _imgQueue.Count > 0 ? _imgQueue.Dequeue() : "";//从队列的开始出返回一个对象;
                        PictureConversion pc = new PictureConversion();

                        string imgName = string.Empty;
                        if (fileType == "docx" || fileType == "doc")
                        {
                            imgName = pc.ConvertToImage_Words(Url, imgUrl, 0, 0, null, 145, img);
                        }
                        if (fileType == "pptx" || fileType == "xlsx" || fileType == "xls" || fileType == "excel" || fileType == "excelx" || fileType == "ppt")
                        {
                            imgName = pc.ConvertToImage_PPT(Url, imgUrl, 0, 0, 145, fileType, img);
                        }
                        if (fileType == "pdf")
                        {
                            imgName = pc.ConvertToImage_PDF(Url, imgUrl, 0, 0, 145, img);
                        }
                        if (imgName != null && imgName != "")
                        {
                           //
                        }
                    }
                    catch (Exception e)
                    {
                        Console.Write(e);
                    }
                }
            }
        }

        public static void Add(string Url, string Type, string KcId, string UserId, string imgUrl, string img)
        {
            _urlQueue.Enqueue(Url);
            _typeQueue.Enqueue(Type);
            _KcidQueue.Enqueue(KcId);
            _UserIdQueue.Enqueue(UserId);
            _imgUrlQueue.Enqueue(imgUrl);
            _imgQueue.Enqueue(img);
            if (isFirst)
            {
                isFirst = false;
                _hasNew.Set();
            }
        }

    }

类名:PictureConversion

public class PictureConversion
{
/// <summary>
/// 将Word文档转换为图片的方法
/// </summary>
/// <param name="wordInputPath">Word文件路径</param>
/// <param name="imageOutputDirPath">图片输出路径,如果为空,默认值为Word所在路径</param>
/// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
/// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为Word总页数</param>
/// <param name="imageFormat">设置所需图片格式,如果为null,默认格式为PNG</param>
/// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
public string ConvertToImage_Words(string wordInputPath, string imageOutputDirPath, int startPageNum, int endPageNum, ImageFormat imageFormat, int resolution, string imgUrl)
{
try
{
Aspose.Words.Document doc = new Aspose.Words.Document(wordInputPath);

if (doc == null)
{
throw new Exception("Word文件无效或者Word文件被加密!");
}

if (imageOutputDirPath.Trim().Length == 0)
{
imageOutputDirPath = Path.GetDirectoryName(wordInputPath);
}

if (!Directory.Exists(imageOutputDirPath))
{
Directory.CreateDirectory(imageOutputDirPath);
}

if (startPageNum <= 0)
{
startPageNum = 1;
}

if (endPageNum > doc.PageCount || endPageNum <= 0)
{
endPageNum = doc.PageCount;
}

if (startPageNum > endPageNum)
{
int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
}

if (imageFormat == null)
{
imageFormat = ImageFormat.Png;
}

if (resolution <= 0)
{
resolution = 128;
}

string imageName = Path.GetFileNameWithoutExtension(wordInputPath);
Aspose.Words.Saving.ImageSaveOptions imageSaveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png);
imageSaveOptions.Resolution = resolution;
string imgName = string.Empty;
for (int i = startPageNum; i <= endPageNum; i++)
{
MemoryStream stream = new MemoryStream();
imageSaveOptions.PageIndex = i - 1;
string imgPath = Path.Combine(imageOutputDirPath, imageName) + "_" + i.ToString("000") + "." + imageFormat.ToString();
imgName += imgUrl + "/" + imageName + "_" + i.ToString("000") + "." + imageFormat.ToString() + "|";
doc.Save(stream, imageSaveOptions);
System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
System.Drawing.Bitmap bm = ESBasic.Helpers.ImageHelper.Zoom(img, 0.6f);
bm.Save(imgPath, imageFormat);
img.Dispose();
stream.Dispose();
bm.Dispose();
System.Threading.Thread.Sleep(200);
}
if (!string.IsNullOrEmpty(imgName))
{
imgName = imgName.Substring(0, imgName.Length - 1);
}
return imgName;
}

catch (Exception ex)
{
ErrorHandler.WriteError(ex);
throw;
}
}

/// <summary>
/// 将PPT、Excel、Txt文档转换为图片的方法
/// </summary>
/// <param name="originFilePath">ppt文件路径</param>
/// <param name="imageOutputDirPath">图片输出路径,如果为空,默认值为pdf所在路径</param>
/// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
/// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为pdf总页数</param>
/// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
public string ConvertToImage_PPT(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution, string Format, string imgUrl)
{
try
{
//先将文件转换为pdf临时文件
string tmpPdfPath = originFilePath.Replace(Format, "") + "pdf";
if (Format == ".xls" || Format == ".xlsx" || Format == ".txt")
{
Workbook wb = new Workbook(originFilePath);
wb.Save(tmpPdfPath, SaveFormat.Pdf);
}
else
{
Aspose.Slides.Presentation doc = new Aspose.Slides.Presentation(originFilePath);
if (doc == null)
{
throw new Exception("ppt文件无效或者ppt文件被加密!");
}

if (imageOutputDirPath.Trim().Length == 0)
{
imageOutputDirPath = Path.GetDirectoryName(originFilePath);
}

if (!Directory.Exists(imageOutputDirPath))
{
Directory.CreateDirectory(imageOutputDirPath);
}

if (startPageNum <= 0)
{
startPageNum = 1;
}

if (endPageNum > doc.Slides.Count || endPageNum <= 0)
{
endPageNum = doc.Slides.Count;
}

if (startPageNum > endPageNum)
{
int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
}

if (resolution <= 0)
{
resolution = 128;
}
if (doc != null)
{
doc.Save(tmpPdfPath, Aspose.Slides.Export.SaveFormat.Pdf);
}
}

//再将pdf转换为图片
string imgName = ConvertToImage_PDF(tmpPdfPath, imageOutputDirPath, startPageNum, endPageNum, resolution, imgUrl);
//删除pdf临时文件
File.Delete(tmpPdfPath);
return imgName;
}
catch (Exception ex)
{
ErrorHandler.WriteError(ex);
return "888";
throw;
}
}

/// <summary>
/// 将pdf文档转换为图片的方法
/// </summary>
/// <param name="originFilePath">pdf文件路径</param>
/// <param name="imageOutputDirPath">图片输出路径,如果为空,默认值为pdf所在路径</param>
/// <param name="startPageNum">从PDF文档的第几页开始转换,如果为0,默认值为1</param>
/// <param name="endPageNum">从PDF文档的第几页开始停止转换,如果为0,默认值为pdf总页数</param>
/// <param name="resolution">设置图片的像素,数字越大越清晰,如果为0,默认值为128,建议最大值不要超过1024</param>
public string ConvertToImage_PDF(string originFilePath, string imageOutputDirPath, int startPageNum, int endPageNum, int resolution, string imgUrl)
{
try
{
Aspose.Pdf.Document doc = new Aspose.Pdf.Document(originFilePath);

if (doc == null)
{
throw new Exception("pdf文件无效或者pdf文件被加密!");
}

if (imageOutputDirPath.Trim().Length == 0)
{
imageOutputDirPath = Path.GetDirectoryName(originFilePath);
}

if (!Directory.Exists(imageOutputDirPath))
{
Directory.CreateDirectory(imageOutputDirPath);
}

if (startPageNum <= 0)
{
startPageNum = 1;
}

if (endPageNum > doc.Pages.Count || endPageNum <= 0)
{
endPageNum = doc.Pages.Count;
}

if (startPageNum > endPageNum)
{
int tempPageNum = startPageNum; startPageNum = endPageNum; endPageNum = startPageNum;
}

if (resolution <= 0)
{
resolution = 128;
}

string imageNamePrefix = Path.GetFileNameWithoutExtension(originFilePath);
string imgName = string.Empty;
for (int i = startPageNum; i <= endPageNum; i++)
{
MemoryStream stream = new MemoryStream();
string imgPath = Path.Combine(imageOutputDirPath, imageNamePrefix) + "_" + i.ToString("000") + ".jpg";
imgName += imgUrl + "/" + imageNamePrefix + "_" + i.ToString("000") + ".jpg|";
Aspose.Pdf.Devices.Resolution reso = new Aspose.Pdf.Devices.Resolution(resolution);
Aspose.Pdf.Devices.JpegDevice jpegDevice = new Aspose.Pdf.Devices.JpegDevice(reso, 100);
jpegDevice.Process(doc.Pages[i], stream);

Image img = Image.FromStream(stream);
Bitmap bm = ESBasic.Helpers.ImageHelper.Zoom(img, 0.6f);
bm.Save(imgPath, ImageFormat.Jpeg);
img.Dispose();
stream.Dispose();
bm.Dispose();
System.Threading.Thread.Sleep(200);
}
if (!string.IsNullOrEmpty(imgName))
{
imgName = imgName.Substring(0, imgName.Length - 1);
}

return imgName;
}
catch (Exception ex)
{
ErrorHandler.WriteError(ex);
throw;
}
}

}

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Xml;

namespace LicenseHelper
{
    public static class ModifyInMemory
    {
        private static string AsposeList = "Aspose.3D.dll, Aspose.BarCode.dll, Aspose.BarCode.Compact.dll, Aspose.BarCode.WPF.dll, Aspose.Cells.GridDesktop.dll, Aspose.Cells.GridWeb.dll, Aspose.CAD.dll, Aspose.Cells.dll, Aspose.Diagram.dll, Aspose.Email.dll, Aspose.Imaging.dll, Aspose.Note.dll, Aspose.OCR.dll, Aspose.Pdf.dll, Aspose.Slides.dll, Aspose.Tasks.dll, Aspose.Words.dll";

        public static void ActivateMemoryPatching()
        {
            Assembly[] arr = AppDomain.CurrentDomain.GetAssemblies();
            foreach (Assembly assembly in arr)
            {
                if (AsposeList.IndexOf(assembly.FullName.Split(‘,‘)[0] + ".dll") != -1)
                    ActivateForAssembly(assembly);
            }
            AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(ActivateOnLoad);
        }

        private static void ActivateOnLoad(object sender, AssemblyLoadEventArgs e)
        {
            if (AsposeList.IndexOf(e.LoadedAssembly.FullName.Split(‘,‘)[0] + ".dll") != -1)
                ActivateForAssembly(e.LoadedAssembly);
        }

        private static void ActivateForAssembly(Assembly assembly)
        {
            MethodInfo miLicensed1 = typeof(ModifyInMemory).GetMethod("InvokeMe1", BindingFlags.NonPublic | BindingFlags.Static);
            MethodInfo miLicensed2 = typeof(ModifyInMemory).GetMethod("InvokeMe2", BindingFlags.NonPublic | BindingFlags.Static);
            MethodInfo miEvaluation = null;

            Dictionary<string, MethodInfo> miDict = new Dictionary<string, MethodInfo>()
            {
                {"System.DateTime"      , miLicensed1},
                {"System.Xml.XmlElement", miLicensed2}
            };

            Type[] arrType = null;
            bool isFound = false;
            int nCount = 0;

            try
            {
                arrType = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException err)
            {
                arrType = err.Types;
            }

            foreach (Type type in arrType)
            {
                if (isFound) break;

                if (type == null) continue;

                MethodInfo[] arrMInfo = type.GetMethods(BindingFlags.NonPublic | BindingFlags.Static);

                foreach (MethodInfo info in arrMInfo)
                {
                    if (isFound) break;

                    try
                    {
                        string strMethod = info.ToString();
                        if ((strMethod.IndexOf("(System.Xml.XmlElement, System.String)") > 0) && (miDict.ContainsKey(info.ReturnType.ToString())))
                        {
                            miEvaluation = info;
                            MemoryPatching(miEvaluation, miDict[miEvaluation.ReturnType.ToString()]);
                            nCount++;

                            if (((assembly.FullName.IndexOf("Aspose.Pdf") == -1) && (nCount == 2)) ||
                                ((assembly.FullName.IndexOf("Aspose.Pdf") != -1) && (nCount == 6)))
                            {
                                isFound = true;
                                break;
                            }
                        }
                    }
                    catch
                    {
                        throw new InvalidOperationException("MemoryPatching for \"" + assembly.FullName + "\" failed !");
                    }
                }
            }

            String[] aParts = assembly.FullName.Split(‘,‘);
            string fName = aParts[0];
            if (fName.IndexOf("Aspose.BarCode.") != -1)
                fName = "Aspose.BarCode";
            else if (fName.IndexOf("Aspose.3D") != -1)
                fName = "Aspose.ThreeD";

            try
            {
                Type type2 = assembly.GetType(fName + ".License");
                MethodInfo mi = type2.GetMethod("SetLicense", new Type[] { typeof(Stream) });
                string LData = "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPExpY2Vuc2U+CiAgPERhdGE+CiAgICA8TGljZW5zZWRUbz5MaWNlbnNlZTwvTGljZW5zZWRUbz4KICAgIDxFbWFpbFRvPmxpY2Vuc2VlQGVtYWlsLmNvbTwvRW1haWxUbz4KICAgIDxMaWNlbnNlVHlwZT5EZXZlbG9wZXIgT0VNPC9MaWNlbnNlVHlwZT4KICAgIDxMaWNlbnNlTm90ZT5MaW1pdGVkIHRvIDEwMDAgZGV2ZWxvcGVyLCB1bmxpbWl0ZWQgcGh5c2ljYWwgbG9jYXRpb25zPC9MaWNlbnNlTm90ZT4KICAgIDxPcmRlcklEPjc4NDM3ODU3Nzg1PC9PcmRlcklEPgogICAgPFVzZXJJRD4xMTk3ODkyNDM3OTwvVXNlcklEPgogICAgPE9FTT5UaGlzIGlzIGEgcmVkaXN0cmlidXRhYmxlIGxpY2Vuc2U8L09FTT4KICAgIDxQcm9kdWN0cz4KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIFByb2R1Y3QgRmFtaWx5PC9Qcm9kdWN0PgogICAgPC9Qcm9kdWN0cz4KICAgIDxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT4KICAgIDxTZXJpYWxOdW1iZXI+e0YyQjk3MDQ1LTFCMjktNEIzRi1CRDUzLTYwMUVGRkExNUFBOX08L1NlcmlhbE51bWJlcj4KICAgIDxTdWJzY3JpcHRpb25FeHBpcnk+MjA5OTEyMzE8L1N1YnNjcmlwdGlvbkV4cGlyeT4KICAgIDxMaWNlbnNlVmVyc2lvbj4zLjA8L0xpY2Vuc2VWZXJzaW9uPgogIDwvRGF0YT4KICA8U2lnbmF0dXJlPlFYTndiM05sTGxSdmRHRnNJRkJ5YjJSMVkzUWdSbUZ0YVd4NTwvU2lnbmF0dXJlPgo8L0xpY2Vuc2U+";
                Stream stream = new MemoryStream(Convert.FromBase64String(LData));
                stream.Seek(0, SeekOrigin.Begin);
                mi.Invoke(Activator.CreateInstance(type2, null), new Stream[] { stream });
            }
            catch
            {
                //throw new InvalidOperationException("SetLicense for \"" + assembly.FullName + "\" failed !");
            }

        }

        private static DateTime InvokeMe1(XmlElement element, string name)
        {
            return DateTime.MaxValue;
        }

        private static XmlElement InvokeMe2(XmlElement element, string name)
        {
            if (element.LocalName == "License")
            {
                string License64 = "PERhdGE+PExpY2Vuc2VkVG8+R3JvdXBEb2NzPC9MaWNlbnNlZFRvPjxMaWNlbnNlVHlwZT5TaXRlIE9FTTwvTGljZW5zZVR5cGU+PExpY2Vuc2VOb3RlPkxpbWl0ZWQgdG8gMTAgZGV2ZWxvcGVyczwvTGljZW5zZU5vdGU+PE9yZGVySUQ+MTMwNzI0MDQwODQ5PC9PcmRlcklEPjxPRU0+VGhpcyBpcyBhIHJlZGlzdHJpYnV0YWJsZSBsaWNlbnNlPC9PRU0+PFByb2R1Y3RzPjxQcm9kdWN0PkFzcG9zZS5Ub3RhbDwvUHJvZHVjdD48L1Byb2R1Y3RzPjxFZGl0aW9uVHlwZT5FbnRlcnByaXNlPC9FZGl0aW9uVHlwZT48U2VyaWFsTnVtYmVyPjliNTc5NTAxLTUyNjEtNDIyMC04NjcwLWZjMmQ4Y2NkZDkwYzwvU2VyaWFsTnVtYmVyPjxTdWJzY3JpcHRpb25FeHBpcnk+MjAxNDA3MjQ8L1N1YnNjcmlwdGlvbkV4cGlyeT48TGljZW5zZVZlcnNpb24+Mi4yPC9MaWNlbnNlVmVyc2lvbj48L0RhdGE+PFNpZ25hdHVyZT5udFpocmRoL3I0QS81ZFpsU2dWYnhac0hYSFBxSjZ5UVVYa0RvaW4vS2lVZWhUUWZET0lQdHdzUlR2NmRTUVplOVdXekNnV3RGdkdROWpmR2QySmF4YUQvbkx1ZEk2R0VVajhqeVhUMG4vbWRrMEF1WVZNYlBXRjJYd3dSTnFlTmRrblYyQjhrZVFwbDJ2RzZVbnhxS2J6VVFxS2Rhc1pzZ2w1Q0xqSFVEWms9PC9TaWduYXR1cmU+";
                element.InnerXml = new UTF8Encoding().GetString(Convert.FromBase64String(License64));
            }

            if (element.LocalName == "BlackList")
            {
                string BlackList64 = "PERhdGE+PC9EYXRhPjxTaWduYXR1cmU+cUJwMEx1cEVoM1ZnOWJjeS8vbUVXUk9KRWZmczRlY25iTHQxYlNhanU2NjY5RHlad09FakJ1eEdBdVBxS1hyd0x5bmZ5VWplYUNGQ0QxSkh2RVUxVUl5eXJOTnBSMXc2NXJIOUFyUCtFbE1lVCtIQkZ4NFMzckFVMnd6dkxPZnhGeU9DQ0dGQ2UraTdiSHlGQk44WHp6R1UwdGRPMGR1RTFoRTQ5M1RNY3pRPTwvU2lnbmF0dXJlPg==";
                element.InnerXml = new UTF8Encoding().GetString(Convert.FromBase64String(BlackList64));
            }

            XmlNodeList elementsByTagName = element.GetElementsByTagName(name);
            if (elementsByTagName.Count <= 0)
            {
                return null;
            }

            return (XmlElement)elementsByTagName[0];
        }

        private static unsafe void MemoryPatching(MethodBase miEvaluation, MethodBase miLicensed)
        {
            IntPtr IntPtrEval = GetMemoryAddress(miEvaluation);
            IntPtr IntPtrLicensed = GetMemoryAddress(miLicensed);

            if (IntPtr.Size == 8)
                *((long*)IntPtrEval.ToPointer()) = *((long*)IntPtrLicensed.ToPointer());
            else
                *((int*)IntPtrEval.ToPointer()) = *((int*)IntPtrLicensed.ToPointer());

        }

        private static unsafe IntPtr GetMemoryAddress(MethodBase mb)
        {
            RuntimeHelpers.PrepareMethod(mb.MethodHandle);

            if ((Environment.Version.Major >= 4) || ((Environment.Version.Major == 2) && (Environment.Version.MinorRevision >= 3053)))
            {
                return new IntPtr(((int*)mb.MethodHandle.Value.ToPointer() + 2));
            }

            UInt64* location = (UInt64*)(mb.MethodHandle.Value.ToPointer());
            int index = (int)(((*location) >> 32) & 0xFF);
            if (IntPtr.Size == 8)
            {
                ulong* classStart = (ulong*)mb.DeclaringType.TypeHandle.Value.ToPointer();
                ulong* address = classStart + index + 10;
                return new IntPtr(address);
            }
            else
            {
                uint* classStart = (uint*)mb.DeclaringType.TypeHandle.Value.ToPointer();
                uint* address = classStart + index + 10;
                return new IntPtr(address);
            }
        }
    }
}
时间: 2024-10-08 15:21:48

PPT,Word,Excel,PDF,TXT转换图片的相关文章

PDF文件格式转换攻略:PDF格式转换图片格式

关于PDF文件格式的转换大家有了解多少吗?就比如将PDF格式转换成图片格式,可能之前大家对于PDF件大家都有了解到,办公中我们经常遇到过.现在小编在这里教大家如何将PDF格式转换成图片格式,有兴趣的伙伴可以学着尝试一下! 1.操作之前可以将转换成图片格式的PDF文件另存到电脑桌面上,这样便于在后面的操作. 2.打开PDF转换器进入到操作的页面,在操作页面中可以选择到"PDF转成其他文件"栏目下的功能"文件转换图片",这一步完成之后,然后继续进行下一步操作.3.这时候

在Java中如何操作word, excel, pdf文件

java操作word,excel,pdf 在平常应用程序中,对office和pdf文档进行读取数据是比较常见的功能,尤其在很多web应用程序中.所以今天我们就简单来看一下java对word.excel.pdf文件的读取.本篇博客只是讲解简单应用.如果想深入了解原理.请读者自行研究一些相关源码. 首先我们来认识一下读取相关文档的jar包: 1. 引用POI包读取word文档内容 poi.jar 下载地址 http://apache.freelamp.com/poi/release/bin/poi-

Web方式预览Office/Word/Excel/pdf文件解决方案

最近在做项目时需要在Web端预览一些Office文件,经过在万能的互联网上一番搜索确定并解决了. 虽然其中碰到的一些问题已经通过搜索和自己研究解决了,但是觉得有必要将整个过程记录下来,以方便自己以后查找,也方便以后碰到相同问题的朋友. 首先大家都知道在浏览器中是无法直接直接打开office文件查看的(IE除外),所以我们需要将office文件转换成其他格式来预览. 所以我的实现方法是 office文件=>pdf文件=>swf文件=>flexpaper中浏览 我们用到的软件如下: 1.li

PDF/WORD/EXCEL 图片预览

一.PDF/WORD/EXCEL 转 XPS 转 第一页内容 转 图片 WORD.EXCEL转XPS (Office2010) public bool WordToXPS(string sourcePath, string targetPath) { bool result = false; Microsoft.Office.Interop.Word.WdExportFormat exportFormat = Microsoft.Office.Interop.Word.WdExportForma

那些PDF转换图片、PPT、Word的神操作,一键互转不是梦

无论你是职场办公,还是日常学习,只要使用电脑你就逃不开PDF文件. 因为PDF兼容性强,又能保证无论你在什么系统和端口打开的时候,内容格式都不会发生变形.尤其是在打印文件的时候,这个优势就特别明显. 今天咱们就来聊聊,关于PDF版本转换的那些事! 一.直接转换 直接转换的意思就是你不需要借助任何工具,也能直接进行版本转换.比如Word文档.Excel表格.PPT等,都能直接转换为PDF版本,这个小窍门很多人还不知道. 举个例子,将Excel表格直接换为PDF版本: 文件- -另存为- -选择保存

Atitit.office&#160;word&#160;&#160;excel&#160;&#160;ppt&#160;pdf&#160;的web在线预览方案与html转换方案&#160;attilax&#160;总结

Atitit.office word  excel  ppt pdf 的web在线预览方案与html转换方案 attilax 总结 1. office word  excel pdf 的web预览要求1 1.1. 显示效果要好1 1.2. 可以自定义显示界面1 1.3. 不需要控件,兼容性好1 1.4. 支持编辑操作1 2. 纯html预览解决之道(自由的格式)1 3. 转换swf flash方案2 4. 转换pdf方式..更多的浏览器已经直接支持pdf格式查看2 5. 控件方式2 6. Hyb

怎样把PDF转换成PPT?迅捷PDF转换器来助力

PDF文件因它的安全性和保密性而被广泛的使用,不管是什么格式文件,只要文件内容太长看起来都会烦躁,但是把PDF转换成PPT就会好很多,看完一张滑动一下鼠标就可以看下一张了.那么怎样把PDF转换成PPT呢?迅捷PDF转换器:PDF转PPT图文教程一.下载安装并运行PDF转换器--点击软件界面中的[文件转PPT]--添加需要转换的PDF文件(这里提供三种添加方式:直接拖拽.添加文件.添加文件夹): 二.添加PDF文件后,软件展示出相关的属性设置,包括:排列方式:缩略图.列表,输出目录:原文件夹.自定

如何把文档从pdf格式转换成word格式

在求职时,你会不会为简历的格式而犯愁,Word文档还是PDF格式呢?Word好编辑,PDF好阅读.一般统一都是Word多些吧,但是HR也会经常收到PDF格式的简历.PDF 是一个很有价值的工具,求职者是否 care 这份机会,是否珍视他自己的专业经历,很大一部分会反映到排版的认真程度.有些HR还会比较欣赏愿意花时间把Word转成PDF格式的候选人,因为这样做会让简历阅读的感觉比较好.但是很多公司有自己的招聘系统Word一般支持附件解析,可如果是PDF格式,那么把简历录入系统基本就需要手动完成了,

[原创]java实现word转pdf

最近遇到一个项目需要把word 转成pdf,百度了一下网上的方案有很多,比如虚拟打印.给word 装扩展插件等,这些方案都依赖于ms word 程序,在java代码中也得使用诸如jacob或jcom这类java com bridge,使得服务器开发受限于win平台,而且部署起来也很麻烦.后来在某论坛看到了一个openoffice+jodconverter的转换方案,可以完成word到PDF的转换工作,服务器开发端需要安装openoffice,但是需求一步额外的操作--需要在服务器开发上的某个端口