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 SortBookmarksByPage(Form1 Parent)
        {
            //delegate double[] GetXYFromDestination(IPXC_Bookmark bookmark, PXC_Destination dest);
            GetXYFromDestination getXYFromDestination = (IPXC_Document doc, PXC_Destination destination) => {
                PXC_DestType Type          = destination.nType;
                PXC_Point    retValue      = new PXC_Point();
                IPXC_Pages   pages         = doc.Pages;
                IPXC_Page    page          = pages[destination.nPageNum];
                PXC_Rect     contentBBox   = page.get_Box(PXC_BoxType.PBox_BBox);
                PXC_Rect     pageBBox      = page.get_Box(PXC_BoxType.PBox_PageBox);
                bool         IsContentType = (Type == PXC_DestType.Dest_FitB) || (Type == PXC_DestType.Dest_FitBH) || (Type == PXC_DestType.Dest_FitBV);
                retValue.x = IsContentType ? contentBBox.left : pageBBox.left;
                retValue.y = IsContentType ? contentBBox.top : pageBBox.top;
                switch (Type)
                {
                case PXC_DestType.Dest_XYZ:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitH:
                {
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitV:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitR:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    if ((destination.nNullFlags & 8) == 0)
                    {
                        retValue.y = destination.dValues[3];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitBH:
                {
                    if ((destination.nNullFlags & 2) == 0)
                    {
                        retValue.y = destination.dValues[1];
                    }
                    break;
                }

                case PXC_DestType.Dest_FitBV:
                {
                    if ((destination.nNullFlags & 1) == 0)
                    {
                        retValue.x = destination.dValues[0];
                    }
                    break;
                }

                default:
                    break;
                }
                Marshal.ReleaseComObject(page);
                Marshal.ReleaseComObject(pages);
                return(retValue);
            };
            //delegate void SortByAnything(SortByAnything sort, IPXC_Bookmark root);
            SortByAnything sortByAnything = (sort, root, actionType) => {
                List <Tuple <IPXC_Bookmark, PXC_Destination> > bookmarks = new List <Tuple <IPXC_Bookmark, PXC_Destination> >();
                int             MAX_VALUE   = int.MaxValue;
                PXC_Destination invalidDest = new PXC_Destination();
                invalidDest.nPageNum = (uint)MAX_VALUE;

                while (root.ChildrenCount > 0)
                {
                    Tuple <IPXC_Bookmark, PXC_Destination> currentBookmark = Tuple.Create(root.FirstChild, invalidDest);
                    if (root.FirstChild.Actions != null)
                    {
                        for (int i = (int)root.FirstChild.Actions.Count - 1; i >= 0; i--)
                        {
                            if (root.FirstChild.Actions[(uint)i].Type == actionType)
                            {
                                IPXC_Action_Goto actionGoTo = root.FirstChild.Actions[(uint)i] as IPXC_Action_Goto;
                                PXC_Destination  currDest   = actionGoTo.IsNamedDest
                                                                        ? Parent.m_CurDoc.GetNamedDestination(actionGoTo.DestName)
                                                                        : actionGoTo.get_Dest();
                                currentBookmark = Tuple.Create(root.FirstChild, currDest);
                                break;
                            }
                        }
                    }
                    root.FirstChild.Unlink();

                    if ((bookmarks.Count == 0) || (currentBookmark.Item2.nPageNum > bookmarks[bookmarks.Count - 1].Item2.nPageNum))
                    {
                        bookmarks.Add(currentBookmark);
                        continue;
                    }
                    else if (currentBookmark.Item2.nPageNum < bookmarks[0].Item2.nPageNum)
                    {
                        bookmarks.Insert(0, currentBookmark);
                        continue;
                    }

                    int first = 0;
                    int last  = bookmarks.Count;

                    while (first < last)
                    {
                        int mid = first + (last - first) / 2;
                        if (currentBookmark.Item2.nPageNum == bookmarks[mid].Item2.nPageNum)
                        {
                            if ((MAX_VALUE == currentBookmark.Item2.nPageNum) && (MAX_VALUE == bookmarks[mid].Item2.nPageNum))
                            {
                                if (Form1.NativeMethods.StrCmpLogicalW(currentBookmark.Item1.Title, bookmarks[mid].Item1.Title) == 1)
                                {
                                    first = mid + 1;
                                }
                                else
                                {
                                    last = mid;
                                }
                            }
                            else
                            {
                                PXC_Point currentBookmarkXY   = getXYFromDestination(Parent.m_CurDoc, currentBookmark.Item2);
                                PXC_Point bookmarkXY_FromList = getXYFromDestination(Parent.m_CurDoc, bookmarks[mid].Item2);
                                if (currentBookmarkXY.y < bookmarkXY_FromList.y)
                                {
                                    first = mid + 1;
                                }
                                else if (currentBookmarkXY.y > bookmarkXY_FromList.y)
                                {
                                    last = mid;
                                }
                                else
                                {
                                    if (currentBookmarkXY.x < bookmarkXY_FromList.x)
                                    {
                                        last = mid;
                                    }
                                    else
                                    {
                                        first = mid + 1;
                                    }
                                }
                            }
                        }
                        else if (currentBookmark.Item2.nPageNum < bookmarks[mid].Item2.nPageNum)
                        {
                            last = mid;
                        }
                        else
                        {
                            first = mid + 1;
                        }
                    }
                    bookmarks.Insert(last, currentBookmark);
                }

                foreach (Tuple <IPXC_Bookmark, PXC_Destination> bookmark in bookmarks)
                {
                    root.AddChild(bookmark.Item1, true);
                    if (bookmark.Item1.ChildrenCount > 0)
                    {
                        sort(sort, bookmark.Item1, actionType);
                    }
                }
            };

            if (Parent.m_CurDoc == null)
            {
                return(0);
            }

            IPXS_Inst pxsInst = Parent.m_pxcInst.GetExtension("PXS") as IPXS_Inst;
            uint      nGoTo   = pxsInst.StrToAtom("GoTo");

            sortByAnything(sortByAnything, Parent.m_CurDoc.BookmarkRoot, nGoTo);
            return((int)Form1.eFormUpdateFlags.efuf_Bookmarks);
        }
Beispiel #3
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);
        }