Hello,
Thank you for your inquiry.
Note that Spire.Doc can only load files of the format type it supports, PDF is not a format type supported by Spire.Doc, so after loading a PDF stream file, the value obtained by DetectedFormatType is incorrect. So you need to use your own code to determine the file format before loading the flow file, and then deal with it.
Please refer to the following code to determine the file format of the stream file:
- Code: Select all
static void Main(string[] args)
{
string fileName = "input.pdf";
FileExtension fileExtension= CheckFileType(fileName);
}
public static FileExtension CheckFileType(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
string fileType = string.Empty; ;
try
{
byte data = br.ReadByte();
fileType += data.ToString();
data = br.ReadByte();
fileType += data.ToString();
FileExtension extension;
try
{
extension = (FileExtension)Enum.Parse(typeof(FileExtension), fileType);
}
catch
{
extension = FileExtension.VALIDFILE;
}
return extension;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (fs != null)
{
fs.Close();
br.Close();
}
}
}
public enum FileExtension
{
JPG = 255216,
GIF = 7173,
BMP = 6677,
PNG = 13780,
COM = 7790,
EXE = 7790,
DLL = 7790,
RAR = 8297,
ZIP = 8075,
XML = 6063,
HTML = 6033,
ASPX = 239187,
CS = 117115,
JS = 119105,
TXT = 210187,
SQL = 255254,
BAT = 64101,
BTSEED = 10056,
RDP = 255254,
PSD = 5666,
PDF = 3780,
CHM = 7384,
LOG = 70105,
REG = 8269,
HLP = 6395,
DOC = 208207,
XLS = 208207,
DOCX = 208207,
XLSX = 208207,
VALIDFILE = 9999999
}
Sincerely,
Annika
E-iceblue support team