I am executing a export to tif operation(code below). If I create a Windows Service/Console App/Mock Desktop app it works fine, but when I create a VS2017 unit test i get a "-2147418113", Critical Failure. The error is on the "operation.do()" call.
Anyone have experience or advice on this topic?
Code: Select all
if (File.Exists(inputPDF))
{
if (File.Exists(outputTIF))
{
DolphinIOTools.DeleteFile(outputTIF);
}
if (outputTIF == null || outputTIF == "")
{
outputTIF = DolphinIOTools.GetNextValidFileName(Path.GetDirectoryName(inputPDF) + @"\" + Path.GetFileNameWithoutExtension(inputPDF) + ".tif");
Logger.Log("SavePath not set, defaulting to PDF path: " + outputTIF, 5);
}
if (!Directory.Exists(Path.GetDirectoryName(outputTIF)))
{
Directory.CreateDirectory(Path.GetDirectoryName(outputTIF));
}
Init();
IPXC_Inst pxcInst = (IPXC_Inst)viewerInstance.GetExtension("PXC");
IPXC_Document doc = pxcInst.OpenDocumentFromFile(inputPDF, clbk);
int nID = viewerInstance.Str2ID("op.document.exportToImages", false);
IOperation Op = viewerInstance.CreateOp(nID);
ICabNode input = Op.Params.Root["Input"];
input.Add().v = doc;
ICabNode options = Op.Params.Root["Options"];
if (page == -1)
{
options["PagesRange.Type"].v = "All";
}
else
{
options["PagesRange.Type"].v = "Exactly";
options["PagesRange.Text"].v = Convert.ToString(page+1);
}
options["FileName"].v = outputTIF;
options["ExportMode"].v = "AllToMutliPage";
options["ShowResultFolder"].v = 0;
options["DpiX"].v = dpi;
options["DpiY"].v = dpi;
ICabNode fmtParams = options["FormatParams"];
fmtParams["COMP"].v = 5; //LZW compression
fmtParams["FMT"].v = 1414088262; //TIFF
if (useColor)
{
fmtParams["ITYP"].v = 32; //24 TrueColor w/alpha
}
else
{
fmtParams["ITYP"].v = 8;
}
fmtParams["PRED"].v = 1; //Yes
if (thumbNail)
{
double thumbZoom = doc.Pages[((uint)page)].get_Box(PXC_BoxType.PBox_CropBox).right / 72 * dpi / defaultThumbNailWidth;
thumbZoom = Math.Round(thumbZoom, 2);
options["Zoom"].v = thumbZoom;
//fmtParams["THUM"].v = 1; //No
}
else
{
options["Zoom"].v = 100;
fmtParams["THUM"].v = 0; //No
}
Op.Do();
doc.Close();
options.Clear();
fmtParams.Clear();
input.Clear();
pxcInst = null;
Logger.Log("PDF File: " + inputPDF + ", does not exist. Cannot convert to TIF file: " + outputTIF, 1);
}
else
{
Logger.Log("PDF File: " + inputPDF + ", does not exist. Cannot convert to TIF", 1);
}