LEADTOOLS Support
Imaging
Imaging SDK Examples
HOW TO: Convert Faxes Embedded in PDF to TIF
#1
Posted
:
Thursday, June 7, 2018 9:55:09 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 89
Was thanked: 4 time(s) in 4 post(s)
Updated from our
LEADTOOLS Blog PostEven today there are many organizations that rely on fax as a required form of communications. Because of this, receiving faxes is a requirement that much still be met. To do this, many organizations utilize fax services either hosted locally or by a third-party. Many of these services will email received faxes to users as a PDF file.
In a normal facsimile transmission, every other scan-line is skipped. This reduces the amount of data that needs to be sent over the relatively slow connection used to send faxes. To account for the missing scan-lines, the aspect ratio of the pixels is 2:1. It is important to recognize this when displaying the image else you will end up displaying the image incorrectly, making it looked squashed.
The code below utilizes the following DLLs:
Leadtools.dll
Leadtools.Codecs.dll
Leadtools.Codecs.Tif.dll
Leadtools.Pdf
C#Code:using System;
using System.IO;
using Leadtools;
using Leadtools.Codecs;
namespace convertFaxEmbeddedInPdfToTiff_20
{
class Program
{
static void Main(string[] args)
{
string licenseFilePath = @"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC";
string keyFileValue = File.ReadAllText(@"C:\LEADTOOLS 20\Common\License\LEADTOOLS.LIC.KEY");
RasterSupport.SetLicense(licenseFilePath, keyFileValue);
string srcFile = @"C:\Users\cthompson\Desktop\Fax.pdf";
Func<int, string> getSaveFileName = pg => Path.GetDirectoryName(srcFile)
+ Path.DirectorySeparatorChar
+ Path.GetFileNameWithoutExtension(srcFile)
+ "_pg"
+ pg.ToString()
+ ".tif";
try
{
using (var codecs = new RasterCodecs())
{
var info = codecs.GetInformation(srcFile, true);
for (var pageNumber = 1; pageNumber <= info.TotalPages; pageNumber++)
{
// Make sure the resulting img has the original resolution
var pdfInfo = codecs.GetRasterPdfInfo(srcFile, pageNumber);
codecs.Options.RasterizeDocument.Load.XResolution = pdfInfo.XResolution;
codecs.Options.RasterizeDocument.Load.YResolution = pdfInfo.YResolution;
// Save the file using a format appropriate for the bits per pixel
var bpp = pdfInfo.BitsPerPixel;
var saveFormat = RasterImageFormat.Tif;
if (bpp == 1)
saveFormat = RasterImageFormat.CcittGroup4;
else if (bpp > 1 && bpp < 9)
saveFormat = RasterImageFormat.TifLzw;
else if (bpp == 24)
saveFormat = RasterImageFormat.TifJpeg;
using (var page = codecs.Load(srcFile, pageNumber))
codecs.Save(page, getSaveFileName(pageNumber), saveFormat, 0);
}
}
Console.WriteLine("Operation Successful");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
Console.ReadLine();
}
}
}
}
Chris Thompson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Examples
HOW TO: Convert Faxes Embedded in PDF to TIF
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.