examples/activex_cpp/repair/repair.cpp
38 lines
// ============================================================================
// repair -- C++ ActiveX (COM) port, following
// examples/activex/repair/repair.vbs
//
// Fixes a damaged PDF with a SINGLE call: ConvertFile(..., ctNormalize).
// Normalising a file forces the engine down its repair path, and
// GetInRepairMode afterwards reports which repair strategy it actually needed.
//
// The AX ConvertFile is the 7-argument form (ends at OwnerPwd) -- the flat
// API's trailing OnFontNotFound / OnReplaceICCProfile callback pointers have
// no place on a COM signature; they are connection-point events instead.
// ============================================================================
#import "..\\..\\wrappers\\activex\\LumasPdfAX.tlb" no_namespace named_guids
#include <windows.h>
#include "axcommon.h"
#include <cstdio>
int main() {
ChdirToExe();
ComInit com;
if (!com.ok()) return 1;
ILumasPDFPtr pdf;
if (FAILED(pdf.CreateInstance(L"LumasPdf.PDF"))) return 1;
// ctNormalize ; "" for RGBProfile / CMYKProfile / OwnerPwd (not needed here)
long rc = pdf->ConvertFile(B("../../test_files/corrupt.pdf"), B("repaired.pdf"),
ctNormalize, 0, B(""), B(""), B(""));
VARIANT_BOOL repairMode = pdf->GetInRepairMode();
std::printf("ConvertFile(ctNormalize) rc=%ld (repair-mode used: %d)\n",
rc, repairMode ? -1 : 0);
return 0;
}
This file is in the SDK at examples/activex_cpp/repair/repair.cpp.
The build fails if this page and that file ever differ.