Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        static public void ConvertToImage(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.OpenDocFromStringPath(Parent);
            }

            IIXC_Inst  ixcInst = Parent.m_pxcInst.GetExtension("IXC");
            IAUX_Inst  auxInst = Parent.m_pxcInst.GetExtension("AUX");
            IPXC_Pages pages   = Parent.m_CurDoc.Pages;
            IPXC_Page  Page    = pages[Parent.CurrentPage];
            double     nHeight = 0.0;
            double     nWidth  = 0.0;

            Page.GetDimension(out nWidth, out nHeight);
            uint                  cx      = (uint)(nWidth * 150 / 72.0);
            uint                  cy      = (uint)(nHeight * 150 / 72.0);
            IIXC_Page             ixcPage = ixcInst.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8ARGB, 0);
            IPXC_PageRenderParams param   = Parent.m_pxcInst.CreateRenderParams();

            if (param != null)
            {
                param.RenderFlags |= ((uint)PXC_RenderFlags.RF_SmoothImages | (uint)PXC_RenderFlags.RF_SmoothLineArts);
                param.SetColor(PXC_RenderColor.RC_PageColor1, 255, 255, 255, 0);
                param.TextSmoothMode |= PXC_TextSmoothMode.TSM_Antialias;
            }
            tagRECT rc = new tagRECT();

            rc.right  = (int)cx;
            rc.bottom = (int)cy;
            PXC_Matrix matrix = Page.GetMatrix(PXC_BoxType.PBox_PageBox);

            matrix = auxInst.MathHelper.Matrix_Scale(ref matrix, cx / nWidth, -cy / nHeight);
            matrix = auxInst.MathHelper.Matrix_Translate(ref matrix, 0, cy);
            Page.DrawToIXCPage(ixcPage, ref rc, ref matrix, param);
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_XDPI]       = 150;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_YDPI]       = 150;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_INTERLACE]  = 1;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_FILTER]     = 5;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_COMP_LEVEL] = 5;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_FORMAT]     = (uint)IXC_ImageFileFormatIDs.FMT_PNG_ID;
            IIXC_Image ixcImg = ixcInst.CreateEmptyImage();

            ixcImg.InsertPage(ixcPage, 0);
            string sPath = Path.GetTempFileName();

            sPath = sPath.Replace(".tmp", ".png");
            ixcImg.Save(sPath, IXC_CreationDisposition.CreationDisposition_Overwrite);
            Process.Start(sPath);

            ixcImg.RemovePageByIndex(0);
            ixcPage = ixcInst.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8Gray, 0);
            if (param != null)
            {
                param.SetColor(PXC_RenderColor.RC_PageColor1, 255, 255, 255, 255);
            }
            Page.DrawToIXCPage(ixcPage, ref rc, ref matrix, param);
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_XDPI]         = 150;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_YDPI]         = 150;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_YSUBSAMPLING] = 20;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_FORMAT]       = (uint)IXC_ImageFileFormatIDs.FMT_JPEG_ID;
            ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_JPEG_QUALITY] = 100;
            ixcImg.InsertPage(ixcPage, 0);
            sPath = sPath.Replace(".png", ".jpg");
            ixcImg.Save(sPath, IXC_CreationDisposition.CreationDisposition_Overwrite);
            Process.Start(sPath);
            Marshal.ReleaseComObject(Page);

            ixcImg.RemovePageByIndex(0);
            ixcPage = ixcInst.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8RGB, 0);
            for (int i = 0; i < pages.Count; i++)
            {
                Page = pages[(uint)i];
                Page.DrawToIXCPage(ixcPage, ref rc, ref matrix, param);
                ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_XDPI]   = 150;
                ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_YDPI]   = 150;
                ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_ITYPE]  = 1;
                ixcPage.FmtInt[(uint)IXC_FormatParametersIDS.FP_ID_FORMAT] = (uint)IXC_ImageFileFormatIDs.FMT_TIFF_ID;
                ixcImg.InsertPage(ixcPage);
                ixcPage = ixcInst.Page_CreateEmpty(cx, cy, IXC_PageFormat.PageFormat_8Gray, 0);
                Marshal.ReleaseComObject(Page);
            }
            sPath = sPath.Replace(".jpg", ".tiff");
            ixcImg.Save(sPath, IXC_CreationDisposition.CreationDisposition_Overwrite);
            Process.Start(sPath);


            Marshal.ReleaseComObject(pages);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        static public void ConvertToTXT(Form1 Parent)
        {
            if (Parent.m_CurDoc == null)
            {
                Document.OpenDocFromStringPath(Parent);
            }

            IAUX_Inst     auxInst = Parent.m_pxcInst.GetExtension("AUX");
            IPXC_Pages    pages   = Parent.m_CurDoc.Pages;
            IPXC_Page     Page    = pages[Parent.CurrentPage];
            IPXC_PageText Text    = Page.GetText(null, false);

            string writePath = Path.GetTempFileName();

            writePath = writePath.Replace(".tmp", ".txt");
            StreamWriter stream = new StreamWriter(writePath);

            List <PXC_TextLineInfo> textsLineInfo = new List <PXC_TextLineInfo>();

            for (int i = 0; i < Text.LinesCount; i++)
            {
                PXC_TextLineInfo pxcTLI = Text.LineInfo[(uint)i];
                textsLineInfo.Add(pxcTLI);
            }

            textsLineInfo.Sort(delegate(PXC_TextLineInfo firstTLI, PXC_TextLineInfo secondTLI)
            {
                PXC_RectF rcFirst  = firstTLI.rcBBox;
                PXC_RectF rcSecond = secondTLI.rcBBox;
                auxInst.MathHelper.Rect_TransformDF(ref firstTLI.Matrix, ref rcFirst);
                auxInst.MathHelper.Rect_TransformDF(ref secondTLI.Matrix, ref rcSecond);
                if (rcFirst.top < rcSecond.top)
                {
                    return(1);
                }
                if (rcFirst.top > rcSecond.top)
                {
                    return(-1);
                }

                if (rcFirst.left < rcSecond.left)
                {
                    return(-1);
                }
                if (rcFirst.left > rcSecond.left)
                {
                    return(1);
                }

                return(0);
            });

            for (int i = 0; i < Text.LinesCount; i++)
            {
                stream.Write(Text.GetChars(textsLineInfo[i].nFirstCharIndex, textsLineInfo[i].nCharsCount));
                if (i < Text.LinesCount - 1)
                {
                    stream.Write((textsLineInfo[i].rcBBox.top == textsLineInfo[i + 1].rcBBox.top) ? " " : "\r\n");
                }
            }
            stream.Close();
            Process.Start(writePath);

            Marshal.ReleaseComObject(Page);
            Marshal.ReleaseComObject(pages);
        }
Ejemplo n.º 5
0
        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);
        }