Created
March 4, 2019 15:48
-
-
Save ArthurEzenwanne/5e0e820d1ffe8af06e0e1c1ec58ad066 to your computer and use it in GitHub Desktop.
C# .docx to .pdf convesion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
//wordtopdf.dll downloaded from https://www.c-sharpcorner.com/uploadfile/698727/convert-word-file-to-pdf-using-c-sharp/ | |
using WordToPDF; | |
namespace WordPDFConsoleApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// The code provided will print ‘Hello World’ to the console. | |
// Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app. | |
// Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app! | |
Word2Pdf objWorPdf = new Word2Pdf(); | |
//string backfolder1 = "D:\\WOrdToPDF\\"; | |
string backfolder1 = @"C:\Users\Arthur\WordToPDFFiles\"; | |
string strFileName = "TestMemoDoc - Copy.docx"; | |
object FromLocation = backfolder1 + "\\" + strFileName; | |
string FileExtension = Path.GetExtension(strFileName); | |
string ChangeExtension = strFileName.Replace(FileExtension, ".pdf"); | |
if (FileExtension == ".doc" || FileExtension == ".docx") | |
{ | |
object ToLocation = backfolder1 + "\\" + ChangeExtension; | |
objWorPdf.InputLocation = FromLocation; | |
objWorPdf.OutputLocation = ToLocation; | |
objWorPdf.Word2PdfCOnversion(); | |
} | |
Console.WriteLine("Hello... Document Converted!"); | |
Console.ReadKey(); | |
} | |
} | |
} |
Well, ensure you set a reference to the object before calling it. You may also use these gists:
https://gist.github.com/ArthurEzenwanne/c443e8bbc67af312aea05c632652ab56
https://gist.github.com/ArthurEzenwanne/fa5d4d2d651081b39071f1883fe6619c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error: {"Referencia a objeto no establecida como instancia de un objeto."}
when I execute 'objWorPdf.Word2PdfCOnversion();'