1. Home
  2. Foxit PDF SDK for Windows
  3. How to convert TIFF to PDF on AWS Lambda with Foxit PDF SDK (.NET)

How to convert TIFF to PDF on AWS Lambda with Foxit PDF SDK (.NET)

Foxit PDF SDK for Windows features three libraries: C++, C# (.NET) and Java, built to run in both desktop and server environments, both 32-bit and 64-bit.

Foxit PDF SDK (.NET) works with AWS Lambda for creating functions in C# such as rendering, viewing, annotating, signing, protecting and managing forms in PDFs. This article will provide specific instructions on converting converting TIFF to PDF.

First, you need to create a “AWS Lambda Project (.Net Core – C#) and add ‘fsdk_dotnet.dll’ as a reference to your project in Visual Studio. We describe the process of adding references to your projects in the ‘How to Create a Simple Project’ section of the Foxit PDF SDK Developer Guide (.NET).

The fsdk_dotnet.dll is located in the lib directory of the evaluation package. Once you do, you can add the following using statements.

using foxit;
using foxit.common;
using foxit.common.fxcrt;
using foxit.pdf;

Next, add the following code:

public string TiffToPDF(string input, string output)
{
 //the sn and key value are license/evaluation values. This is provided with the Foxit PDF SDK evaluation package in the lib directory.
 string sn = "SNValue"; //the SN value provided in the evaluation package at lib\gsdk_sn.txt
 string key = "SignKeyValue"; //the Sign value provided in evaluation package at lib\gsdk_key.txt
 ErrorCode error_code;
 try
 {
 error_code = Library.Initialize(sn, key); //Unlocks the library to be used. Make sure you update the sn and key file accordingly.
 if (error_code != ErrorCode.e_ErrSuccess)
 {
 return error_code.ToString();
 }
 PDFDoc doc = new PDFDoc(); //Creates a PDF document object
 foxit.common.Image image = new foxit.common.Image(input); //Create a image object from the text file
 int pageIndex = doc.GetPageCount(); //Get the page count
 PDFPage page = doc.InsertPage(pageIndex, image.GetWidth(), image.GetHeight()); //Adds a blank PDF page that matches the images height and width to the PDF document object
 page.StartParse((int)PDFPage.ParseFlags.e_ParsePageNormal, null, false); //Parsing is required here. Just do it.
 page.AddImage(image, 0, new PointF(0, 0), page.GetWidth(), page.GetHeight(), true); //Adds a image to the PDF page
 doc.SaveAs(output, (int)PDFDoc.SaveFlags.e_SaveFlagIncremental); //Save the new PDF to the output path
 image.Dispose(); //clean up the cache data used to create the image object
 page.Dispose(); //clean up the cache data used to create the PDF page
 doc.Dispose(); //clean up the cache data used to create the PDF Document object
 Library.Release(); //clean up the cache data used by the Foxit PDF SDK library
 }
 catch (foxit.PDFException e)
 {
 return e.Message; //If successful this will return the "E_ERRSUCCESS." Please check out the headers for other error codes.
 }
 catch (Exception e)
 {
 return e.Message;
 }
 return error_code.ToString().ToUpper();
}

The fsdk_dotnet.dll reference the fsdk.dll file located in the lib directory. Please ensure that the fsdk.dll is correctly outputted to the output directory for the reference to be correct.

Note: Further image types supported are:

  • BMP
  • JPG (or JPEG)
  • PNG
  • GIF
  • TIF
  • JPX or JPEG2000
  • JBIG2
Updated on November 13, 2019

Was this article helpful?

Related Articles

Ready to try Foxit PDF SDK?
Click the link below to download your trial
Free Trial