static public void AddCheckBoxFormFields(Form1 Parent) { int index = 1; //delegate string CheckNamesFields(IPXC_Document Doc, string fieldName, ref int x); CheckNamesFields checkNamesFields = (IPXC_Document Doc, string fName, ref int inx) => { string sFieldName = ""; uint i = 0; do { sFieldName = fName + inx; IPXC_FormField ff = Doc.AcroForm.GetFieldByName(sFieldName); if (ff == null) { break; } inx++; i++; }while (i <= Doc.AcroForm.FieldsCount); inx++; return(sFieldName); }; if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } PXC_Rect rc = new PXC_Rect(); rc.top = 800; rc.right = 600; //Adding uncheked checkbox IPXC_UndoRedoData urD = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page Page = pages.InsertPage(0, rc, out urD); PXC_Rect rcPB = new PXC_Rect(); rcPB.left = 3.2 * 72.0; rcPB.right = rcPB.left + 0.5 * 72.0; rcPB.top = rc.top - 0.2 * 72.0; rcPB.bottom = rcPB.top - 0.5 * 72.0; //top is greater then bottom (PDF Coordinate System) IPXC_FormField checkBoxUnch = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "CheckBox", ref index), PXC_FormFieldType.FFT_CheckBox, 0, ref rcPB); Marshal.ReleaseComObject(checkBoxUnch); //Adding cheked checkbox rcPB.right = rc.right - 3.2 * 72.0; rcPB.left = rcPB.right - 0.5 * 72.0; IPXC_FormField checkBoxCh = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "CheckBox", ref index), PXC_FormFieldType.FFT_CheckBox, 0, ref rcPB); IPXC_Annotation annot = checkBoxCh.Widget[0]; IPXC_AnnotData_Widget widget = (IPXC_AnnotData_Widget)annot.Data; checkBoxCh.CheckWidget((uint)checkBoxCh.GetWidgetIndex(annot), true); Marshal.ReleaseComObject(checkBoxCh); Marshal.ReleaseComObject(Page); Marshal.ReleaseComObject(pages); }
static public void AddDateFormFields(Form1 Parent) { int index = 1; //delegate string CheckNamesFields(IPXC_Document Doc, string fieldName, ref int x); CheckNamesFields checkNamesFields = (IPXC_Document Doc, string fName, ref int inx) => { string sFieldName = ""; uint i = 0; do { sFieldName = fName + inx; IPXC_FormField ff = Doc.AcroForm.GetFieldByName(sFieldName); if (ff == null) { break; } inx++; i++; }while (i <= Doc.AcroForm.FieldsCount); inx++; return(sFieldName); }; if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } PXC_Rect rc = new PXC_Rect(); rc.top = 800; rc.right = 600; //Adding Date IPXC_UndoRedoData urD = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page Page = pages.InsertPage(0, rc, out urD); PXC_Rect rcPB = new PXC_Rect(); rcPB.left = 2.5 * 72.0; rcPB.right = rc.right - 2.5 * 72.0; rcPB.top = rc.top - 1.5 * 72.0; rcPB.bottom = rcPB.top - 0.5 * 72.0; //top is greater then bottom (PDF Coordinate System) IPXC_FormField Date = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Date", ref index), PXC_FormFieldType.FFT_Text, 0, ref rcPB); IPXC_Annotation annot = Date.Widget[0]; IPXC_AnnotData_Widget widget = (IPXC_AnnotData_Widget)annot.Data; IPXC_ActionsList actionsList = Parent.m_CurDoc.CreateActionsList(); //Set script to ActionList actionsList.AddJavaScript("var now = new Date()\n" + "this.getField(\"Date1\").value = (now.getMonth() + 1) + \"/\" + now.getDate() + \"/\" + now.getFullYear(); "); Date.Actions[PXC_TriggerType.Trigger_Format] = actionsList; Marshal.ReleaseComObject(Date); Marshal.ReleaseComObject(Page); Marshal.ReleaseComObject(pages); }
static public void AddComboBoxFormFields(Form1 Parent) { int index = 1; //delegate string CheckNamesFields(IPXC_Document Doc, string fieldName, ref int x); CheckNamesFields checkNamesFields = (IPXC_Document Doc, string fName, ref int inx) => { string sFieldName = ""; uint i = 0; do { sFieldName = fName + inx; IPXC_FormField ff = Doc.AcroForm.GetFieldByName(sFieldName); if (ff == null) { break; } inx++; i++; }while (i <= Doc.AcroForm.FieldsCount); inx++; return(sFieldName); }; if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } PXC_Rect rc = new PXC_Rect(); rc.top = 800; rc.right = 600; //Adding ComboBox with items IPXC_UndoRedoData urD = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page Page = pages.InsertPage(0, rc, out urD); PXC_Rect rcPB = new PXC_Rect(); rcPB.left = 1.5 * 72.0; rcPB.right = rc.right - 1.5 * 72.0; rcPB.top = rc.top - 1.5 * 72.0; rcPB.bottom = rcPB.top - 0.5 * 72.0; //top is greater then bottom (PDF Coordinate System) IPXC_FormField comboBox = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "ComboBox", ref index), PXC_FormFieldType.FFT_ComboBox, 0, ref rcPB); comboBox.InsertOptRecord("lable1", "First Item"); comboBox.InsertOptRecord("lable2", "Second Item"); comboBox.InsertOptRecord("lable3", "Third Item"); comboBox.InsertOptRecord("lable4", "Forth Item"); comboBox.SelectItem(1, true); Marshal.ReleaseComObject(comboBox); Marshal.ReleaseComObject(Page); Marshal.ReleaseComObject(pages); }
static public int AddTextAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); //Getting Text annotation atom for the InsertNewAnnot method uint nText = pxsInst.StrToAtom("Text"); double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 2.0; PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 200; rcOut.bottom = nCY + 250; rcOut.right = nCX - 150; rcOut.top = nCY + 300; IPXC_Annotation annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); IPXC_AnnotData_Text aData = annot.Data as IPXC_AnnotData_Text; aData.Contents = "Text Annotation 1."; aData.Title = "Text Annotation 1"; var color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.0f, 0.8f, 0.8f); aData.Color = color; aData.Opacity = 0.5f; annot.Data = aData; rcOut.bottom -= 100; rcOut.top -= 100; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Text; aData.Contents = "Text Annotation 2."; aData.Title = "Text Annotation 2"; color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.5f, 0.4f, 0.48f); aData.Color = color; annot.Data = aData; Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public int AddPopupAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); //Getting Popup annotation atom for the InsertNewAnnot method uint nSquare = pxsInst.StrToAtom("Square"); double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 2.0; PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 200; rcOut.bottom = nCY + 200; rcOut.right = nCX + 200; rcOut.top = nCY + 300; IPXC_Annotation sqAnnot = page.InsertNewAnnot(nSquare, ref rcOut); IPXC_AnnotData_SquareCircle aSData = sqAnnot.Data as IPXC_AnnotData_SquareCircle; var color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.0f, 0.8f, 0.8f); aSData.Color = color; aSData.Title = "Square annotation 1."; aSData.Contents = "Popup Annotation 1."; sqAnnot.Data = aSData; //Getting Text annotation atom for the InsertNewAnnot method uint nText = pxsInst.StrToAtom("Popup"); IPXC_Annotation annot = page.InsertNewAnnot(nText, ref rcOut); IPXC_AnnotData_Popup aData = annot.Data as IPXC_AnnotData_Popup; aData.Opened = true; annot.Data = aData; sqAnnot.SetPopup(annot); Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public void AddBarcodeFormFields(Form1 Parent) { int index = 1; //delegate string CheckNamesFields(IPXC_Document Doc, string fieldName, ref int x); CheckNamesFields checkNamesFields = (IPXC_Document Doc, string fName, ref int inx) => { string sFieldName = ""; uint i = 0; do { sFieldName = fName + inx; IPXC_FormField ff = Doc.AcroForm.GetFieldByName(sFieldName); if (ff == null) { break; } inx++; i++; }while (i <= Doc.AcroForm.FieldsCount); inx++; return(sFieldName); }; if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } PXC_Rect rc = new PXC_Rect(); rc.top = 800; rc.right = 600; //Adding Barcode IPXC_UndoRedoData urD = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page Page = pages.InsertPage(0, rc, out urD); PXC_Rect rcPB = new PXC_Rect(); rcPB.left = 2.5 * 72.0; rcPB.right = rc.right - 2.5 * 72.0; rcPB.top = rc.top - 1.5 * 72.0; rcPB.bottom = rcPB.top - 1.5 * 72.0; //top is greater then bottom (PDF Coordinate System) IPXC_FormField Barcode = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Barcode", ref index), PXC_FormFieldType.FFT_Barcode, 0, ref rcPB); Marshal.ReleaseComObject(Barcode); Marshal.ReleaseComObject(Page); Marshal.ReleaseComObject(pages); }
static public void AddRadioButtonsFormFields(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } PXC_Rect rc = new PXC_Rect(); rc.top = 800; rc.right = 600; //Adding group with RadioButtons IPXS_Inst pxsInst = (IPXS_Inst)Parent.m_pxcInst.GetExtension("PXS"); IPXC_UndoRedoData urD = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page Page = pages.InsertPage(0, rc, out urD); PXC_Rect rcPB = new PXC_Rect(); rcPB.top = rc.top - 0.35 * 72.0; rcPB.bottom = rcPB.top - 0.5 * 72.0; //top is greater then bottom (PDF Coordinate System) rcPB.left = 1.7 * 72.0; rcPB.right = rcPB.left + 0.5 * 72.0; IPXC_FormField firstGroup = Parent.m_CurDoc.AcroForm.CreateField("RadioButton", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB); rcPB.left = 2.3 * 72.0; rcPB.right = rcPB.left + 0.5 * 72.0; Parent.m_CurDoc.AcroForm.CreateField("RadioButton", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB); rcPB.left = 2.9 * 72.0; rcPB.right = rcPB.left + 0.5 * 72.0; Parent.m_CurDoc.AcroForm.CreateField("RadioButton", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB); rcPB.right = rc.right - 1.5 * 72.0; rcPB.left = rcPB.right - 0.5 * 72.0; IPXC_FormField secondGroup = Parent.m_CurDoc.AcroForm.CreateField("RadioButton1", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB); rcPB.top = rcPB.top - 0.6 * 72.0; rcPB.bottom = rcPB.top - 0.5 * 72.0; Parent.m_CurDoc.AcroForm.CreateField("RadioButton1", PXC_FormFieldType.FFT_RadioButton, 0, ref rcPB); firstGroup.CheckWidget(1, true); secondGroup.CheckWidget(1, true); Marshal.ReleaseComObject(firstGroup); Marshal.ReleaseComObject(secondGroup); Marshal.ReleaseComObject(Page); Marshal.ReleaseComObject(pages); }
static public int AddAttachmentAsAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); //Getting File attachment annotation atom for the InsertNewAnnot method uint nText = pxsInst.StrToAtom("FileAttachment"); double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 2.0; PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 200; rcOut.bottom = nCY + 250; rcOut.right = nCX - 150; rcOut.top = nCY + 300; IPXC_Annotation annot = page.InsertNewAnnot(nText, ref rcOut); IPXC_AnnotData_FileAttachment aData = annot.Data as IPXC_AnnotData_FileAttachment; aData.Contents = "FileAttachment Annotation 1."; string sFilePath = System.Environment.CurrentDirectory + "\\Documents\\Hobbit.txt"; IPXC_FileSpec fileSpec = Parent.m_CurDoc.CreateEmbeddFile(sFilePath); IPXC_EmbeddedFileStream EFS = fileSpec.EmbeddedFile; EFS.UpdateFromFile2(sFilePath); aData.FileAttachment = fileSpec; annot.Data = aData; Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations | (int)Form1.eFormUpdateFlags.efuf_Attachments); }
static public int ConvertFromTXT(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rc = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_UndoRedoData urData; IPXC_ContentCreator CC = Parent.m_CurDoc.CreateContentCreator(); IPXC_Page page = pages.InsertPage(0, ref rc, out urData); DrawTextCallbacks drawTextCallbacks = new DrawTextCallbacks(); drawTextCallbacks.m_currPage = page; drawTextCallbacks.m_Text = File.ReadAllText(Environment.CurrentDirectory + "\\Documents\\Hobbit.txt"); IPXC_Font font = Parent.m_CurDoc.CreateNewFont("Times New Roman", 0, 400); CC.SetColorRGB(0x00000000); CC.SetFont(font); CC.SetFontSize(15); PXC_Rect rect = new PXC_Rect(); rect.top = rc.top - 40; rect.right = rc.right - 40; rect.bottom = rc.bottom + 40; rect.left = rc.left + 40; CC.ShowTextBlock(drawTextCallbacks.m_Text, rect, rect, (uint)PXC_DrawTextFlags.DTF_Center, -1, null, null, drawTextCallbacks, out rect); Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_All); }
public void OnGetNewRect(IPXC_ContentCreator pCC, out PXC_Rect pRect, ref uint pFlags, out PXC_Rect pClip) { m_currPage.PlaceContent(pCC.Detach(), (uint)PXC_PlaceContentFlags.PlaceContent_Replace); PXC_Rect rc = m_currPage.get_Box(PXC_BoxType.PBox_PageBox); IPXC_UndoRedoData urData; m_currPage.Document.CreateContentCreator(); IPXC_Pages pages = m_currPage.Document.Pages; IPXC_Page page = pages.InsertPage(m_currPage.Number + 1, ref rc, out urData); Marshal.ReleaseComObject(m_currPage); m_currPage = page; PXC_Rect rect = new PXC_Rect(); rect.top = rc.top - 40; rect.right = rc.right - 40; rect.bottom = rc.bottom + 40; rect.left = rc.left + 40; pRect = rect; pClip = rect; Marshal.ReleaseComObject(pages); }
static public int AddRedactAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); IPXC_ContentCreator CC = Parent.m_CurDoc.CreateContentCreator(); double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 4.0 * 3.0; IPXC_Font font = Parent.m_CurDoc.CreateNewFont("Arial", (uint)PXC_CreateFontFlags.CreateFont_Monospaced, 700); CC.SetFontSize(30); CC.SetFont(font); CC.SetColorRGB(0x00000000); for (int i = 0; i < 4; i++) { CC.ShowTextLine(nCX - 190, nCY - (40 * i), "This is a story of long ago.", -1, (uint)PXC_ShowTextLineFlags.STLF_Default | (uint)PXC_ShowTextLineFlags.STLF_AllowSubstitution); } page.PlaceContent(CC.Detach(), (uint)PXC_PlaceContentFlags.PlaceContent_Replace); IPXC_PageText Text = page.GetText(null, false); PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 150; rcOut.bottom = nCY - 100; rcOut.right = nCX + 150; rcOut.top = nCY + 100; //Getting Redact annotation atom for the InsertNewAnnot method uint nText = pxsInst.StrToAtom("Redact"); IPXC_Annotation annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); IPXC_AnnotData_Redaction aData = annot.Data as IPXC_AnnotData_Redaction; aData.Title = "Redact annotation 1."; IPXC_QuadsF quadsF = Parent.m_pxcInst.CreateQuads(); uint afafaf = quadsF.Count; PXC_RectF rectF = new PXC_RectF(); Text.GetTextQuads3(8, 75, quadsF, out rectF); aData.Quads = quadsF; var color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.0f, 0.0f, 0.0f); aData.FColor = color; aData.SColor = color; annot.Data = aData; Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public void AddImageFormFields(Form1 Parent) { int index = 1; //delegate string CheckNamesFields(IPXC_Document Doc, string fieldName, ref int x); CheckNamesFields checkNamesFields = (IPXC_Document Doc, string fName, ref int inx) => { string sFieldName = ""; uint i = 0; do { sFieldName = fName + inx; IPXC_FormField ff = Doc.AcroForm.GetFieldByName(sFieldName); if (ff == null) { break; } inx++; i++; }while (i <= Doc.AcroForm.FieldsCount); inx++; return(sFieldName); }; if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } PXC_Rect rc = new PXC_Rect(); rc.top = 800; rc.right = 600; //Adding button with icon as Image IPXC_UndoRedoData urD = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page Page = pages.InsertPage(0, rc, out urD); PXC_Rect rcPB = new PXC_Rect(); rcPB.left = 1.5 * 72.0; rcPB.right = rcPB.left + 1.0 * 72.0; rcPB.top = rc.top - 1.5 * 72.0; rcPB.bottom = rcPB.top - 2.0 * 72.0; //top is greater then bottom (PDF Coordinate System) IPXC_FormField Image = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Image", ref index), PXC_FormFieldType.FFT_PushButton, 0, ref rcPB); //Now we'll need to add the icon IPXC_Annotation annot = Image.Widget[0]; IPXC_AnnotData_Widget WData = (IPXC_AnnotData_Widget)annot.Data; string sPath = System.Environment.CurrentDirectory + "\\Images\\Editor_welcome.png"; IPXC_Image img = Parent.m_CurDoc.AddImageFromFile(sPath); float imgw = img.Width; float imgh = img.Height; IPXC_ContentCreator CC = Parent.m_CurDoc.CreateContentCreator(); CC.SaveState(); CC.ScaleCS(imgw, imgh); //the image will be scaled to the button's size CC.PlaceImage(img); CC.RestoreState(); IPXC_Content content = CC.Detach(); PXC_Rect rcBBox; rcBBox.left = 0; rcBBox.top = imgh; rcBBox.right = imgw; rcBBox.bottom = 0; content.set_BBox(rcBBox); IPXC_XForm xForm = Parent.m_CurDoc.CreateNewXForm(ref rcPB); xForm.SetContent(content); WData.ButtonTextPosition = PXC_WidgetButtonTextPosition.WidgetText_IconOnly; WData.SetIcon(PXC_AnnotAppType.AAT_Normal, xForm, true); annot.Data = WData; Marshal.ReleaseComObject(Image); Marshal.ReleaseComObject(Page); Marshal.ReleaseComObject(pages); }
static public int AddPolygonAndPolylineAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); //Getting Polygon and Polyline annotations atom for the InsertNewAnnot method string sPolygon = "Polygon"; string sPolyline = "PolyLine"; uint nText = pxsInst.StrToAtom(sPolygon); for (int p = 0; p < 2; p++) { double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 2.0; PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 150; rcOut.bottom = nCY + 200; rcOut.right = nCX + 150; rcOut.top = nCY + 300; if (p > 0) { nText = pxsInst.StrToAtom(sPolyline); rcOut.bottom = nCY - 200; rcOut.top = nCY - 100; } IPXC_Annotation annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); IPXC_AnnotData_Poly aData = annot.Data as IPXC_AnnotData_Poly; aData.Title = (p == 0) ? sPolygon : sPolyline; aData.Title += " annotation 1."; IPXC_PolygonSrcF poly = aData.Vertices; double r = 1.5 * 72.0; double a = -90.0; poly.Clear(); for (int i = 0; i < 4 + p; i++) { PXC_PointF pointF = new PXC_PointF(); pointF.x = (float)(rcOut.left + r * Math.Cos(a * Math.PI / 180.0)); pointF.y = (float)(rcOut.bottom - r * Math.Sin(a * Math.PI / 180.0)); a += 360.0 / 4; poly.Insert(ref pointF, 1, uint.MaxValue); } aData.Vertices = poly; IColor color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.5f, 0.2f, 0.2f); aData.FColor = color; color.SetRGB(0.0f, 0.0f, 0.0f); aData.SColor = color; annot.Data = aData; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Poly; aData.Title = (p == 0) ? sPolygon : sPolyline; aData.Title += " annotation 2."; poly = aData.Vertices; poly.Clear(); for (int i = 0; i < 6 + p; i++) { PXC_PointF pointF = new PXC_PointF(); pointF.x = (float)(nCX + r * Math.Cos(a * Math.PI / 180.0)); pointF.y = (float)(rcOut.bottom - r * Math.Sin(a * Math.PI / 180.0)); a += 360.0 / 6; poly.Insert(ref pointF, 1, uint.MaxValue); } aData.Vertices = poly; color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.2f, 0.5f, 0.2f); aData.FColor = color; color.SetRGB(0.0f, 0.0f, 0.0f); aData.SColor = color; PXC_AnnotBorder border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Solid; border.nWidth = 5.0f; aData.set_Border(border); aData.BlendMode = PXC_BlendMode.BlendMode_Multiply; annot.Data = aData; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Poly; aData.Title = (p == 0) ? sPolygon : sPolyline; aData.Title += " annotation 3."; poly = aData.Vertices; poly.Clear(); for (int i = 0; i < 8 + p; i++) { PXC_PointF pointF = new PXC_PointF(); pointF.x = (float)(rcOut.right + r * Math.Cos(a * Math.PI / 180.0)); pointF.y = (float)(rcOut.bottom - r * Math.Sin(a * Math.PI / 180.0)); a += 360.0 / 8; poly.Insert(ref pointF, 1, uint.MaxValue); } aData.Vertices = poly; color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.2f, 0.2f, 0.5f); aData.FColor = color; color.SetRGB(0.0f, 0.0f, 0.0f); aData.SColor = color; border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Dashed; border.nWidth = 3.0f; border.DashArray = new float[] { 10f, 8f, 6f, 4f, 2f, 2f, 4f, 6f, 8f, 10f }; //Width of dashes border.nDashCount = 4; //Number of dashes aData.set_Border(border); aData.BlendMode = PXC_BlendMode.BlendMode_Multiply; annot.Data = aData; } Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public int AddLinkAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); //Getting Link annotation atom for the InsertNewAnnot method uint nText = pxsInst.StrToAtom("Link"); double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 2.0; PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 200; rcOut.bottom = nCY + 250; rcOut.right = nCX + 150; rcOut.top = nCY + 300; IPXC_Annotation annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); IPXC_AnnotData_Link aData = annot.Data as IPXC_AnnotData_Link; aData.Contents = "Link Annotation 1."; aData.HighlighMode = PXC_AnnotHighlightMode.AHM_Outline; var color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.0f, 0.8f, 0.8f); aData.Color = color; //Setting dashed border pattern var border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Dashed; border.nWidth = 4.0f; border.DashArray = new float[10]; border.DashArray[0] = border.DashArray[1] = 16.0f; //Width of dashes border.nDashCount = 2; //Number of dashes aData.set_Border(border); //Setting the annotation's URI action IPXC_ActionsList AL = Parent.m_CurDoc.CreateActionsList(); AL.AddURI("https://www.google.com"); annot.set_Actions(PXC_TriggerType.Trigger_Up, AL); annot.Data = aData; rcOut.bottom -= 200; rcOut.top -= 200; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Link; aData.Contents = "Link Annotation 2."; color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.5f, 0.4f, 0.48f); aData.Color = color; //Setting the annotation's Goto action PXC_Destination dest = new PXC_Destination(); dest.nPageNum = page.Number + 1; dest.nType = PXC_DestType.Dest_XYZ; dest.nNullFlags = 15; AL = Parent.m_CurDoc.CreateActionsList(); AL.AddGoto(dest); annot.set_Actions(PXC_TriggerType.Trigger_Up, AL); annot.Data = aData; Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public int AddSquareAndCircleAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); //Getting Square and Circle annotations atom for the InsertNewAnnot method uint nSquare = pxsInst.StrToAtom("Square"); uint nCircle = pxsInst.StrToAtom("Circle"); double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 2.0; PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 200; rcOut.bottom = nCY + 200; rcOut.right = nCX + 200; rcOut.top = nCY + 300; IPXC_Annotation annot = unchecked (page.InsertNewAnnot(nSquare, ref rcOut)); IPXC_AnnotData_SquareCircle aData = annot.Data as IPXC_AnnotData_SquareCircle; aData.Title = "Square annotation 1."; annot.Data = aData; rcOut.bottom -= 150; rcOut.top -= 150; annot = unchecked (page.InsertNewAnnot(nSquare, ref rcOut)); aData = annot.Data as IPXC_AnnotData_SquareCircle; aData.Title = "Square annotation 2."; IColor color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.0f, 0.0f, 0.0f); aData.SColor = color; color.SetRGB(0.15f, 0.5f, 0.12f); aData.FColor = color; annot.Data = aData; rcOut.bottom -= 150; rcOut.top -= 150; annot = unchecked (page.InsertNewAnnot(nCircle, ref rcOut)); aData = annot.Data as IPXC_AnnotData_SquareCircle; aData.Title = "Circle annotation 3."; color.SetRGB(0.0f, 0.0f, 0.0f); aData.SColor = color; color.SetRGB(0.5f, 0.5f, 0.5f); aData.FColor = color; //Setting dashed border pattern PXC_AnnotBorder border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Dashed; border.nWidth = 4.0f; border.DashArray = new float[] { 10f, 8f, 6f, 4f, 2f, 2f, 4f, 6f, 8f, 10f }; //Width of dashes border.nDashCount = 4; //Number of dashes aData.set_Border(border); annot.Data = aData; rcOut.bottom -= 150; rcOut.top -= 150; annot = unchecked (page.InsertNewAnnot(nCircle, ref rcOut)); aData = annot.Data as IPXC_AnnotData_SquareCircle; aData.Title = "Circle annotation 4."; color.SetRGB(0.0f, 0.0f, 0.0f); aData.SColor = color; color.SetRGB(0.5f, 0.5f, 0.5f); aData.FColor = color; //Setting dashed border pattern border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Solid; border.nWidth = 5.0f; aData.set_Border(border); annot.Data = aData; Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public int AddLineAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); //Getting Line annotation atom for the InsertNewAnnot method uint nText = pxsInst.StrToAtom("Line"); double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 2.0; PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 200; rcOut.bottom = nCY + 200; rcOut.right = nCX + 200; rcOut.top = nCY + 300; PXC_Point startPoint = new PXC_Point(); startPoint.x = rcPage.left + 50; startPoint.y = rcPage.top - 50; PXC_Point endPiont = new PXC_Point(); endPiont.x = rcPage.right - 50; endPiont.y = startPoint.y; IPXC_Annotation annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); IPXC_AnnotData_Line aData = annot.Data as IPXC_AnnotData_Line; aData.Title = "Line annotation 1."; var color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.0f, 0.0f, 0.0f); aData.Color = color; aData.SetLinePoints(ref startPoint, ref endPiont); PXC_AnnotBorder border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Solid; border.nWidth = 3.0f; aData.set_Border(border); annot.Data = aData; startPoint.y = startPoint.y - 50; endPiont.y = startPoint.y; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Line; aData.SetLinePoints(ref startPoint, ref endPiont); aData.Title = "Line annotation 2."; aData.Color = color; aData.SetLineEndings(PXC_AnnotLineEndingStyle.LE_None, PXC_AnnotLineEndingStyle.LE_OpenArrow); aData.set_Border(border); annot.Data = aData; startPoint.y = startPoint.y - 50; endPiont.y = startPoint.y; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Line; aData.SetLinePoints(ref startPoint, ref endPiont); aData.Title = "Line annotation 3."; aData.Color = color; aData.FColor = color; aData.SetLineEndings(PXC_AnnotLineEndingStyle.LE_ClosedArrow, PXC_AnnotLineEndingStyle.LE_ClosedArrow); aData.set_Border(border); annot.Data = aData; startPoint.y = startPoint.y - 50; endPiont.y = startPoint.y; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Line; aData.SetLinePoints(ref startPoint, ref endPiont); aData.Title = "Line annotation 4."; aData.Color = color; aData.FColor = color; aData.SetLineEndings(PXC_AnnotLineEndingStyle.LE_Circle, PXC_AnnotLineEndingStyle.LE_None); aData.set_Border(border); annot.Data = aData; startPoint.y = startPoint.y - 50; endPiont.y = startPoint.y; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Line; aData.SetLinePoints(ref startPoint, ref endPiont); aData.Title = "Line annotation 5."; aData.ShowCaption = true; aData.CaptionInLine = true; PXC_Size size; size.cx = 0; size.cy = 10; aData.set_CaptionOffset(ref size); aData.Contents = "Line annotation 5."; aData.Color = color; annot.Data = aData; startPoint.y = startPoint.y - 50; endPiont.y = startPoint.y; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_Line; aData.SetLinePoints(ref startPoint, ref endPiont); aData.Title = "Line annotation 6."; aData.Color = color; aData.FColor = color; aData.LeaderLine = 15.0; aData.LeaderLineExtension = 15.0; aData.set_Border(border); annot.Data = aData; Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public int AddFreeTextAnnotation(Form1 Parent) { if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } IPXC_UndoRedoData urData = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages[0]; PXC_Rect rcPage = firstPage.get_Box(PXC_BoxType.PBox_PageBox); Marshal.ReleaseComObject(firstPage); IPXC_Page page = pages.InsertPage(0, ref rcPage, out urData); IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); //Getting Free text annotation atom for the InsertNewAnnot method uint nText = pxsInst.StrToAtom("FreeText"); double nCX = (rcPage.right - rcPage.left) / 2.0; double nCY = (rcPage.top - rcPage.bottom) / 2.0; PXC_Rect rcOut = new PXC_Rect(); rcOut.left = nCX - 200; rcOut.bottom = nCY + 200; rcOut.right = nCX + 200; rcOut.top = nCY + 300; IPXC_Annotation annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); IPXC_AnnotData_FreeText aData = annot.Data as IPXC_AnnotData_FreeText; aData.Contents = "Free Text Annotation 1."; aData.Title = "Free Text Annotation 1."; IPXC_Font font = Parent.m_CurDoc.CreateNewFont("Arial", (uint)PXC_CreateFontFlags.CreateFont_Monospaced, 700); aData.DefaultFont = font; aData.DefaultFontSize = 40; var color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.7f, 0.7f, 0.7f); aData.DefaultTextColor = color; aData.Opacity = 0.5; aData.TextRotation = 90; aData.Subject = "Typewriter"; //Setting dashed border pattern var border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Beveled; border.nWidth = 4.0f; border.DashArray = new float[15]; border.DashArray[0] = border.DashArray[1] = 5.0f; //Width of dashes border.nDashCount = 2; //Number of dashes aData.set_Border(border); annot.Data = aData; rcOut.bottom -= 200; rcOut.top -= 200; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_FreeText; aData.Contents = "Free Text Annotation 2."; aData.DefaultFontSize = 15.0; color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.0f, 0.0f, 0.0f); aData.SColor = color; aData.DefaultTextColor = color; //Setting dashed border pattern border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Dashed; border.nWidth = 10.0f; border.DashArray = new float[20]; border.DashArray[0] = border.DashArray[1] = 5.0f; //Width of dashes border.nDashCount = 4; //Number of dashes aData.set_Border(border); annot.Data = aData; rcOut.bottom -= 200; rcOut.top -= 200; annot = unchecked (page.InsertNewAnnot(nText, ref rcOut)); aData = annot.Data as IPXC_AnnotData_FreeText; aData.Contents = "Free Text Annotation 3."; color = auxInst.CreateColor(ColorType.ColorType_RGB); aData.DefaultFontSize = 15.0; color.SetRGB(1.0f, 1.0f, 1.0f); aData.SColor = color; color.SetRGB(0.0f, 0.0f, 0.0f); aData.DefaultTextColor = color; annot.Data = aData; Marshal.ReleaseComObject(page); Marshal.ReleaseComObject(pages); return((int)Form1.eFormUpdateFlags.efuf_Annotations); }
static public void AddButtonWithIconAndURI(Form1 Parent) { int index = 1; //delegate string CheckNamesFields(IPXC_Document Doc, string fieldName, ref int x); CheckNamesFields checkNamesFields = (IPXC_Document Doc, string fName, ref int inx) => { string sFieldName = ""; uint i = 0; do { sFieldName = fName + inx; IPXC_FormField ff = Doc.AcroForm.GetFieldByName(sFieldName); if (ff == null) { break; } inx++; i++; }while (i <= Doc.AcroForm.FieldsCount); inx++; return(sFieldName); }; if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } PXC_Rect rc = new PXC_Rect(); rc.top = 800; rc.right = 600; //Adding button with icon with the URI action IPXC_UndoRedoData urD = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page Page = pages.InsertPage(0, rc, out urD); PXC_Rect rcPB = new PXC_Rect(); rcPB.left = 1.5 * 72.0; rcPB.right = rcPB.left + 0.5 * 72.0; rcPB.top = rc.top - 0.14 * 72.0; rcPB.bottom = rcPB.top - 0.5 * 72.0; //top is greater then bottom (PDF Coordinate System) IPXC_FormField googleButton = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Button", ref index), PXC_FormFieldType.FFT_PushButton, 0, ref rcPB); //Now we'll need to add the icon IPXC_Annotation annot = googleButton.Widget[0]; IPXC_AnnotData_Widget WData = (IPXC_AnnotData_Widget)annot.Data; string sPath = System.Environment.CurrentDirectory + "\\Images\\gotoSource_24.png"; IPXC_Image img = Parent.m_CurDoc.AddImageFromFile(sPath); float imgw = img.Width; float imgh = img.Height; IPXC_ContentCreator CC = Parent.m_CurDoc.CreateContentCreator(); CC.SaveState(); CC.ScaleCS(imgw, imgh); //the image will be scaled to the button's size CC.PlaceImage(img); CC.RestoreState(); IPXC_Content content = CC.Detach(); PXC_Rect rcBBox; rcBBox.left = 0; rcBBox.top = imgh; rcBBox.right = imgw; rcBBox.bottom = 0; content.set_BBox(rcBBox); IPXC_XForm xForm = Parent.m_CurDoc.CreateNewXForm(ref rcPB); xForm.SetContent(content); WData.ButtonTextPosition = PXC_WidgetButtonTextPosition.WidgetText_IconOnly; WData.SetIcon(PXC_AnnotAppType.AAT_Normal, xForm, true); WData.Contents = "http://www.google.com"; //tooltip annot.Data = WData; //Setting the annotation's URI action IPXC_ActionsList AL = Parent.m_CurDoc.CreateActionsList(); AL.AddURI("https://www.google.com"); annot.set_Actions(PXC_TriggerType.Trigger_Up, AL); Marshal.ReleaseComObject(googleButton); //Adding button with icon and label and JS that goes to next page rcPB.left += 1.2 * 72.0; rcPB.right = rcPB.left + 0.6 * 72.0; IPXC_FormField nextButton = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Button", ref index), PXC_FormFieldType.FFT_PushButton, 0, ref rcPB); //Now we'll need to add the icon annot = nextButton.Widget[0]; WData = (IPXC_AnnotData_Widget)annot.Data; sPath = System.Environment.CurrentDirectory + "\\Images\\next_24.png"; img = Parent.m_CurDoc.AddImageFromFile(sPath); imgw = img.Width; imgh = img.Height; CC.SaveState(); CC.ScaleCS(imgw, imgh); //the image will be scaled to the button's size CC.PlaceImage(img); CC.RestoreState(); content = CC.Detach(); rcBBox.left = 0; rcBBox.top = imgh; rcBBox.right = imgw; rcBBox.bottom = 0; content.set_BBox(rcBBox); xForm = Parent.m_CurDoc.CreateNewXForm(ref rcPB); xForm.SetContent(content); WData.SetCaption(PXC_AnnotAppType.AAT_Normal, "Next Page"); WData.ButtonTextPosition = PXC_WidgetButtonTextPosition.WidgetText_IconTextV; PXC_Point p = new PXC_Point(); p.x = 0.5; p.y = 0.5; WData.set_IconOffset(p); WData.SetIcon(PXC_AnnotAppType.AAT_Normal, xForm, true); WData.Contents = "Next Page"; //tooltip annot.Data = WData; //Setting the annotation's Goto action PXC_Destination dest = new PXC_Destination(); dest.nPageNum = Page.Number + 1; dest.nType = PXC_DestType.Dest_XYZ; dest.nNullFlags = 15; AL = Parent.m_CurDoc.CreateActionsList(); AL.AddGoto(dest); annot.set_Actions(PXC_TriggerType.Trigger_Up, AL); Marshal.ReleaseComObject(nextButton); //Adding text button that opens the file rcPB.left += 1.5 * 72.0; rcPB.right = rcPB.left + 2.0 * 72.0; IPXC_FormField openButton = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Button", ref index), PXC_FormFieldType.FFT_PushButton, 0, ref rcPB); //Now we'll need to add the icon annot = openButton.Widget[0]; WData = (IPXC_AnnotData_Widget)annot.Data; WData.ButtonTextPosition = PXC_WidgetButtonTextPosition.WidgetText_TextOnly; WData.SetCaption(PXC_AnnotAppType.AAT_Normal, "Open File"); WData.Contents = "Open File"; //tooltip annot.Data = WData; //Setting the annotation's Launch action AL = Parent.m_CurDoc.CreateActionsList(); sPath = System.Environment.CurrentDirectory + "\\Documents\\FeatureChartEU.pdf"; AL.AddLaunch(sPath); annot.set_Actions(PXC_TriggerType.Trigger_Up, AL); Marshal.ReleaseComObject(openButton); Marshal.ReleaseComObject(Page); Marshal.ReleaseComObject(pages); }
static public void AddTextFieldsOnPage(Form1 Parent) { int index = 1; //delegate string CheckNamesFields(IPXC_Document Doc, string fieldName, ref int x); CheckNamesFields checkNamesFields = (IPXC_Document Doc, string fName, ref int inx) => { string sFieldName = ""; uint i = 0; do { sFieldName = fName + inx; IPXC_FormField ff = Doc.AcroForm.GetFieldByName(sFieldName); if (ff == null) { break; } inx++; i++; }while (i <= Doc.AcroForm.FieldsCount); inx++; return(sFieldName); }; if (Parent.m_CurDoc == null) { Document.CreateNewDoc(Parent); } PXC_Rect rc = new PXC_Rect(); rc.top = 800; rc.right = 600; IPXC_UndoRedoData urD = null; IPXC_Pages pages = Parent.m_CurDoc.Pages; IPXC_Page firstPage = pages.InsertPage(0, rc, out urD); PXC_Rect textRC = new PXC_Rect(); textRC.top = rc.top - 1.0 * 72.0; textRC.left = 1.0 * 72.0; textRC.bottom = rc.top - 2.0 * 72.0; textRC.right = rc.right - 1.0 * 72.0; //Ordinary text field IPXC_FormField firstTextBOX = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Text", ref index), PXC_FormFieldType.FFT_Text, 0, textRC); firstTextBOX.SetValueText("Ordinary text field"); Marshal.ReleaseComObject(firstTextBOX); //Read-only and locked text field with custom style textRC.top = rc.top - 3.0 * 72.0; textRC.bottom = rc.top - 4.0 * 72.0; IPXC_FormField secondTextBOX = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Text", ref index), PXC_FormFieldType.FFT_Text, 0, textRC); secondTextBOX.SetValueText("Read-only and locked text field with custom style"); IAUX_Inst auxInst = Parent.m_pxcInst.GetExtension("AUX"); IPXC_Annotation annot = secondTextBOX.Widget[0]; IPXC_AnnotData_Widget WData = (IPXC_AnnotData_Widget)annot.Data; IColor color = auxInst.CreateColor(ColorType.ColorType_RGB); color.SetRGB(0.9f, 0.9f, 0.6f); WData.FColor = color; color.SetRGB(0.6f, 0.9f, 0.9f); WData.SColor = color; PXC_AnnotBorder border = new PXC_AnnotBorder(); border.nStyle = PXC_AnnotBorderStyle.ABS_Dashed; border.DashArray = new float[10]; border.DashArray[0] = border.DashArray[1] = 16.0f; //Width of dashes border.nDashCount = 2; //Number of dashes border.nWidth = 5.0f; WData.set_Border(ref border); annot.Data = WData; secondTextBOX.SetFlags((uint)PXC_FormFieldFlag.FFF_ReadOnly, (uint)PXC_FormFieldFlag.FFF_ReadOnly); Marshal.ReleaseComObject(secondTextBOX); //90 degree orientation text field with multiline option enabled textRC.top = rc.top - 5.0 * 72.0; textRC.bottom = rc.top - 7.0 * 72.0; IPXC_FormField thirdTextBOX = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Text", ref index), PXC_FormFieldType.FFT_Text, 0, textRC); thirdTextBOX.SetFlags((uint)PXC_FormFieldFlag.TFF_MultiLine, (uint)PXC_FormFieldFlag.TFF_MultiLine); thirdTextBOX.SetValueText("90 degree orientation text field with multiline option enabled"); annot = thirdTextBOX.Widget[0]; WData = (IPXC_AnnotData_Widget)annot.Data; WData.ContentRotation = 90; annot.Data = WData; Marshal.ReleaseComObject(thirdTextBOX); //Time formatted text field with custom JS that gives current time textRC.top = rc.top - 8.0 * 72.0; textRC.bottom = rc.top - 9.0 * 72.0; IPXC_FormField fourthTextBOX = Parent.m_CurDoc.AcroForm.CreateField(checkNamesFields(Parent.m_CurDoc, "Text", ref index), PXC_FormFieldType.FFT_Text, 0, textRC); annot = fourthTextBOX.Widget[0]; annot.Flags |= (uint)PXC_SignDocumentFlags.Sign_TX_Date; IPXC_ActionsList actionsList = Parent.m_CurDoc.CreateActionsList(); //Set script to ActionList actionsList.AddJavaScript("var now = new Date()\n" + "this.getField(\"Text4\").value = now.getHours() + \":\" + now.getMinutes() "); fourthTextBOX.Actions[PXC_TriggerType.Trigger_Format] = actionsList; Marshal.ReleaseComObject(fourthTextBOX); Marshal.ReleaseComObject(firstPage); Marshal.ReleaseComObject(pages); }