gpt4 book ai didi

c++ - 如何获取spl文件的页数

转载 作者:太空宇宙 更新时间:2023-11-04 13:47:36 25 4
gpt4 key购买 nike

我正在从事一个旨在监控打印作业的项目。我正在将 spl 和 shd 文件从 spool 文件夹复制到一个临时文件夹,并尝试解析以获取我想要的数据,例如打印页数、所有者、日期和时间...

我正在使用以下代码来解析后台处理程序 spl 文件(获取 emf 文件结构)

#include "stdafx.h"
#include <windows.h>
#include <winspool.h>
#include <stdio.h>
#include <locale.h>
#include <tchar.h>
#include <iostream>
using namespace std;

BOOL AnalyseFile(const char* pszFileName);

void UPFM(const wchar_t pszInfo[])
{
wprintf(L"%s\n",pszInfo);
}

static char* ID_Func[] =
{
"EMF_HEADER", "EMF_POLYBEZIER", /*....*/
};

int main()
{
setlocale(LC_ALL,"");

const char* pszFileName = "~MyTempFolder\\00031.SPL";

if(!AnalyseFile(pszFileName))
printf("Analyse File Failed!");
else
printf("Analyse File Successed Completed!");

return 0;
}


BOOL AnalyseFile(const char* pszFileName)
{
BOOL bRet = FALSE;

DWORD dwStartPos = 0;
FILE * f ;
f = fopen("log.txt", "w");
FILE* pFile = fopen(pszFileName,"rb");

if(!pFile)
{
fprintf(f,"Open File Failed!");
return bRet;
}

/* =======================Headers================================ */
DWORD dwTmp = 0;

fseek(pFile,0,0);

fread(&dwTmp,sizeof(DWORD),1,pFile);

fread(&dwTmp,sizeof(DWORD),1,pFile);

dwStartPos = dwTmp;

fread(&dwTmp,sizeof(DWORD),1,pFile);

long pos = ftell(pFile);

fseek(pFile,dwTmp,SEEK_SET);

wchar_t pszInfo[256] = {0};
pszInfo[0] = L'(';

WORD wTmp;
int i;
for( i = 1;;i++)
{
fread(&wTmp,sizeof(wTmp),1,pFile);

if(!wTmp)
break;

memcpy((char*)&pszInfo[i],&wTmp,sizeof(wTmp));
}
pszInfo[i] = L')';
UPFM(pszInfo);

fseek(pFile,pos,SEEK_SET);

fread(&dwTmp,sizeof(DWORD),1,pFile);

fseek(pFile,dwTmp,SEEK_SET);

memset(pszInfo,0,sizeof(wchar_t)*256);
pszInfo[0] = L'(';
for(i = 1;;i++)
{
fread(&wTmp,sizeof(wTmp),1,pFile);

if(!wTmp)
break;

memcpy((char*)&pszInfo[i],&wTmp,sizeof(wTmp));
}
pszInfo[i] = L')';
UPFM(pszInfo);

/* ======================== Unknown datas ================================= */
fseek(pFile,dwStartPos,SEEK_SET);

fread(&dwTmp,sizeof(DWORD),1,pFile);

fread(&dwTmp,sizeof(DWORD),1,pFile);

/* ======================== Record datas ================================= */
DWORD dwTmp2 = 0;
for(int i=0;;i++)
{
pos = ftell(pFile);

fread(&dwTmp,sizeof(DWORD),1,pFile);

fread(&dwTmp2,sizeof(DWORD),1,pFile);
FILE *f;
f = fopen("log.txt", "a");

fprintf(f,"index: (%04d) type: 0x%04X size: %04d 0x%08X (%s)\n",i,dwTmp,dwTmp2,pos,ID_Func[dwTmp-1]);
fclose (f);

if(dwTmp == 0x0E)
{
break;
}

fseek(pFile,pos+dwTmp2,SEEK_SET);
}
fclose (f);
if(pFile) fclose(pFile);
bRet = TRUE;

return bRet;
}

有没有办法用这种方法计算spl文件的页数?

最佳答案

要计算页面,您必须计算 PAGE 标题。

下面是部分代码

 SpoolFilename = Path.ChangeExtension(SpoolFilename, ".SPL")

'\\ Open a binary reader for the spool file
Dim SpoolFileStream As New System.IO.FileStream(SpoolFilename, FileMode.Open, FileAccess.Read)
Dim SpoolBinaryReader As New BinaryReader(SpoolFileStream, System.Text.Encoding.UTF8)

'Read the spooler records and count the total pages
Dim recNext As EMFMetaRecordHeader = NextHeader(SpoolBinaryReader)
While recNext.iType <> SpoolerRecordTypes.SRT_EOF
If recNext.iType = SpoolerRecordTypes.SRT_PAGE Then
_Pages += 1
End If
'SpoolfileReaderPerformaceCounter.Increment()
Call SkipAHeader(recNext, SpoolBinaryReader)
recNext = NextHeader(SpoolBinaryReader)
End While

代码获取文件名,为其打开二进制流,并逐个读取 header 。如果 header 代码是 SRT_PAGE,则增加页面计数器。

更多详细信息和来源 here

关于c++ - 如何获取spl文件的页数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25205317/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com