Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to convert document to PDF format in Asp.net using c#

How to convert document to PDF format in Asp.net using c#

Scheduled Pinned Locked Moved ASP.NET
csharphelpasp-netcomwindows-admin
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hemananthan
    wrote on last edited by
    #1

    Can anybody help me programatically to get the solution for converting any type of document to PDF format we already tried through this coding: public static void ConverWordToPDF(string Filepath, string Targetpath) { object Unknown = Type.Missing; object Source = Filepath; object Target = Targetpath; ApplicationClass MSdoc = new ApplicationClass(); try { MSdoc.Visible = false; MSdoc.Documents.Open(ref Source, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); MSdoc.Application.Visible = false; MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize; object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; MSdoc.ActiveDocument.SaveAs(ref Target, ref format, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); } catch (Exception e) { log.Info("Converted Word to PDF", e); } finally { if (MSdoc != null) { MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown); } MSdoc.Quit(ref Unknown, ref Unknown, ref Unknown); } } Normally in while runing this application in local its working fine in XP System: while run through IIS i getting the following error: System.Runtime.InteropServices.COMException (0x800A11FD): =================== System.Runtime.InteropServices.COMException (0x800A11FD): This method or property is not available because a document window is not active. at Microsoft.Office.Interop.Word.Documents.Close(Object& SaveChanges, Object& OriginalFormat, Object& RouteDocument) Can anybody suggest me how to resolve it or any new solution for conversion process

    Thanks Regards Hemananthan.S ===============

    A F T 3 Replies Last reply
    0
    • H hemananthan

      Can anybody help me programatically to get the solution for converting any type of document to PDF format we already tried through this coding: public static void ConverWordToPDF(string Filepath, string Targetpath) { object Unknown = Type.Missing; object Source = Filepath; object Target = Targetpath; ApplicationClass MSdoc = new ApplicationClass(); try { MSdoc.Visible = false; MSdoc.Documents.Open(ref Source, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); MSdoc.Application.Visible = false; MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize; object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; MSdoc.ActiveDocument.SaveAs(ref Target, ref format, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); } catch (Exception e) { log.Info("Converted Word to PDF", e); } finally { if (MSdoc != null) { MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown); } MSdoc.Quit(ref Unknown, ref Unknown, ref Unknown); } } Normally in while runing this application in local its working fine in XP System: while run through IIS i getting the following error: System.Runtime.InteropServices.COMException (0x800A11FD): =================== System.Runtime.InteropServices.COMException (0x800A11FD): This method or property is not available because a document window is not active. at Microsoft.Office.Interop.Word.Documents.Close(Object& SaveChanges, Object& OriginalFormat, Object& RouteDocument) Can anybody suggest me how to resolve it or any new solution for conversion process

      Thanks Regards Hemananthan.S ===============

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Plese, use PRE tag for your code block ! Like,

      public static void ConverWordToPDF(string Filepath, string Targetpath)
      {

      object Unknown = Type.Missing;
      object Source = Filepath;
      object Target = Targetpath;

      ApplicationClass MSdoc = new ApplicationClass();

      try
      {

      MSdoc.Visible = false;
      MSdoc.Documents.Open(ref Source, ref Unknown,
      ref Unknown, ref Unknown, ref Unknown,
      ref Unknown, ref Unknown, ref Unknown,
      ref Unknown, ref Unknown, ref Unknown,
      ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
      MSdoc.Application.Visible = false;
      MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize;

      object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

      MSdoc.ActiveDocument.SaveAs(ref Target, ref format,
      ref Unknown, ref Unknown, ref Unknown,
      ref Unknown, ref Unknown, ref Unknown,
      ref Unknown, ref Unknown, ref Unknown,
      ref Unknown, ref Unknown, ref Unknown,
      ref Unknown, ref Unknown);
      }
      catch (Exception e)
      {
      log.Info("Converted Word to PDF", e);

      }
      finally
      {
      if (MSdoc != null)
      {
      MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown);

      }

      MSdoc.Quit(ref Unknown, ref Unknown, ref Unknown);
      }
      }

      It will help us to read the code properly.

      Cheers ! Abhijit Jana | My Blog | @Twitter | Disclaimer

      :bob: Indian CodeProject Members Meet 2010 - Nominate Now :bob:

      1 Reply Last reply
      0
      • H hemananthan

        Can anybody help me programatically to get the solution for converting any type of document to PDF format we already tried through this coding: public static void ConverWordToPDF(string Filepath, string Targetpath) { object Unknown = Type.Missing; object Source = Filepath; object Target = Targetpath; ApplicationClass MSdoc = new ApplicationClass(); try { MSdoc.Visible = false; MSdoc.Documents.Open(ref Source, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); MSdoc.Application.Visible = false; MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize; object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; MSdoc.ActiveDocument.SaveAs(ref Target, ref format, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); } catch (Exception e) { log.Info("Converted Word to PDF", e); } finally { if (MSdoc != null) { MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown); } MSdoc.Quit(ref Unknown, ref Unknown, ref Unknown); } } Normally in while runing this application in local its working fine in XP System: while run through IIS i getting the following error: System.Runtime.InteropServices.COMException (0x800A11FD): =================== System.Runtime.InteropServices.COMException (0x800A11FD): This method or property is not available because a document window is not active. at Microsoft.Office.Interop.Word.Documents.Close(Object& SaveChanges, Object& OriginalFormat, Object& RouteDocument) Can anybody suggest me how to resolve it or any new solution for conversion process

        Thanks Regards Hemananthan.S ===============

        F Offline
        F Offline
        fjdiewornncalwe
        wrote on last edited by
        #3

        If you want a solid solution, don't try to write it yourself because there is alot more involved in generating pdf documents in a reliable manner than just using a single method. Do a google search for pdf creator assembly modules. There are plenty of them out there and the cost is minimal and much less than the cost associated with developing one in house.

        1 Reply Last reply
        0
        • H hemananthan

          Can anybody help me programatically to get the solution for converting any type of document to PDF format we already tried through this coding: public static void ConverWordToPDF(string Filepath, string Targetpath) { object Unknown = Type.Missing; object Source = Filepath; object Target = Targetpath; ApplicationClass MSdoc = new ApplicationClass(); try { MSdoc.Visible = false; MSdoc.Documents.Open(ref Source, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); MSdoc.Application.Visible = false; MSdoc.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateMinimize; object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF; MSdoc.ActiveDocument.SaveAs(ref Target, ref format, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown); } catch (Exception e) { log.Info("Converted Word to PDF", e); } finally { if (MSdoc != null) { MSdoc.Documents.Close(ref Unknown, ref Unknown, ref Unknown); } MSdoc.Quit(ref Unknown, ref Unknown, ref Unknown); } } Normally in while runing this application in local its working fine in XP System: while run through IIS i getting the following error: System.Runtime.InteropServices.COMException (0x800A11FD): =================== System.Runtime.InteropServices.COMException (0x800A11FD): This method or property is not available because a document window is not active. at Microsoft.Office.Interop.Word.Documents.Close(Object& SaveChanges, Object& OriginalFormat, Object& RouteDocument) Can anybody suggest me how to resolve it or any new solution for conversion process

          Thanks Regards Hemananthan.S ===============

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          No one can help you with converting "any" type of document. That is an unrealistic requirement. Anyone who tells you they have something that can handle "any" format is lying. One of the best resources I have found for finding code or products for dealing with PDFs is PDF Zone[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups