PDF is one of the most ubiquitous file formats today. Whether you are submitting a resume for your next job, generating a financial report for your boss, or publishing a scientific whitepaper – PDF is the defacto format.
- Download Pdf To Microsoft Office Word Convertersarah Smith Online
- Download Pdf To Microsoft Office Word Convertersarah Smithsonian
Because it’s so widely used, you’re likely to run across many situations as a software developer where you need to be able to open and manipulate PDF files. But what do you do when your customers prefer to submit Microsoft Word, Powerpoint, or Excel documents and you need PDF files? Thanks to Foxit, you can easily build software that converts any of these formats to PDF.
PDF To WORD Converter Convert PDF files in a flash. PDF To WORD Converter is a piece of software developed for the Windows operating system. Designed to convert your existing PDF files into text files, PDF To WORD Converter works exclusively with Microsoft Word to make editing converted files even easier. The Microsoft Save as PDF or XPS add-in is an official windows software that allows you to export and save documents into PDF and XPS file formats in the Microsoft Office 365 Suite. Whether you are using Excel, Word, Publisher or any of the other programs in Microsoft Office Suite, being able to convert documents into PDF files is very useful.
In this tutorial, we’ll look at how to convert Microsoft Office documents to PDF files using Foxit’s PDF SDK for .NET. We’ll build a .NET web application that will accept these documents as uploaded files and convert them to PDF. There’s a sample application available on GitHub in the event you want to check out the code and run the finished application. Otherwise, follow along for a complete tutorial.
Prerequisites
Before you start building the .NET web application, you’ll need the following:
– A recent version of .NET Core such as version 3.1
– An IDE that supports .NET Core development like Visual Studio 2019 or JetBrains Rider
– Foxit PDF SDK for .NET Core on Windows using a free trial
Creating the .NET Web Application
When building any new .NET application, Microsoft and the community recommend using .NET Core or the upcoming re-branded .NET version 5.
Create a new folder, navigate to it, and run the following command from your command prompt:
This will scaffold a new .NET Core web application using Razor Pages.
Note: Alternatively, you may use your IDE to create a new Razor Page web application.
Referencing The Foxit PDF SDK
After you’ve downloaded and extracted Foxit PDF SDK for Windows and .NET Core, copy the “lib” folder over to your .NET Core project’s root.
Using your IDE, add a reference to “libx64_vc15fsdk_dotnetcore.dll”.
In your IDE (such as Visual Studio 2019), right-click your project in the solution explorer and choose “Add -> Existing Item…”. Add the file found at “libx64_vc15fsdk.dll”.
Note: If using an IDE like JetBrains Rider, you may need to manually copy that file into the root of the project.
In the solution explorer, right-click that same file and choose “properties”. Under “Copy to output directory” choose “Copy if newer”.
Your `.csproj` file should now look like this:
You’re now ready to configure Foxit’s SDK with your serial number and key.
Configuration
To use Foxit PDF SDK, you’ll need the serial number and key that was given to you inside the SDK download. The folder for the SDK version 7.4 is named `foxitpdfsdk_7_4_win_dotnet`. Inside this folder, navigate to the `lib` folder. You’ll see two files that have your serial number and key:
In the `gsdk_key.txt` file, your key is all the characters after “Sign=”.
In the `gsdk_sn.txt` file, your serial number is everything after “SN=”.
Go back to your .NET application and open the `appsettings.json` file. Replace it with the following:
Don’t forget to replace the serial number and key with your own. Foxit’s SDK is now configured, so now you need a user interface and logic to handle file uploads.
Creating A File Upload UI
For this tutorial, you’ll need to create a user interface that will allow you to upload an Office document to the .NET back-end web application.
Open up the file at `Pages/Index.cshtml` and replace it with the following:
The preceding code uses the built-in .NET Razor syntax to create an HTML form with a file upload input and a `<span>` that will display any validation errors.
Next, create the code-behind file for this Razor Page. Open up the `Pages/Index.cshtml.cs` and paste the following into this file:
This is a basic controller shell. Right now, it allows you to upload a file but doesn’t do anything with it. In the following section, you’ll validate the file extension and convert it to a PDF file using Foxit.
File Validation
Next, you need to add some basic validation that ensures the file is either a Word, Excel or PowerPoint document. At the bottom of the `IndexModel` class add the following:
The `EnsureExtensionIsConvertible` will let you test whether a given file extension is able to be converted to a PDF document.
Next, replace the entire `OnPost` method that was already in your controller shell with the following:
Now, when you try to upload an invalid document type, you’ll get an error on the UI.
PDF Conversion
Now it’s time to add the code that converts Microsoft Office documents to PDF documents.
First, replace the `OnPost` method again with the following final implementation:
You’ll see the same file validation logic from before as well as the code that saves the uploaded file and converts it to a PDF. If the file is valid then you’ll save it to the file system. Next, a method, `ConvertToPDFFileResult`, is used to return the converted PDF file as an HTTP message.
Create the `ConvertToPDFFileResult` method like this:
The Foxit PDF SDK does all the “heavy lifting”, so this method is pretty straightforward.
When converting any of the Office documents to a PDF, the Foxit SDK will save the converted file to the location that was specified. All we need to do is read that file using the `PhysicalFileResult` class. This will return the file to the requesting internet browser as an appropriate HTTP response.
Running the Application
To run the application, navigate to the root of your .NET application’s project. Then, execute `dotnet run` in your terminal. You’ll see the upload form in your browser.
Next, create and save a Microsoft Word document and upload it using your upload form.
Press “Convert To PDF!” and you’ll be taken to the converted PDF file in your browser.
That’s it!
Bonus: HTML To PDF Conversion
If you need to convert HTML documents to PDF, then Foxit also has you covered. The developer guide has a section about how to convert HTML documents to PDF documents.
If you follow the instructions and install the required files, you can add the following code inside the `ConvertToPDFFileResult` method in your application:
Also, don’t forget to add the `”html”` file extension to the list of valid extensions. This will now let you convert uploaded HTML files or web pages to PDF documents that you can send to your users.
Now, you’ve seen how easy Foxit’s PDF SDK is to use when converting Microsoft Office and HTML documents to PDF. The core logic for PDF conversion was only about 20 lines of code. Foxit’s PDF SDK can help you build advanced application features that your customers need without investing a ton of time into custom code. Have a look at the developer guide to see what else is possible with Foxit’s PDF SDK for .NET.
PDF is one of the most ubiquitous file formats today. Whether you are submitting a resume for your next job, generating a financial report for your boss, or publishing a scientific whitepaper – PDF is the defacto format.
Because it’s so widely used, you’re likely to run across many situations as a software developer where you need to be able to open and manipulate PDF files. But what do you do when your customers prefer to submit Microsoft Word, Powerpoint, or Excel documents and you need PDF files? Thanks to Foxit, you can easily build software that converts any of these formats to PDF.
In this tutorial, we’ll look at how to convert Microsoft Office documents to PDF files using Foxit’s PDF SDK for .NET. We’ll build a .NET web application that will accept these documents as uploaded files and convert them to PDF. There’s a sample application available on GitHub in the event you want to check out the code and run the finished application. Otherwise, follow along for a complete tutorial.
Prerequisites
Before you start building the .NET web application, you’ll need the following:
– A recent version of .NET Core such as version 3.1
– An IDE that supports .NET Core development like Visual Studio 2019 or JetBrains Rider
– Foxit PDF SDK for .NET Core on Windows using a free trial
Creating the .NET Web Application
When building any new .NET application, Microsoft and the community recommend using .NET Core or the upcoming re-branded .NET version 5.
Create a new folder, navigate to it, and run the following command from your command prompt:
This will scaffold a new .NET Core web application using Razor Pages.
Note: Alternatively, you may use your IDE to create a new Razor Page web application.
Referencing The Foxit PDF SDK
After you’ve downloaded and extracted Foxit PDF SDK for Windows and .NET Core, copy the “lib” folder over to your .NET Core project’s root.
Using your IDE, add a reference to “libx64_vc15fsdk_dotnetcore.dll”.
In your IDE (such as Visual Studio 2019), right-click your project in the solution explorer and choose “Add -> Existing Item…”. Add the file found at “libx64_vc15fsdk.dll”.
Note: If using an IDE like JetBrains Rider, you may need to manually copy that file into the root of the project.
In the solution explorer, right-click that same file and choose “properties”. Under “Copy to output directory” choose “Copy if newer”.
Your `.csproj` file should now look like this:
You’re now ready to configure Foxit’s SDK with your serial number and key.
Configuration
To use Foxit PDF SDK, you’ll need the serial number and key that was given to you inside the SDK download. The folder for the SDK version 7.4 is named `foxitpdfsdk_7_4_win_dotnet`. Inside this folder, navigate to the `lib` folder. You’ll see two files that have your serial number and key:
In the `gsdk_key.txt` file, your key is all the characters after “Sign=”.
In the `gsdk_sn.txt` file, your serial number is everything after “SN=”.
Go back to your .NET application and open the `appsettings.json` file. Replace it with the following:
Don’t forget to replace the serial number and key with your own. Foxit’s SDK is now configured, so now you need a user interface and logic to handle file uploads.
Creating A File Upload UI
For this tutorial, you’ll need to create a user interface that will allow you to upload an Office document to the .NET back-end web application.
Open up the file at `Pages/Index.cshtml` and replace it with the following:
The preceding code uses the built-in .NET Razor syntax to create an HTML form with a file upload input and a `<span>` that will display any validation errors.
Next, create the code-behind file for this Razor Page. Open up the `Pages/Index.cshtml.cs` and paste the following into this file:
This is a basic controller shell. Right now, it allows you to upload a file but doesn’t do anything with it. In the following section, you’ll validate the file extension and convert it to a PDF file using Foxit.
File Validation
Next, you need to add some basic validation that ensures the file is either a Word, Excel or PowerPoint document. At the bottom of the `IndexModel` class add the following:
The `EnsureExtensionIsConvertible` will let you test whether a given file extension is able to be converted to a PDF document.
Next, replace the entire `OnPost` method that was already in your controller shell with the following:
Now, when you try to upload an invalid document type, you’ll get an error on the UI.
PDF Conversion
Now it’s time to add the code that converts Microsoft Office documents to PDF documents.
First, replace the `OnPost` method again with the following final implementation:
You’ll see the same file validation logic from before as well as the code that saves the uploaded file and converts it to a PDF. If the file is valid then you’ll save it to the file system. Next, a method, `ConvertToPDFFileResult`, is used to return the converted PDF file as an HTTP message.
Create the `ConvertToPDFFileResult` method like this:
The Foxit PDF SDK does all the “heavy lifting”, so this method is pretty straightforward.
When converting any of the Office documents to a PDF, the Foxit SDK will save the converted file to the location that was specified. All we need to do is read that file using the `PhysicalFileResult` class. This will return the file to the requesting internet browser as an appropriate HTTP response.
Running the Application
To run the application, navigate to the root of your .NET application’s project. Then, execute `dotnet run` in your terminal. You’ll see the upload form in your browser.
Next, create and save a Microsoft Word document and upload it using your upload form.
Press “Convert To PDF!” and you’ll be taken to the converted PDF file in your browser.
That’s it!
Bonus: HTML To PDF Conversion
Download Pdf To Microsoft Office Word Convertersarah Smith Online
If you need to convert HTML documents to PDF, then Foxit also has you covered. The developer guide has a section about how to convert HTML documents to PDF documents.
If you follow the instructions and install the required files, you can add the following code inside the `ConvertToPDFFileResult` method in your application:
Also, don’t forget to add the `”html”` file extension to the list of valid extensions. This will now let you convert uploaded HTML files or web pages to PDF documents that you can send to your users.
Download Pdf To Microsoft Office Word Convertersarah Smithsonian
Now, you’ve seen how easy Foxit’s PDF SDK is to use when converting Microsoft Office and HTML documents to PDF. The core logic for PDF conversion was only about 20 lines of code. Foxit’s PDF SDK can help you build advanced application features that your customers need without investing a ton of time into custom code. Have a look at the developer guide to see what else is possible with Foxit’s PDF SDK for .NET.