AVAILABLE NOW: Spring 2025 Release
By Apryse | 2025 Apr 03
9 min
Tags
PDF SDK
conversion
C#
This past weekend, I was very fortunate compared to so many people that recently faced and are still having to deal with Hurricane Florence. At home, the power is out, but there is no major damage. I am fortunate. Since there is nothing I can do at the moment about the power and everyone around me is safe, I decided to forget my first-world problems, go to the office, which does have power, and write a small and simple app that solves some common first-world problems. I am hoping that you will find this tool useful, too!
Most scanners do not automatically OCR while scanning, even though it sends a PDF. It merely captures the image and wraps it in the PDF format making it possible to open in Acrobat, but not possible search for a word or phrase.
Also, there are times I do not have a scanner around and just have my phone. Those are pictures and not in the PDF format nor text-searchable.
Some clients have inbound limitations on the size of emails they can receive. This means that if you need to scan a 90-page document and try to send it to them, it will probably bounce due to the size restriction.
It never fails. I go to the network scanner to scan a document just after someone else and do not pay attention to the settings. It just so happens that they needed to scan a large batch of single-page documents and changed the settings to scan each page as a separate file. I do not notice until I get back to my desk and see 12 different files for my 12-page document. When that happens, I quietly say a few choice words and go back to the scanner to try again.
I like to digitally keep track of bills and receipts. For example, I receive a property tax bill in the mail and make a payment online. The confirmation is either a PDF or a screenshot (image). Now, I must keep two files from different sources and possibly in different formats together. It would be better if I could merge the files and only have to keep track of one file. Another example is keeping related purchase requests, approvals, and receipts in one file, even if they were originally received in different formats and at different times.
For me, the only requirement is that the tool be easy to use and save time. Ideally, I want to be able to right-click a file or files and do as little as possible to solve all of the problems I listed above. (I feel like I have heard that before.)
With the Apryse SDK, you can use the following code to convert and merge multiple files to a PDF. This code can also be used as part of a shell script that adds a right-click context menu option to automatically send the list of file paths to the application.
using pdftron;
using pdftron.PDF;
using pdftron.SDF;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
List<string> inputFiles = new List<string> { “paths_to_your_inputs”, “…” };
PDFNet.Initialize(PDFTronLicense.License);
PDFNet.AddResourceSearchPath(PDFTronLicense.ModulePath);
RunBatchConvert(inputFiles);
PDFNet.Terminate();
}
static void RunBatchConvert(List<string> inputFiles)
{
using (PDFDoc outputDoc = new PDFDoc())
{
foreach (var file in inputFiles)
{
string extension = System.IO.Path.GetExtension(file).ToLower();
if (extension == ".pdf")
{
using (PDFDoc doc = new PDFDoc(file))
{
TextExtractor textExtractor = new TextExtractor();
textExtractor.Begin(doc.GetPage(1));
if (string.IsNullOrEmpty(textExtractor.GetAsText()))
{
OCRModule.ProcessPDF(doc, null);
}
Optimizer.Optimize(doc);
outputDoc.InsertPages(outputDoc.GetPageCount() + 1, doc, 1, doc.GetPageCount(), PDFDoc.InsertFlag.e_none);
}
}
else if (extension == ".jpg" || extension == ".jpeg" || extension == ".png" || extension == ".tiff" || extension == ".tif")
{
OCRModule.ImageToPDF(outputDoc, file, null);
}
}
outputDoc.Save("output.pdf", SDFDoc.SaveOptions.e_linearized);
}
}
}
}
Download the Apryse SDK for free. It’s fully functional and comes with free chat and email support.
Need help? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team.
Tags
PDF SDK
conversion
C#
Apryse
Share this post
PRODUCTS
Platform Integrations
End User Applications
Popular Content