class Program
{
public static string imageOutputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"output/output.jpg");
[STAThread]
public static void Main(string[] args)
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "output"));
PDFNet.Initialize("place your license key here");
PDFNet.AddResourceSearchPath("../../../../../Lib/");
if (!OCRModule.IsModuleAvailable())
{
Console.WriteLine("");
Console.WriteLine("Unable to run OCRTest: Apryse SDK OCR module not available.");
Console.WriteLine("---------------------------------------------------------------");
Console.WriteLine("The OCR module is an optional add-on, available for download");
Console.WriteLine("at http://www.pdftron.com/. If you have already downloaded this");
Console.WriteLine("module, ensure that the SDK is able to find the required files");
Console.WriteLine("using the PDFNet.AddResourceSearchPath() function.");
Console.WriteLine("");
return;
}
ImageToPdf();
}
public static void ImageToPdf()
{
try
{
GetClipboardImage();
using (PDFDoc doc = new PDFDoc())
{
OCRModule.ImageToPDF(doc, imageOutputPath, null);
doc.Save(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "output/output.pdf"), pdftron.SDF.SDFDoc.SaveOptions.e_linearized);
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr GetOpenClipboardWindow();
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern bool OpenClipboard(IntPtr hWndNewOwner);
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern bool CloseClipboard();
public static void GetClipboardImage()
{
IntPtr hWnd = GetOpenClipboardWindow();
OpenClipboard(IntPtr.Zero);
CloseClipboard();
System.Drawing.Image image = null;
if (Clipboard.ContainsImage())
{
image = Clipboard.GetImage();
}
image.Save(imageOutputPath);
}
}