I am trying to convert scanned images converted to a Bitonal (1bpp) Tiff to a PDF document. The conversion process from 32bppARGB to 1bbp Indexed format (Bitonal) tiff with CCITT4 compression appears to work smoothly as I am able to view the file and convert it to pdf using a 3rd party tool.
The document creation process also appears to work fine, however, when I open the newly created PDF document, I receive an
"Insufficient data for an image" error message from adobe.
I could revert to using the 32bpp file, but it is an
order of magnitude slower to create the Pdf document per image/page scanned. Any suggestions are welcome.
Code to create Pdf document
Code:
public static PdfDocument CreatePdfFromTiffs(List<string> tiffList)
{
PdfDocument doc = new PdfDocument();
tiffList.ForEach(img =>
{
if (string.IsNullOrWhiteSpace(img)) throw new ArgumentNullException("path");
if (File.Exists(img))
{
PdfPage page = doc.AddPage();
using (XGraphics gfx = XGraphics.FromPdfPage(page))
{
DrawTiff(gfx, 1, img, ref page);
}
}
});
}
public static void DrawTiff(XGraphics gfx, int number, string tiffSamplePath, ref PdfSharp.Pdf.PdfPage page)
{
using (XImage image = XImage.FromFile(tiffSamplePath))
{
// Make the page the same size as the tiff image that
// was scanned.
page.Height = XUnit.FromPoint(image.Size.Height);
page.Width = XUnit.FromPoint(image.Size.Width);
gfx.DrawImage(image, 0, 0, image.Size.Width, image.Size.Height);
}
}