如果我使用FPDF_CreateNewDocument()
创建一个新的PDF文件,然后使用FPDF_SaveAsCopy
保存它,则一切正常:
FPDF_DOCUMENT destDoc = FPDF_CreateNewDocument();
if (!destDoc) {
return 1;
}
FPDF_FILEWRITE writer;
writer.version = 1;
writer.WriteBlock = FakeBlockWriter;
if (!FPDF_SaveAsCopy(destDoc, &writer, 0))
{
return 1;
}
但是,使用FPDF_LoadDocument()
打开PDF文件在调用FPDF_SaveAsCopy()
时给我一个错误,例如:
FPDF_STRING test_doc = "C:\\temp.pdf";
FPDF_DOCUMENT srcDoc = FPDF_LoadDocument(test_doc, NULL);
if (!srcDoc) {
return 1;
}
FPDF_FILEWRITE writer;
writer.version = 1;
writer.WriteBlock = FakeBlockWriter;
if (!FPDF_SaveAsCopy(srcDoc, &writer, 0))
{
return 1;
}
断言失败的原因是CFX_FileBufferArchive::WriteBlock
,pBuf
为空:
bool CFX_FileBufferArchive::WriteBlock(const void* pBuf, size_t size) {
ASSERT(pBuf && size > 0);
Callstack:
pdfium.dll!common_assert_to_message_box<wchar_t>(const wchar_t * const expression, const wchar_t * const file_name, const unsigned int line_number, void * const return_address) Line 388
pdfium.dll!common_assert<wchar_t>(const wchar_t * const expression, const wchar_t * const file_name, const unsigned int line_number, void * const return_address) Line 424
pdfium.dll!_wassert(const wchar_t * expression, const wchar_t * file_name, unsigned int line_number) Line 444
pdfium.dll!`anonymous namespace'::CFX_FileBufferArchive::WriteBlock(const void * pBuf, unsigned __int64 size) Line 77
pdfium.dll!`anonymous namespace'::CFX_FileBufferArchive::WriteString(const fxcrt::StringViewTemplate<char> & str) Line 111
pdfium.dll!CPDF_Name::WriteTo(IFX_ArchiveStream * archive) Line 55
pdfium.dll!CPDF_Dictionary::WriteTo(IFX_ArchiveStream * archive) Line 290
pdfium.dll!CPDF_Creator::WriteDirectObj(unsigned int objnum, const CPDF_Object * pObj, bool bEncrypt) Line 262
pdfium.dll!CPDF_Creator::WriteIndirectObj(unsigned int objnum, const CPDF_Object * pObj) Line 189
pdfium.dll!CPDF_Creator::WriteOldIndirectObject(unsigned int objnum) Line 306
pdfium.dll!CPDF_Creator::WriteOldObjs() Line 319
pdfium.dll!CPDF_Creator::WriteDoc_Stage2() Line 430
pdfium.dll!CPDF_Creator::Continue() Line 766
pdfium.dll!CPDF_Creator::Create(unsigned int flags) Line 711
pdfium.dll!`anonymous namespace'::FPDF_Doc_Save(fpdf_document_t__ * document, FPDF_FILEWRITE_ * pFileWrite, unsigned long flags, int bSetVersion, int fileVerion) Line 247
pdfium.dll!FPDF_SaveAsCopy(fpdf_document_t__ * document, FPDF_FILEWRITE_ * pFileWrite, unsigned long flags) Line 261
PdfiumApp.exe!main()
我错过了中间手术吗?