Skip to content

Instantly share code, notes, and snippets.

@ArthurEzenwanne
Created March 4, 2019 15:48
Show Gist options
  • Save ArthurEzenwanne/5e0e820d1ffe8af06e0e1c1ec58ad066 to your computer and use it in GitHub Desktop.
Save ArthurEzenwanne/5e0e820d1ffe8af06e0e1c1ec58ad066 to your computer and use it in GitHub Desktop.
C# .docx to .pdf convesion
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();
}
}
}
@Luengas
Copy link

Luengas commented May 13, 2020

Error: {"Referencia a objeto no establecida como instancia de un objeto."}
when I execute 'objWorPdf.Word2PdfCOnversion();'

@ArthurEzenwanne
Copy link
Author

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