Unable to use FAXCOMLib with certain TIFF formats.

  • Thread starter Thread starter Orbian
  • Start date Start date
O

Orbian

I am trying to use a web service to submit a fax to a fax server via
the FAXCOMLib. When I do a FAXCOMLib.FaxDoc.Send() on a fax that was
faxed to me it works fine. However, If I create a TIFF file via the
DotNet framework the TIFF file fails with "Invalid Data" exception. The
DotNet generated TIFFs will work fine with a stand-alone desktop
application but fail in a web service. I know the web service is
capable of submitting faxes, just not DotNet generated ones. The only
thing I can think of is that the faxes that work are 1bpp indexed and
the DotNet generated ones are gray scale I believe. Although this
doesn't explain why the DotNet ones will work with the exact same code
in a Windows Form application. Here are the dumps from the two files
that I test with:

The one that works with web services:
c:\outfaxes\test.tif:
Magic: 0x4949 <little-endian> Version: 0x2a
Directory 0: offset 22568 (0x5828) next 0 (0)
SubFileType (254) LONG (4) 1<2>
ImageWidth (256) LONG (4) 1<1728>
ImageLength (257) LONG (4) 1<1084>
BitsPerSample (258) SHORT (3) 1<1>
Compression (259) SHORT (3) 1<4>
Photometric (262) SHORT (3) 1<0>
FillOrder (266) SHORT (3) 1<1>
StripOffsets (273) LONG (4) 1<8>
SamplesPerPixel (277) SHORT (3) 1<1>
RowsPerStrip (278) LONG (4) 1<1084>
StripByteCounts (279) LONG (4) 1<22305>
XResolution (282) RATIONAL (5) 1<204>
YResolution (283) RATIONAL (5) 1<98>
ResolutionUnit (296) SHORT (3) 1<2>
PageNumber (297) SHORT (3) 2<0 0>
40001 (0x9c41) ASCII (2) 8<PSEFAX1\0>
40002 (0x9c42) ASCII (2) 1<\0>
40003 (0x9c43) ASCII (2) 28<Brooktrout Line #1 (TRUF ...>
40005 (0x9c45) ASCII (2) 1<\0>
40046 (0x9c6e) LONG (4) 1<1>
40047 (0x9c6f) LONG (4) 1<4>
40048 (0x9c70) LONG (4) 1<256>
40049 (0x9c71) LONG (4) 1<18>
40051 (0x9c73) SRATIONAL (10) 1<24.2823>
40052 (0x9c74) SRATIONAL (10) 1<36.3325>
40053 (0x9c75) LONG (4) 1<2>



The one that fails with "Invalid Data":
c:\outfaxes\x_124_145.tif:
Magic: 0x4949 <little-endian> Version: 0x2a
Directory 0: offset 138098 (0x21b72) next 0 (0)
SubFileType (254) LONG (4) 1<0>
ImageWidth (256) SHORT (3) 1<850>
ImageLength (257) SHORT (3) 1<1119>
BitsPerSample (258) SHORT (3) 4<8 8 8 8>
Compression (259) SHORT (3) 1<5>
Photometric (262) SHORT (3) 1<2>
StripOffsets (273) LONG (4) 373<8 172 336 500 664 828 992 1156 1320
1484 1648 1812 1976 2140 2304 2468 2632 2796 2960 3124 3288 3452 3616
3780 ...>
SamplesPerPixel (277) SHORT (3) 1<4>
RowsPerStrip (278) LONG (4) 1<3>
StripByteCounts (279) LONG (4) 373<164 164 164 164 164 164 164 164 164
164 164 164 164 164 164 164 164 164 164 164 164 164 164 164 ...>
XResolution (282) RATIONAL (5) 1<100>
YResolution (283) RATIONAL (5) 1<100>
PlanarConfig (284) SHORT (3) 1<1>
ResolutionUnit (296) SHORT (3) 1<2>
Software (305) ASCII (2) 27<Adobe Photoshop CS Windo ...>
DateTime (306) ASCII (2) 20<2005:08:05 15:37:23\0>
Predictor (317) SHORT (3) 1<1>
ExtraSamples (338) SHORT (3) 1<2>
700 (0x2bc) BYTE (1) 6398<0x3c 0x3f 0x78 0x70 0x61 0x63 0x6b 0x65 0x74
0x20 0x62 0x65 0x67 0x69 0x6e 0x3d 0x27 0xef 0xbb 0xbf 0x27 0x20 0x69
0x64 ...>
9999 (0x270f) SHORT (3) 153<21564 18241 15955 21564 18241 15422 20568
29551 13374 12592 12092 20568 29551 15422 20569 29551 14654 15416 22831
28496 15987 17980 28001 27753 ...>
33723 (0x83bb) LONG (4) 2<540 131074>
34377 (0x8649) BYTE (1) 4096<0x38 0x42 0x49 0x4d 0x4 0x4 00 00 00 00 00
0x7 0x1c 0x2 00 00 0x2 00 0x2 00 0x38 0x42 0x49 0x4d ...>
34665 (0x8769) LONG (4) 1<2867432>
ICC Profile (34675) UNDEFINED (7) 3144<00 00 0xc 0x48 0x4c 0x69 0x6e
0x6f 0x2 0x10 00 00 0x6d 0x6e 0x74 0x72 0x52 0x47 0x42 0x20 0x58 0x59
0x5a 0x20 ...>


Anybody see anything that might be causing the problem?

Thanks,
Bob Herzberg
 
Could you post the code you use to submit the TIFF as a fax? Normally even
tiff files will be subject to printing to fax printer driver, so there
should be no difference between native and generated files
 
Alex said:
Could you post the code you use to submit the TIFF as a fax? Normally even
tiff files will be subject to printing to fax printer driver, so there
should be no difference between native and generated files


Here is the code I send the fax with. Again, it only works with TIFF
files generated by the fax server, or if I run it in a Windows Form
application. It fails on DotNet generated files when invoked from a web
service.

private bool SendFax(string faxnum, string fname)
{
string host = null;
int jobID;

FAXCOMLib.FaxServerClass fserver = new FAXCOMLib.FaxServerClass();
FAXCOMLib.FaxDoc doc;

fserver.Connect(host);

doc = (FAXCOMLib.FaxDoc)fserver.CreateDocument(fname);

doc.FaxNumber = faxnum;
jobID = doc.Send();

return(true);

}


Thanks,
Bob Herzberg
 
I see. As far as I know, attempting to send a document with any extension
but .tif will result in it being printed to fax printer driver to convert it
to tiff. For TIFF files a validation is done. If the validation fails, the
method call will fail too - there will be made no attempt to print it. Two
choices - either rename your document to .PNG (no matter that it's still
tiff inside - it wil lbe printed properly since the printing application
sniffs the stream rather than trusts file extensions), or try to ensure
compatibility of your image.

The things that the Fax library cares about are primarily resolution,
bit-per-pixels and encoding. From the first glance I can tell you that your
document has resolution of 100x100 instead of 204x98 or 204x196
Open your tif file using MS Office Document Imaging application and under
View check the page properties. Compression needs to be either CCITT3 or
CCITT4. If it is LZW, you won't be able to fax it.

If you are using System.Drawing.Imaging.Encoder to save the bitmap, you will
need the following code:

EncoderParameters ep = new EncoderParameters(2);

ep.Param[1] = new EncoderParameter(Encoder.SaveFlag,
(long)EncoderValue.MultiFrame);

ep.Param[0] = new EncoderParameter(Encoder.Compression,
(long)EncoderValue.CompressionCCITT4);

myBitmap.Save(fileName, GetEncoderInfo(ImageFormat.Tif­f), ep);
 
Thanks for the response. I had to modify your code snippet slightly
since I was unable to find a GetEncoderInfo function but I believe it
is similar to what I added. The problem is when I use the CCITT4
compression I get an "Invalid parameter" exception. Am I missing
something?

ImageCodecInfo info=null;
foreach(ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders())
{
if(ice.MimeType=="image/tiff")
{
info=ice;
}
}

EncoderParameters ep = new EncoderParameters(2);

ep.Param[1] = new EncoderParameter(Encoder.SaveFlag,
(long)EncoderValue.MultiFrame);
ep.Param[0] = new EncoderParameter(Encoder.Compression,
(long)EncoderValue.CompressionCCITT4);

m_Bmp.Save("test.tif", info, ep);


Thanks Bob Herzberg


I see. As far as I know, attempting to send a document with any extension
but .tif will result in it being printed to fax printer driver to convertit
to tiff. For TIFF files a validation is done. If the validation fails, the
method call will fail too - there will be made no attempt to print it. Two
choices - either rename your document to .PNG (no matter that it's still
tiff inside - it wil lbe printed properly since the printing application
sniffs the stream rather than trusts file extensions), or try to ensure
compatibility of your image.

The things that the Fax library cares about are primarily resolution,
bit-per-pixels and encoding. From the first glance I can tell you that your
document has resolution of 100x100 instead of 204x98 or 204x196
Open your tif file using MS Office Document Imaging application and under
View check the page properties. Compression needs to be either CCITT3 or
CCITT4. If it is LZW, you won't be able to fax it.

If you are using System.Drawing.Imaging.Encoder to save the bitmap, you will
need the following code:

EncoderParameters ep = new EncoderParameters(2);

ep.Param[1] = new EncoderParameter(Encoder.SaveFlag,
(long)EncoderValue.MultiFrame);

ep.Param[0] = new EncoderParameter(Encoder.Compression,
(long)EncoderValue.CompressionCCITT4);

myBitmap.Save(fileName, GetEncoderInfo(ImageFormat.Tif­f), ep);


--
Alex Feinman
---
Visit http://www.opennetcf.org
Orbian said:
Here is the code I send the fax with. Again, it only works with TIFF
files generated by the fax server, or if I run it in a Windows Form
application. It fails on DotNet generated files when invoked from a web
service.

private bool SendFax(string faxnum, string fname)
{
string host = null;
int jobID;

FAXCOMLib.FaxServerClass fserver = new FAXCOMLib.FaxServerClass();
FAXCOMLib.FaxDoc doc;

fserver.Connect(host);

doc = (FAXCOMLib.FaxDoc)fserver.CreateDocument(fname);

doc.FaxNumber = faxnum;
jobID = doc.Send();

return(true);

}


Thanks,
Bob Herzberg
 
Is your bitmap monochrome? Only mono bitmaps can be saved as CCITT4. THe
PixelFormat must be PixelFormat.Format1bppIndexed

--
Alex Feinman
---
Visit http://www.opennetcf.org
Thanks for the response. I had to modify your code snippet slightly
since I was unable to find a GetEncoderInfo function but I believe it
is similar to what I added. The problem is when I use the CCITT4
compression I get an "Invalid parameter" exception. Am I missing
something?

ImageCodecInfo info=null;
foreach(ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders())
{
if(ice.MimeType=="image/tiff")
{
info=ice;
}
}

EncoderParameters ep = new EncoderParameters(2);

ep.Param[1] = new EncoderParameter(Encoder.SaveFlag,
(long)EncoderValue.MultiFrame);
ep.Param[0] = new EncoderParameter(Encoder.Compression,
(long)EncoderValue.CompressionCCITT4);

m_Bmp.Save("test.tif", info, ep);


Thanks Bob Herzberg


I see. As far as I know, attempting to send a document with any extension
but .tif will result in it being printed to fax printer driver to convert
it
to tiff. For TIFF files a validation is done. If the validation fails, the
method call will fail too - there will be made no attempt to print it. Two
choices - either rename your document to .PNG (no matter that it's still
tiff inside - it wil lbe printed properly since the printing application
sniffs the stream rather than trusts file extensions), or try to ensure
compatibility of your image.

The things that the Fax library cares about are primarily resolution,
bit-per-pixels and encoding. From the first glance I can tell you that
your
document has resolution of 100x100 instead of 204x98 or 204x196
Open your tif file using MS Office Document Imaging application and under
View check the page properties. Compression needs to be either CCITT3 or
CCITT4. If it is LZW, you won't be able to fax it.

If you are using System.Drawing.Imaging.Encoder to save the bitmap, you
will
need the following code:

EncoderParameters ep = new EncoderParameters(2);

ep.Param[1] = new EncoderParameter(Encoder.SaveFlag,
(long)EncoderValue.MultiFrame);

ep.Param[0] = new EncoderParameter(Encoder.Compression,
(long)EncoderValue.CompressionCCITT4);

myBitmap.Save(fileName, GetEncoderInfo(ImageFormat.Tif­f), ep);


--
Alex Feinman
---
Visit http://www.opennetcf.org
Orbian said:
Here is the code I send the fax with. Again, it only works with TIFF
files generated by the fax server, or if I run it in a Windows Form
application. It fails on DotNet generated files when invoked from a web
service.

private bool SendFax(string faxnum, string fname)
{
string host = null;
int jobID;

FAXCOMLib.FaxServerClass fserver = new FAXCOMLib.FaxServerClass();
FAXCOMLib.FaxDoc doc;

fserver.Connect(host);

doc = (FAXCOMLib.FaxDoc)fserver.CreateDocument(fname);

doc.FaxNumber = faxnum;
jobID = doc.Send();

return(true);

}


Thanks,
Bob Herzberg
 
Alex said:
Is your bitmap monochrome? Only mono bitmaps can be saved as CCITT4. THe
PixelFormat must be PixelFormat.Format1bppIndexed


The bitmap is most likely 24bits. I believe in dotnet you can't draw on
a 1bpp bitmap so I convert it to 24bits so I can create the graphics
object. The reason I need to draw on it is I have a form that gets
filled out automatically and then submitted to a fax server. Do you
know of a way to easily go from 24bits to 1bpp?

Thanks,
Bob Herzberg
 
Alex said:
You can do it using this class
http://www.alexfeinman.com/download.asp?doc=BitmapConverter.cs

I haven't tested it too much, but it should do the job. Besides sounds like
you could fix it if need arises


Alex,

The converter works great and I now have a 1bpp image (which saves a
lot of bandwidth too). But it still fails when submitted via a web
service. The only thing I can think of is that whatever app is doing
the printto doens't like the DPI. Is there a way to find out what app
is trying to do the printto? It would appear that a different app is
doing it for my web service than for the windows form. And whatever app
is doing the printto for the web service doesn't like something in the
TIFF header because "real" TIFFs (the ones that come from the fax
server) work just fine via the web service.

Is it possible security settings on the ASP.Net account can't run a
particular printto app so it just moves on to another one that isn't
able to handle my new TIFFs? THe only thing that is different from my
Windows Form app and the web service is the user that they run under. I
feel like the solution is close but I'm missing something.

Thanks for your help,
Bob Herzberg
 
Orbian said:
Alex,

The converter works great and I now have a 1bpp image (which saves a
lot of bandwidth too). But it still fails when submitted via a web
service. The only thing I can think of is that whatever app is doing
the printto doens't like the DPI. Is there a way to find out what app
is trying to do the printto? It would appear that a different app is
doing it for my web service than for the windows form. And whatever app
is doing the printto for the web service doesn't like something in the
TIFF header because "real" TIFFs (the ones that come from the fax
server) work just fine via the web service.

Is it possible security settings on the ASP.Net account can't run a
particular printto app so it just moves on to another one that isn't
able to handle my new TIFFs? THe only thing that is different from my
Windows Form app and the web service is the user that they run under. I
feel like the solution is close but I'm missing something.

Yes, the printing app behavior could be the culprit. However the whole point
of the excercise is to ensure that it is not involved. To do this you need
to get your image resolution set to what fax expects. Woudl you mind
emailing me a sample image, so I'd take a look?
 
Alex said:
Yes, the printing app behavior could be the culprit. However the whole point
of the excercise is to ensure that it is not involved. To do this you need
to get your image resolution set to what fax expects. Woudl you mind
emailing me a sample image, so I'd take a look?

It turns out that the DPI settings are the critical thing for sending
out the fax. I tried the latest BitmapConverter class you posted and
the AdjustImage method correctly sets the DPI settings and downsamples
the image to 1bpp. Whatever app is handling the printto accepts the
image.

Thanks Again,
Bob Herzberg
 
Back
Top