I am working on a part of a system handling PDFs and one bit in particular that requires me to extract a page, do some work on that page and then put it back into the document. (replaceing the page that was extracted) I can extract the page and do the work on it just fine, but I'm getting System.AccessViolationException when trying to replace the page. I am using the replacePage operation you have provided a sample code for in the documentation at https://sdkhelp.pdf-xchange.com/vie ... placePages, but it does not say whether it is possible to replace a page on an open document or not. My question is it possible to replace a page in an open document or do I have to close the document, replace the page and then reopen it? If it is possible, I'm guessing I have use the operation incorrect and am wondering how to do it correctly. Basically, is it me misinterpreting the methods or am I using them incorrectly?
The error I get:
This is the code for my ExtractPage mathod:System.AccessViolationException occurred
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
Code: Select all
private void ExtractPages(string outputPath, int pageToExtract)
{
int nID = Inst.Str2ID("op.document.extractPages", false);
IOperation Op = Inst.CreateOp(nID);
ICabNode input = Op.Params.Root["Input"];
input.v = Doc; // reference to the document that is opened in the Control
ICabNode options = Op.Params.Root["Options"];
options["PagesRange.Type"].Int = 8;
options["PagesRange.Current"].Int = pageToExtract;
options["CommentsAction"].Int = 0;
options["FieldsAction"].Int = 0;
options["BookmarksAction"].Int = 1;
options["DeletePages"].Bool = false;
options["ExtractPagesAction"].Int = 1;
options["OverwriteAll"].Bool = true;
options["LocalFolder"].String = outputPath;
options["FileName"].v = "TESTPDF";
options["OpenFolder"].Bool = false;
Op.Do();
}
Code: Select all
private void ReplacePage(string pathToSrcDocument)
{
int nID = Inst.Str2ID("op.document.replacePages", false);
IOperation Op = Inst.CreateOp(nID);
ICabNode input = Op.Params.Root["Input"];
input.v = Doc; // reference to the document that is opened in the Control
ICabNode options = Op.Params.Root["Options"];
options["PagesRange.Type"].Int = 1;
options["PagesRange.Filter"].Int = 1; // the source document only have one page and that is why I'm using the "All pages" type and filter
options["CommentsAction"].Int = 0;
options["FieldsAction"].Int = 0;
options["BookmarksAction"].Int = 1;
options["ContentOnly"].Bool = false;
IAFS_Inst fsInst = (IAFS_Inst)Inst.GetExtension("AFS");
IAFS_Name destPath = fsInst.DefaultFileSys.StringToName(pathToSrcDocument);
options["Src"].v = destPath;
Op.Do();
}
Code: Select all
options["CommentsAction"].v = 0; //Don't copy comments
PS.I am using the desktop on my computer as output folder for extract and input folder (+ filename) for replace.DS.
//Philip