You’ll see the upload form in your browser. Then, execute `dotnet run` in your terminal. To run the application, navigate to the root of your. This will return the file to the requesting internet browser as an appropriate HTTP response. All we need to do is read that file using the `PhysicalFileResult` class. When converting any of the Office documents to a PDF, the Foxit SDK will save the converted file to the location that was specified. The Foxit PDF SDK does all the “heavy lifting”, so this method is pretty straightforward. Return new PhysicalFileResult(saveToPath, "application/pdf") Using var settings = new Excel2PDFSettingData() Ĭonvert.FromExcel(filePath, string.Empty, saveToPath, settings) Using var settings = new PowerPoint2PDFSettingData() Ĭonvert.FromPowerPoint(filePath, string.Empty, saveToPath, settings) Using var settings = new Word2PDFSettingData() Ĭonvert.FromWord(filePath, string.Empty, saveToPath, settings) Private static string ValidExtensions = new /converted.pdf" At the bottom of the `IndexModel` class add the following: csharp Next, you need to add some basic validation that ensures the file is either a Word, Excel or PowerPoint document. In the following section, you’ll validate the file extension and convert it to a PDF file using Foxit. Right now, it allows you to upload a file but doesn’t do anything with it. This is the property that our uploaded file will be bound to. You’ll need all these using statements as you add more code Open up the `Pages/` and paste the following into this file: csharp Next, create the code-behind file for this Razor Page. NET Razor syntax to create an HTML form with a file upload input and a `` that will display any validation errors. Upload either a Word, Powerpoint, Excel or HTML file: Open up the file at `Pages/Index.cshtml` and replace it with the following: = "Convert Office Document To PDF!" Creating A File Upload UIįor this tutorial, you’ll need to create a user interface that will allow you to upload an Office document to the. Foxit’s SDK is now configured, so now you need a user interface and logic to handle file uploads. "": "Information"ĭon’t forget to replace the serial number and key with your own. NET application and open the `appsettings.json` file. In the `gsdk_sn.txt` file, your serial number is everything after “SN=”. In the `gsdk_key.txt` file, your key is all the characters after “Sign=”. You’ll see two files that have your serial number and key: Inside this folder, navigate to the `lib` folder. The folder for the SDK version 7.4 is named `foxitpdfsdk_7_4_win_dotnet`. To use Foxit PDF SDK, you’ll need the serial number and key that was given to you inside the SDK download. You’re now ready to configure Foxit’s SDK with your serial number and key. Your `.csproj` file should now look like this: xml Under “Copy to output directory” choose “Copy if newer”. In the solution explorer, right-click that same file and choose “properties”. Note: If using an IDE like JetBrains Rider, you may need to manually copy that file into the root of the project. Add the file found at “lib\\圆4_vc15\\fsdk.dll”. In your IDE (such as Visual Studio 2019), right-click your project in the solution explorer and choose “Add -> Existing Item…”. Using your IDE, add a reference to “lib\\圆4_vc15\\fsdk_dotnetcore.dll”. NET Core, copy the “lib” folder over to your. Referencing The Foxit PDF SDKĪfter you’ve downloaded and extracted Foxit PDF SDK for Windows and. Note: Alternatively, you may use your IDE to create a new Razor Page web application. NET Core web application using Razor Pages. NET version 5.Ĭreate a new folder, navigate to it, and run the following command from your command prompt: dotnet new webapp -o OfficeToPDF NET application, Microsoft and the community recommend using. NET Core on Windows using a free trial Creating the. NET Core development like Visual Studio 2019 or JetBrains Rider NET web application, you’ll need the following:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |