This brief tutorial will guide you on how to convert Word to scanned PDF using C#. While using C# convert Word to scanned PDF using a few lines of code and simple API calls. The application can be used in any of the .NET Core based environments on Windows, macOS or Linux based platforms.
Steps to Convert Word to Scanned PDF using C#
- Configure the project to add references to Aspose.Words from the NuGet package manager and Systems.Drawing
- Load the source Word file from the disk using the Document class object
- Convert the page ranges from the Word file and save them as Images in Memory Stream using IPageSavingCallback
- Load the saved word page image stream and add it as an image inside DocumentBuilder
- Save the Document as a scanned PDF on the disk
Using C# scan DOC to PDF is easily possible with the help of the aforementioned sequence of operations. We will start the process by loading the source DOCX file from the disk and using IPageSavingCallback each page selected in the page range is converted to a Memory stream of JPEG images. Then we iterate through individual page JPEG memory streams and append inside pages using DocumentBuilder class. Finally, the document is saved as a read-only scanned PDF on the disk.
Code to Convert Word to Scanned PDF using C#
In order to convert Word to PDF using C# and obtain a scanned PDF, we have adopted the approach of converting the Word document pages to JPEG images first and thus making them read-only. Then by using DocumentBuilder class, we have created a new document using the images created in the first step and saved that as a PDF on the disk.
In this tutorial, we have learned that in order to develop a Word to scanned PDF converter C# based API can be effectively used. If you want to remove a blank page in a Word file using C#, refer to the article how to remove blank page in Word using C#.