Created
June 13, 2017 11:59
-
-
Save Polaringu/6b57012d484fa84d73362f13e69e28a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void ReplaceImage(PDFXEdit.IPXV_Document Doc, PDFXEdit.IPXV_Inst Inst) | |
{ | |
int nID = Inst.Str2ID("op.document.replaceImage", false); | |
PDFXEdit.IOperation Op = Inst.CreateOp(nID); | |
var input = Op.Params.Root["Input"]; | |
input.Add().v = Doc.CoreDoc; | |
PDFXEdit.ICabNode options = Op.Params.Root["Options"]; | |
int nSelID = Inst.Str2ID("selection.contentItems", false); | |
uint nPage = 0; //Page number that will have it's image content item edited | |
//First we need to create content items selection | |
PDFXEdit.IPXV_ContentItemsSelection itSel = (PDFXEdit.IPXV_ContentItemsSelection)Doc.CreateStdSel((uint)nSelID); | |
//Then we need to get root item entry for the desired page (we'll create it if needed) | |
PDFXEdit.IPXV_ContentItemEntry itEntry = itSel.GetSel(nPage, true); | |
//Inserting needed content items from the page | |
var content = Doc.CoreDoc.Pages[nPage].GetContent(PDFXEdit.PXC_ContentAccessMode.CAccessMode_Readonly); | |
if (GetFirstImageOnPage(content, ref itEntry) == false) | |
return; | |
//Adding selected page's root entry with added image content item to the operation | |
options["Entry"].v = itEntry; //If it's used in pair with the op.document.extractImage the original IPXV_ContentItemEntry should be used | |
//Input image file | |
PDFXEdit.IAFS_Inst fsInst = (PDFXEdit.IAFS_Inst)pdfCtl.Inst.GetExtension("AFS"); | |
PDFXEdit.IAFS_Name name = fsInst.DefaultFileSys.StringToName(@"D:\TestImage_res.png"); | |
//Src can be of the next types: IAFS_File, IAFS_Name, IString, IStream, IIXC_Image, IIXC_Page | |
options["Src"].v = name; | |
//First page of the image (in case of multipage images) | |
options["SrcFrameIndex"].v = 0; | |
//Setting whether the reversed matrix should be used for correct image resulting appearance | |
//If the image was extracted visually then the UseReverseMatrix = true must be supplied for the reverse op.document.replaceImage operation | |
options["UseReverseMatrix"].v = false; | |
//Replacing image content item | |
Op.Do(); | |
//Clearing the selection | |
itSel.Clear(); | |
} | |
private void ExportImage(PDFXEdit.IPXV_Document Doc, PDFXEdit.IPXV_Inst Inst) | |
{ | |
int nID = Inst.Str2ID("op.document.extractImage", false); | |
PDFXEdit.IOperation Op = Inst.CreateOp(nID); | |
var input = Op.Params.Root["Input"]; | |
input.Add().v = Doc.CoreDoc; | |
PDFXEdit.ICabNode options = Op.Params.Root["Options"]; | |
int nSelID = Inst.Str2ID("selection.contentItems", false); | |
uint nPage = 0; //Page number that will have it's image content item exported | |
//First we need to create content items selection | |
PDFXEdit.IPXV_ContentItemsSelection itSel = (PDFXEdit.IPXV_ContentItemsSelection)Doc.CreateStdSel((uint)nSelID); | |
//Then we need to get root item entry for the desired page (we'll create it if needed) | |
PDFXEdit.IPXV_ContentItemEntry itEntry = itSel.GetSel(nPage, true); | |
//Inserting needed content items from the page | |
var content = Doc.CoreDoc.Pages[nPage].GetContent(PDFXEdit.PXC_ContentAccessMode.CAccessMode_Readonly); | |
if (GetFirstImageOnPage(content, ref itEntry) == false) | |
return; | |
//Adding selected page's root entry with added image content item to the operation | |
options["Entry"].v = itEntry; | |
//Setting resulting png file name | |
options["FileName"].v = @"D:\TestImage_res.png"; | |
//Setting whether the image should be extracted visually or as it is in the PDF content | |
//If the image was extracted visually then the UseReverseMatrix = true must be supplied for the reverse op.document.replaceImage operation | |
options["ExtractVisually"].v = false; | |
//Extracting image content item | |
Op.Do(); | |
//Clearing the selection | |
itSel.Clear(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment