https://sdkhelp.pdf-xchange.com/view/PXV:PXV_Inst says you can use the SDK in most circumstances without registration (but not PXV_Control).
That matches what I wanted to do: I'm trying to extract pages from a PDF file. So I have the code below, but it fails if we get to operation.Params.Root, throwing because a library isn't registered.
It seems like if you can't get to operation.Params.Root, you wouldn't be able to do much with PXV_Inst without requiring registration. Is there something I'm missing?
Thanks.
Code: Select all
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Test
{
class Program
{
static void Main(string[] args)
{
string outputPath = @"c:\outputPath\out.pdf";
//string inputPath = @"c:\inputPath\in.pdf";
const uint opExecFlagsNoUINoProgress = 3;
string libraryName = IntPtr.Size == 4 ? "PDFXEditCore.x86.DLL" : "PDFXEditCore.x64.DLL";
IntPtr module = LoadLibrary(libraryName);
IntPtr hProc = GetProcAddress(module, "PXV_GetInstance");
var pxvDelegate = (PXV_GetInstance)(object)Marshal.GetDelegateForFunctionPointer(hProc, typeof(PXV_GetInstance));
IPXV_Inst typedInstance;
HRESULT result = pxvDelegate(out typedInstance);
dynamic instance = typedInstance;
instance.Init(Missing.Value, "");
int extractPagesId = instance.Str2ID("op.document.extractPages", false);
var pxcInst = (dynamic)instance.GetExtension("PXC");
try
{
//var doc = pxcInst.OpenDocumentFromFile(inputPath, Missing.Value); //Side issue: This gives DISP_E_BADVARTYPE
var operation = instance.CreateOp(extractPagesId);
var operationParams = operation.Params;
var root = operationParams.Root; //Trying to get root throws because a type isn't registered
var options = operation.Params.Root["Options"];
var pagesRange = options["PagesRange"];
pagesRange["Type"].v = 6;// PDFXEdit.RangeType.RangeType_Exact;
pagesRange["Text"].v = string.Join(",", "4");
options["OpenFolder"].v = false;
options["ExtractPagesAction"].v = "AllToOneFile";
options["LocalFolder"].v = Path.GetDirectoryName(outputPath);
options["FileName"].v = Path.GetFileName(outputPath);
var input = operation.Params.Root["Input"];
//input.v = doc;
instance.AsyncDoAndWaitForFinish(operation, opExecFlagsNoUINoProgress);
byte[] bytes = File.ReadAllBytes(outputPath);
Console.WriteLine(bytes.Length);
}
catch (COMException ex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
}
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr LoadLibrary(string dllName);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate HRESULT PXV_GetInstance([MarshalAs(UnmanagedType.Interface)]out IPXV_Inst foo);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern IntPtr GetProcAddress(IntPtr module, [In, MarshalAs(UnmanagedType.LPStr)] string procName);
}
[StructLayout(LayoutKind.Sequential)]
public struct HRESULT
{
private readonly int _Value;
public HRESULT(int value)
{ _Value = value; }
}
[Guid("D726366D-34D6-49FC-A341-7B84C54CCA3E")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[ComImport]
interface IPXV_Inst
{
}
}