Coder Social home page Coder Social logo

officeconverter's Introduction

OfficeConverter

Convert Microsoft Office document to PDF (Office 2007 - 2016)

  • 2014-09-21 Version 1.0
    • Converts .DOC, .DOCM, .DOCX, .DOT, .DOTM, .ODT, .XLS, .XLSB, .XLSM, .XLSX, .XLT, .XLTM, .XLTX, .XLW, .ODS, .POT, .PPT, .POTM, .POTX, .PPS, .PPSM, .PPSX, .PPTM, .PPTX and .ODP files to PDF with the use of Microsoft Office
    • Checks if the files are password protected without using Microsoft Office to speed up conversion

License Information

OfficeConverter is Copyright (C)2014-2024 Kees van Spelde and is licensed under the MIT license:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Installing via NuGet

The easiest way to install OfficeConverter is via NuGet.

In Visual Studio's Package Manager Console, simply enter the following command:

Install-Package OfficeConverter 

Converting a file from code

using (var converter = new Converter())
{
    converter.Convert(<inputfile>, <outputfile>);
}

Logging

From version 1.7.0 OfficeConverter uses the Microsoft ILogger interface (https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.logging.ilogger?view=dotnet-plat-ext-5.0). You can use any logging library that uses this interface.

OfficeConverter has some build in loggers that can be found in the OfficeConverter.Logger namespace.

For example

var logger = !string.IsNullOrWhiteSpace(<some logfile>)
                ? new ChromeHtmlToPdfLib.Loggers.Stream(File.OpenWrite(<some logfile>))
                : new ChromeHtmlToPdfLib.Loggers.Console();

Core Team

Sicos1977 (Kees van Spelde)

Support

If you like my work then please consider a donation as a thank you.

Reporting Bugs

Have a bug or a feature request? Please open a new issue.

Before opening a new issue, please search for existing issues to avoid submitting duplicates.

officeconverter's People

Contributors

anthonychaussin-d4e avatar dependabot[bot] avatar sajidur78 avatar sicos1977 avatar sicos2002 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

officeconverter's Issues

Rights when running as windows service

When running as windows service (the service is running as administeator) The file 'name.xls' is password protected.
But the file is not.And this happen to all xlsx files.If run as console applicaion everything is fine.

The file '' seems to be corrupt

Hello I'm having this issue and I can't find a way to go around it.

The file 'OrderSummary.docx' seems to be corrupt, error: Object reference not set to an instance of an object.

image

I have Office Installed and activated and the library works just fine on my development environment. The issue is just after deploy.

I give permissions to the folder, I'm able to open the document on Word and manually convert.

Do you have any ideas?

With a windows service, Word file conversion error

By launching the conversion of a word document in a webservice, I have the error "The file 'doc.docx' seems to be corrupt, error: Object reference not set to an instance of an object".
Is there a special configuration for windows services? The same conversion from a console application works.

Getting Error while deploying my code to Azure App Service

I needed to convert .DOCX, .XLS, .XLXS file to .PDF file as part of my app. It's working fine on my local machine, as I have MS office installed on my system. But When I tried to deploy this application in Azure App Service plan, then it's not working as MS office is not available. I know we can install both our app and MS office in a VM and it will work. But is there any way we can deploy this app in Azure App Service or Containerize?

ErrorMessage: Could not read registry to check Word version.
InnerException: Could not find registry key Word.Application\CurVer.
StackTrace: at OfficeConverter.Word..ctor()
at OfficeConverter.Converter.get_Word()
at OfficeConverter.Converter.Convert(String inputFile, String outputFile, Stream logStream)

Perform prerequisites tests before launching pdf transformation

I was coping with #13 (pdf transformation not working when using OfficeConverter as a Window Service). As mentioned in this issue the two folders must be created :

  • Windows x64: C:\Windows\SysWOW64\config\systemprofile\Desktop
  • Windows x86: C:\Windows\System32\config\systemprofile\Desktop

I would say in my case that that System32 was causing the issue even if we are in a 64 bits OS server.

In our context we decided to use this project and to create a new module to run it as an executable (and not a service).

What I suggest is to create these folders before the transformation take place (what we did) :
It is important to disable the redirection before creating the system32 folder

        #region general prerequisites

        private static void CheckIfSystemProfileDesktopDirectoryExists()
        {
            if (NativeMethods.IsWindowsServer())
            {
                Wow64Interop.DisableWow64FSRedirection(IntPtr.Zero); // to really test system32 folder !
                var x86DesktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                    @"System32\config\systemprofile\desktop");
                try
                {
                    Logger.WriteToLog("Prerequisites action: About to create x86 desktop path" + x86DesktopPath);
                    Directory.CreateDirectory(x86DesktopPath);
                    Logger.WriteToLog(x86DesktopPath + " created successfully");
                }
                catch (Exception exception)
                {
                    throw new OCConfiguration(
                        $"Prerequisites error: Can't create folder '{x86DesktopPath}' folder to perform PDF rendition",
                        exception);
                }
                Wow64Interop.Wow64RevertWow64FsRedirection(IntPtr.Zero);
                var x64DesktopPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows),
                    @"SysWOW64\config\systemprofile\desktop");

                try
                {
                    Logger.WriteToLog("Prerequisites action: About to create X64 desktop path" + x64DesktopPath);
                    Directory.CreateDirectory(x64DesktopPath);
                    Logger.WriteToLog(x64DesktopPath + " created successfully");
                }
                catch (Exception exception)
                {
                    throw new OCConfiguration(
                        $"Prerequisites error: Can't create folder '{x64DesktopPath}', folder is needed to perform PDF rendition",
                        exception);
                }
            }
        }

        #endregion
    }
    
    /// <summary>
    /// Utility class to disable 32 to 64 file to redirection 
    /// </summary>
    internal static class Wow64Interop
    {
        private const string Kernel32dll = "Kernel32.Dll";

        [DllImport(Kernel32dll, EntryPoint = "Wow64DisableWow64FsRedirection")]
        public static extern bool DisableWow64FSRedirection(IntPtr ptr);

        [DllImport(Kernel32dll, EntryPoint = "Wow64RevertWow64FsRedirection")]
        public static extern bool Wow64RevertWow64FsRedirection(IntPtr ptr);
    }

Exception thrown: 'System.AccessViolationException' in OfficeConverter.dll

This issue is coming while converting excel files to PDF. Is this a known bug or am I doing something wrong ?
I have already tried changing architecture to x86 while compiling the code. The same does not resolve the issue.

Exception thrown: 'System.AccessViolationException' in OfficeConverter.dll
An unhandled exception of type 'System.AccessViolationException' occurred in OfficeConverter.dll
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

// PrintCommunication = true // DO NOT REMOVE THIS LINE, NO NEVER EVER ... DON'T EVEN TRY IT
if the line above in excel.cs file is commented, then conversion works fine. I am using MS Office 2007.

cli_basetypes and rest types 64bit

Hi,

In my inhouse solution for open office i have very similar idea of converting odt to pdf. Problem occurs when i migrate solution to 64bit. I tried use your libs from x64 folder but i think there version mismatch which couse some core error in openoffice
https://github.com/Sicos1977/OfficeConverter/tree/master/OfficeConverter/CLI/x64

Question.
Where did you found these libs for x64?
I was unable to find and some forums mentioned that it dont even exist for x64.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.