static public int AddActionsGoToE(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_Bookmark bookmark = null; if (Parent.SelectedBookmarkNode == null) { bookmark = Parent.m_CurDoc.BookmarkRoot.AddNewChild(true); } else { bookmark = Parent.SelectedBookmarkNode.m_Bookmark.AddNewSibling(false); } IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); uint atomGoToE = pxsInst.StrToAtom("GoToE"); IPXC_NameTree attachments = Parent.m_CurDoc.GetNameTree("EmbeddedFiles"); IPXS_PDFVariant var = null; try { var = attachments.Lookup("FeatureChartEU.pdf"); } catch (Exception) { string sFilePath = System.Environment.CurrentDirectory + "\\Documents\\FeatureChartEU.pdf"; IPXC_FileSpec fileSpec = Parent.m_CurDoc.CreateEmbeddFile(sFilePath); IPXC_EmbeddedFileStream EFS = fileSpec.EmbeddedFile; EFS.UpdateFromFile2(sFilePath); var = fileSpec.PDFObject; } attachments.Add("FeatureChartEU.pdf", var); IPXC_Action_Goto actionGoToE = Parent.m_pxcInst.GetActionHandler(atomGoToE).CreateEmptyAction(atomGoToE, Parent.m_CurDoc) as IPXC_Action_Goto; IPXC_GoToETargetPath targetPath = actionGoToE.TargetPath; IPXC_GoToETargetItem targetItem = targetPath.InsertNew(); targetItem.FileName = "FeatureChartEU.pdf"; targetItem = targetPath.InsertNew(); targetItem.FileName = "MyStamps.pdf"; targetItem = targetPath.InsertNew(); targetItem.AnnotIndex = 0; targetItem.PageNumber = 0; IPXC_ActionsList aList = Parent.m_CurDoc.CreateActionsList(); bookmark.Title = "GoToE Action"; bookmark.Style = PXC_BookmarkStyle.BookmarkFont_Normal; aList.Insert(0, actionGoToE); bookmark.Actions = aList; Marshal.ReleaseComObject(attachments); return((int)Form1.eFormUpdateFlags.efuf_Bookmarks | (int)Form1.eFormUpdateFlags.efuf_Attachments); }
static public int ChangeAttachmentsDescription(Form1 Parent) { if (Parent.m_CurDoc == null) { return(0); } if (Parent.AttachmentView.SelectedItems.Count == 0) { MessageBox.Show("Please select attachment from the Attachments list.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(0); } Form1.ListItemAttachment currentAnnot = Parent.AttachmentView.SelectedItems[0] as Form1.ListItemAttachment; if (currentAnnot.SubItems[currentAnnot.SubItems.Count - 1].Text == "Embedded File Item") { IPXC_NameTree attachments = Parent.m_CurDoc.GetNameTree("EmbeddedFiles"); IPXS_PDFVariant pdfVariant = attachments.Lookup(currentAnnot.SubItems[0].Text); IPXC_FileSpec fileSpec = Parent.m_CurDoc.GetFileSpecFromVariant(pdfVariant); fileSpec.Description = "Description"; Marshal.ReleaseComObject(attachments); return((int)Form1.eFormUpdateFlags.efuf_Attachments | (int)Form1.eFormUpdateFlags.efuf_Annotations); } IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Annotation annotFileAttach = pages[(uint)currentAnnot.m_nPageNumber].GetAnnot((uint)currentAnnot.m_nIndexOnPage); IPXC_AnnotData_FileAttachment fileAttachment = annotFileAttach.Data as IPXC_AnnotData_FileAttachment; IPXC_FileSpec annotAttachFileSpec = fileAttachment.FileAttachment; annotAttachFileSpec.Description = "Description"; return((int)Form1.eFormUpdateFlags.efuf_Attachments | (int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public int ReadSignatureInfoFromStructure(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.OpenDocFromStringPath(Parent); } IPXS_Inst pxsInst = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS"); //Getting structure document IPXS_Document structDoc = Parent.m_CurDoc.CosDocument; //Locking document for read structDoc.LockDocument(); //Getting Pages dictionary IPXS_PDFVariant pagesDict = structDoc.Root.Dict_Get("Pages"); //Getting pages array dictionary IPXS_PDFVariant kidsDict = pagesDict.Dict_Get("Kids"); //Getting running through pagess for (uint p = 0; p < kidsDict.Count; p++) { IPXS_PDFVariant pageDict = kidsDict[p]; //Getting annotations dictionary IPXS_PDFVariant annotsDict = pageDict.Dict_Get("Annots"); for (uint i = 0; i < annotsDict.Count; i++) { //Getting annotation by index IPXS_PDFVariant annotItem = annotsDict[i]; //Getting subtype IPXS_PDFVariant subtypeDict = annotItem.Dict_Get("Subtype"); string sName = subtypeDict.GetName(); if (sName != "Widget") { continue; } //Getting FT node IPXS_PDFVariant ftDict = annotItem.Dict_Get("FT"); string sFT = ftDict.GetName(); if (sFT != "Sig") { continue; } //If it is a signature then getting the V node with it's info IPXS_PDFVariant vDict = annotItem.Dict_Get("V"); //Getting Reason dict IPXS_PDFVariant reasonDict = vDict.Dict_Get("Reason"); string sReason = reasonDict.GetString(); //Getting ContactInfo IPXS_PDFVariant contactInfoDict = vDict.Dict_Get("ContactInfo"); string sContactInfo = contactInfoDict.GetString(); System.Windows.Forms.MessageBox.Show(sReason + "\n" + sContactInfo); } } //Unlocking the document, since we've finished all of the work with it structDoc.UnlockDocument(); return((int)Form1.eFormUpdateFlags.efuf_None); }
static public void ExportAllFieldsOnPage(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.OpenDocumentFromStream(Parent); Parent.UpdateControlsFromDocument(0); Parent.UpdatePreviewFromCurrentDocument(); } //Getting current page IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page Page = pages[Parent.CurrentPage]; //Locking CosDocument for reading Parent.m_CurDoc.CosDocument.LockDocument(); //Creating new array that will store the variants of the needed form fields IPXS_Inst pxsInst = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS"); IPXS_PDFVariant arrVar = pxsInst.NewVar_Array(0, Parent.m_CurDoc.CosDocument); //Get AcroForm from Document IPXC_AcroForm acroForm = Parent.m_CurDoc.AcroForm; for (uint i = 0; i < acroForm.FieldsCount; i++) { IPXC_FormField field = acroForm.Field[i]; if (field == null) { continue; } arrVar.Arr_Insert(field.PDFObject); Marshal.ReleaseComObject(field); } Parent.m_CurDoc.CosDocument.UnlockDocument(); Marshal.ReleaseComObject(Page); Marshal.ReleaseComObject(pages); if (arrVar.Count == 0) { return; } SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "FDF Documents (*.fdf)|*.fdf|XFDF Documents (*.xfdf)|*.xfdf|HTML Documents (*.html)|*.hrml|XML Documents (*.xml)|*.xml"; sfd.FilterIndex = 4; sfd.CheckPathExists = true; if (sfd.ShowDialog() == DialogResult.OK) { IAFS_Inst afsInst = (IAFS_Inst)Parent.m_pxcInst.GetExtension("AFS"); IAFS_Name name = afsInst.DefaultFileSys.StringToName(sfd.FileName); string sExt = Path.GetExtension(sfd.FileName).ToLower(); sExt = sExt.TrimStart('.'); acroForm.Export(name, sExt, arrVar, true, (uint)PXC_ExportFormFlags.FormExport_Default); Process.Start("explorer.exe", "/select, \"" + sfd.FileName + "\""); } }
static public int AddAttachment(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IAFS_Inst afsInst = Parent.m_pxcInst.GetExtension("AFS"); IPXC_NameTree attachments = Parent.m_CurDoc.GetNameTree("EmbeddedFiles"); IPXS_PDFVariant var = null; string path = Environment.CurrentDirectory + "\\Documents\\FeatureChartEU.pdf"; IPXC_FileSpec fileSpec = Parent.m_CurDoc.CreateEmbeddFile(path); IPXC_EmbeddedFileStream embeddedFileStream = fileSpec.EmbeddedFile;; embeddedFileStream.UpdateFromFile2(path); var = fileSpec.PDFObject; attachments.Add("FeatureChartEU.pdf", var); Marshal.ReleaseComObject(attachments); return((int)Form1.eFormUpdateFlags.efuf_Attachments | (int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public int AddNewDictionaryToDocumentsRoot(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.OpenDocFromStringPath(Parent); } IPXS_Inst pxsInst = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS"); //Getting structure document IPXS_Document structDoc = Parent.m_CurDoc.CosDocument; //Locking document for write structDoc.LockDocumentExclusive(); //Creating new indirect variant of the Dictionary type that will hold some elements IPXS_PDFVariant varHolder = pxsInst.NewVar_Dict(structDoc, true); //Adding our newly created variant to the root dictionary structDoc.Root.Dict_Set("TestDataHolder", varHolder); //Creating an item that will hold some custom data and will link to the bookmarks root IPXS_PDFVariant varBookItem = pxsInst.NewVar_Dict(structDoc, true); //Adding that item to the holder dictionary varHolder.Dict_Set("BookmarkItem", varBookItem); //Setting some custom fields for this item varBookItem.Dict_SetBool("IsRoot", true); varBookItem.Dict_SetName("CustName", "Root Link"); varBookItem.Dict_SetInt("CustInt", 123); //Setting a link to the bookmark's Root object IPXC_Bookmark root = Parent.m_CurDoc.BookmarkRoot; //If we have at least one bookmark in the document, then the root won't be null if (root != null) { varBookItem.Dict_Set("BookmarkLink", root.PDFObject); } //Unlocking the document, since we've finished all of the work with it structDoc.UnlockDocumentExclusive(); return((int)Form1.eFormUpdateFlags.efuf_All); }