コード例 #1
0
 /// <summary>
 /// Safely delete a bookmark
 /// </summary>
 /// <param name="bookmark">bookmark</param>
 /// <returns></returns>
 public bool DeleteBookmark(Bookmark bookmark)
 {
     if (bookmark != null)
     {
         bookmark.Delete();
     }
     return(false);
 }
コード例 #2
0
        public ActionResult Delete(int id)
        {
            var loggenInUser      = UsersTable.GetByfirstNameAndLastName(User.Identity.Name);
            var bookmarkForDelete = BookmarkTable.FindByUserIdAndAdId(loggenInUser.id, id);

            BookmarkTable.Delete(bookmarkForDelete.id);

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        /// <summary>
        /// Deletes a bookmark.
        /// </summary>
        /// <param name="bookmark">The bookmark to delete.</param>
        public void Delete(Bookmark bookmark)
        {
            if (bookmark == null)
            {
                throw new ArgumentNullException("bookmark");
            }

            this.bookmarkCache.Remove(bookmark.Name);
            bookmark.Delete();
        }
コード例 #4
0
 internal void DeleteExplanationId(int id)
 {
     try
     {
         Bookmark bm = Explanations.Bookmarks.Where(b => b.ID == id).First();
         if (bm != null)
         {
             bm.Delete();
             Save();
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.Message);
     }
 }
コード例 #5
0
        void ClearBookMarks(PDFDoc pdfDoc)
        {
            Bookmark firstBookMark = pdfDoc.GetFirstBookmark();

            while (firstBookMark != null)
            {
                if (firstBookMark.IsValid())
                {
                    firstBookMark.Delete();
                    firstBookMark = pdfDoc.GetFirstBookmark();
                }
                else
                {
                    firstBookMark = null;
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Changes or adds a bookmark in the document.
        /// </summary>
        /// <param name="name">The name of the bookmark to change.</param>
        /// <param name="range">The new range of the bookmark.</param>
        /// <returns>The new bookmark.</returns>
        public Bookmark ChangeOrAdd(string name, Range range)
        {
            Bookmark bookmark = null;
            this.bookmarkCache.TryGetValue(name, out bookmark);
            if (bookmark != null)
            {
                bookmark.Delete();
                bookmark = this.document.Bookmarks.Add(name, range);
                this.bookmarkCache[name] = bookmark;
            }
            else
            {
                bookmark = this.Add(name, range);
            }

            return bookmark;
        }
コード例 #7
0
ファイル: Form1.cs プロジェクト: leonchen09/poc
        private void button7_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
            wordApp.Visible = true;
            Document wDoc = wordApp.Documents.Open(@"e:\1.docx");
            Bookmark bm   = wDoc.Bookmarks[1];
            string   name = bm.Name;

            Microsoft.Office.Interop.Word.Range bmRange = bm.Range;

            bm.Range.InsertParagraphBefore();
            bmRange.Start = bmRange.Start + 1;
            bm.Delete();
            wDoc.Bookmarks.Add(name, bmRange);
            Microsoft.Office.Interop.Word.Range bmpRange = bm.Range.Paragraphs[1].Range;
            int count = bm.Range.Paragraphs.Count;
            //MessageBox.Show(bmRange.Text);
            //MessageBox.Show(bmpRange.Text);
        }
コード例 #8
0
        private void Delete()
        {
            try
            {
                if (grdVwBookmarks.SelectedRows.Count > 0)
                {
                    if (MessageUtil.Confirm("Bookmark will be deleted. Are you sure?") == System.Windows.Forms.DialogResult.Yes)
                    {
                        int      bkmrkId = grdVwBookmarks.SelectedRows[0].Cells["ID"].Value.ToInt();
                        Bookmark bkmrk   = null;
                        for (int bookmarkCounter = 0; bookmarkCounter < bookmarkList.Count; bookmarkCounter++)
                        {
                            if (bkmrkId == bookmarkList[bookmarkCounter].ID)
                            {
                                bkmrk = bookmarkList[bookmarkCounter];
                                break;
                            }
                        }

                        if (bkmrk != null)
                        {
                            bkmrk.Delete();
                            bookmarkList.Remove(bkmrk);
                            SetDataSourceOfGRid();
                            MessageUtil.Message("Bookmark deleted successfully.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LightLogger.LogMethod(ex, this.Name, "Delete");

                MessageUtil.Error("Object could not be deleted.");
            }
        }
コード例 #9
0
ファイル: RedactCommands.cs プロジェクト: res0o43m/Redaction
        /// <summary>
        /// Redact a range, replacing all marked text.
        /// </summary>
        /// <param name="range">A range to redact.</param>
        /// <param name="rangeData">A RangeDataEx containing properties about the range.</param>
        private void RedactRange(Word.Range range, RangeDataEx rangeData)
        {
            object ParagraphNumber = Word.WdNumberType.wdNumberParagraph;

            foreach (Word.Paragraph p in range.Paragraphs)
            {
                //get the para's range
                Word.Range ParagraphRange = p.Range;

                //trim to the selection, if needed
                if (range.Start > ParagraphRange.Start)
                {
                    ParagraphRange.Start = range.Start;
                }
                if (range.End < ParagraphRange.End)
                {
                    ParagraphRange.End = range.End;
                }
                if (ParagraphRange.End == p.Range.End - 1 && ParagraphRange.Start == p.Range.Start)
                {
                    p.Range.ListFormat.ConvertNumbersToText(ref ParagraphNumber); //if the whole para was redacted, redact the numbering
                }
                //make it black on black
                ParagraphRange.Font.Shading.BackgroundPatternColor = Word.WdColor.wdColorAutomatic;
                ParagraphRange.HighlightColorIndex = Word.WdColorIndex.wdBlack; //moving to highlighting instead of text background
                ParagraphRange.Font.Color          = Word.WdColor.wdColorBlack;

                //get rid of links and bookmarks
                foreach (Word.Hyperlink Hyperlink in ParagraphRange.Hyperlinks)
                {
                    Hyperlink.Delete();
                }
                foreach (Word.Bookmark Bookmark in ParagraphRange.Bookmarks)
                {
                    Bookmark.Delete();
                }

                //BUG 110: suppress proofing errors
                ParagraphRange.NoProofing = -1;

                //finally, replace the text
                Debug.Assert(ParagraphRange.ShapeRange.Count == 0, "Some Shapes were not redacted by RedactShapes.");
                if (ParagraphRange.InlineShapes.Count > 0)
                {
                    //if there are images, then split into subranges and process text and images separately
                    List <RangeData> Subranges = RedactCommon.SplitRange(ParagraphRange);

                    for (int j = Subranges.Count - 1; j >= 0; j--)
                    {
                        //set start and end
                        ParagraphRange.Start = Subranges[j].Start;
                        ParagraphRange.End   = Subranges[j].End;

                        if (ParagraphRange.InlineShapes.Count > 0)
                        {
                            RedactInlineShape(ParagraphRange.InlineShapes[1]);
                        }
                        else
                        {
                            ParagraphRange.Text = RedactCommon.BuildFillerText(ParagraphRange, rangeData);
                        }
                    }
                }
                else
                {
                    ParagraphRange.Text = RedactCommon.BuildFillerText(ParagraphRange, rangeData);
                }
            }
        }
コード例 #10
0
        //public bool DeleteAllBookmark(string value)
        //{
        //    try
        //    {
        //        foreach (Bookmark bookmark in Wkl.MainCtrl.CommonCtrl.CommonProfile.Bookmarks)
        //            if (MarkupUtilities.GetRangeText(bookmark.Range).Equals(value))
        //                DeleteBookmark(bookmark);
        //        return true;
        //    }
        //    catch (System.Exception ex)
        //    {
        //        ManagerException mgrExp = new ManagerException(ErrorCode.ipe_DeleteBookmarkError,
        //            MessageUtils.Expand(Properties.Resources.ipe_DeleteBookmarkError, ex.Message), ex.StackTrace);

        //        throw mgrExp;
        //    }
        //}

        private void DeleteBookmark(Bookmark bookmark, bool isDeleteWhole)
        {
            if (bookmark != null)
            {
                // 1. remove order by if bookmark is data tag
                string name = bookmark.Name;
                string text = MarkupUtilities.GetRangeText(bookmark.Range);
                if (name.EndsWith(ProntoMarkup.KeySelect))
                {
                    System.Collections.Generic.List <Bookmark>  bms        = GetBookmarksOrderByPosition();
                    System.Collections.Generic.Stack <Bookmark> foreachBms = new System.Collections.Generic.Stack <Bookmark>();
                    bool isExist = false;
                    foreach (Bookmark bm in bms)
                    {
                        if (bm.Name.EndsWith(ProntoMarkup.KeyStartForeach))
                        {
                            foreachBms.Push(bm);
                        }
                        if (bm.Name.EndsWith(ProntoMarkup.KeyEndForeach))
                        {
                            foreachBms.Pop();
                        }
                        if (bm.Name == name)
                        {
                            isExist = true;
                            break;
                        }
                    }
                    if (isExist && foreachBms.Count > 0)
                    {
                        Bookmark foreachBm = foreachBms.Pop();
                        string   oldText   = MarkupUtilities.GetRangeText(foreachBm.Range);
                        string   newText   = oldText.Replace(text +
                                                             Constants.OrderBy.Concat +
                                                             Constants.OrderBy.AscMark +
                                                             Constants.OrderBy.Delimiter, "");
                        newText = newText.Replace(text +
                                                  Constants.OrderBy.Concat +
                                                  Constants.OrderBy.DescMark +
                                                  Constants.OrderBy.Delimiter, "");
                        newText = newText.Replace(Constants.OrderBy.Delimiter + text +
                                                  Constants.OrderBy.Concat +
                                                  Constants.OrderBy.AscMark, "");
                        newText = newText.Replace(Constants.OrderBy.Delimiter + text +
                                                  Constants.OrderBy.Concat +
                                                  Constants.OrderBy.DescMark, "");
                        if (oldText != newText)
                        {
                            UpdateBookmarkText(foreachBm, newText);
                        }
                    }
                }

                // 2. remove bookmark
                if (isDeleteWhole)
                {
                    bookmark.Range.Text = "";
                }
                else
                {
                    bookmark.Delete();
                }
            }
        }
コード例 #11
0
        private object _pathFile;    //文件路径
        public bool SaveToWorld(string title, string imageLocation, string content)
        {
            try
            {
                string strTemplateFile = @"D:\bany\夏士安\震情信息.doc";
                string strFilePath     = @"D:\bany\夏士安\File";
                string strFileName     = Path.Combine(strFilePath, "震情信息" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc");
                object oFileName       = strFileName;
                try
                {
                    if (Directory.Exists(strFilePath) == false)
                    {
                        Directory.CreateDirectory(strFilePath);
                    }
                    if (File.Exists(strFileName))
                    {
                        File.Delete(strFileName);
                    }
                    File.Copy(strTemplateFile, strFileName, true);
                }
                catch (Exception)
                {
                    return(false);
                }
                _wordApp = new ApplicationClass();
                object readOnly  = false;
                object isVisible = false;
                _wordDoc = _wordApp.Documents.Open(ref oFileName, ref nothing,
                                                   ref readOnly, ref nothing,
                                                   ref nothing, ref nothing,
                                                   ref nothing, ref nothing,
                                                   ref nothing, ref nothing,
                                                   ref nothing, ref isVisible,
                                                   ref nothing, ref nothing,
                                                   ref nothing, ref nothing);
                _wordDoc.Activate();


                object _index = "title";

                Bookmark bmTitle = _wordDoc.Bookmarks.get_Item(ref _index);
                bmTitle.Select();
                bmTitle.Range.Font.Name = "宋体";
                bmTitle.Range.Font.Size = 16;
                bmTitle.Range.Text      = title;
                bmTitle.Delete();

                object oimage           = "image";
                Object LinkToFile       = false;
                Object savewithDocument = true;
                object rangs            = _wordApp.ActiveDocument.Bookmarks.get_Item(ref oimage).Range;
                _wordDoc.InlineShapes.AddPicture(imageLocation, ref LinkToFile, ref savewithDocument, ref rangs);
                _wordDoc.Application.ActiveDocument.InlineShapes[1].Width  = 420;
                _wordDoc.Application.ActiveDocument.InlineShapes[1].Height = 200;

                _index = "content";
                Bookmark bmContent = _wordDoc.Bookmarks.get_Item(ref _index);
                bmContent.Select();
                bmContent.Range.Font.Name = "楷体";
                bmContent.Range.Text      = content;
                bmContent.Delete();

                #region 保存word文档
                _saveChanges = true;
                _wordDoc.Close(ref _saveChanges, ref nothing, ref nothing);
                _wordApp.Quit(ref nothing, ref nothing, ref nothing);
                _wordDoc = null;
                _wordApp = null;
                #endregion
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
            }

            return(true);
        }
コード例 #12
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            PDFNet.Initialize();

            // Relative path to the folder containing test files.
            string input_path  = "../../TestFiles/";
            string output_path = "../../TestFiles/Output/";


            // The following example illustrates how to create and edit the outline tree
            // using high-level Bookmark methods.
            try
            {
                using (PDFDoc doc = new PDFDoc(input_path + "numbered.pdf"))
                {
                    doc.InitSecurityHandler();

                    // Lets first create the root bookmark items.
                    Bookmark red   = Bookmark.Create(doc, "Red");
                    Bookmark green = Bookmark.Create(doc, "Green");
                    Bookmark blue  = Bookmark.Create(doc, "Blue");

                    doc.AddRootBookmark(red);
                    doc.AddRootBookmark(green);
                    doc.AddRootBookmark(blue);

                    // You can also add new root bookmarks using Bookmark.AddNext("...")
                    blue.AddNext("foo");
                    blue.AddNext("bar");

                    // We can now associate new bookmarks with page destinations:

                    // The following example creates an 'explicit' destination (see
                    // section '8.2.1 Destinations' in PDF Reference for more details)
                    Destination red_dest = Destination.CreateFit(doc.GetPage(1));
                    red.SetAction(pdftron.PDF.Action.CreateGoto(red_dest));

                    // Create an explicit destination to the first green page in the document
                    green.SetAction(pdftron.PDF.Action.CreateGoto(
                                        Destination.CreateFit(doc.GetPage(10))));

                    // The following example creates a 'named' destination (see
                    // section '8.2.1 Destinations' in PDF Reference for more details)
                    // Named destinations have certain advantages over explicit destinations.
                    String             key         = "blue1";
                    pdftron.PDF.Action blue_action = pdftron.PDF.Action.CreateGoto(key,
                                                                                   Destination.CreateFit(doc.GetPage(19)));

                    blue.SetAction(blue_action);

                    // We can now add children Bookmarks
                    Bookmark sub_red1 = red.AddChild("Red - Page 1");
                    sub_red1.SetAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(doc.GetPage(1))));
                    Bookmark sub_red2 = red.AddChild("Red - Page 2");
                    sub_red2.SetAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(doc.GetPage(2))));
                    Bookmark sub_red3 = red.AddChild("Red - Page 3");
                    sub_red3.SetAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(doc.GetPage(3))));
                    Bookmark sub_red4 = sub_red3.AddChild("Red - Page 4");
                    sub_red4.SetAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(doc.GetPage(4))));
                    Bookmark sub_red5 = sub_red3.AddChild("Red - Page 5");
                    sub_red5.SetAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(doc.GetPage(5))));
                    Bookmark sub_red6 = sub_red3.AddChild("Red - Page 6");
                    sub_red6.SetAction(pdftron.PDF.Action.CreateGoto(Destination.CreateFit(doc.GetPage(6))));

                    // Example of how to find and delete a bookmark by title text.
                    Bookmark foo = doc.GetFirstBookmark().Find("foo");
                    if (foo.IsValid())
                    {
                        foo.Delete();
                    }

                    Bookmark bar = doc.GetFirstBookmark().Find("bar");
                    if (bar.IsValid())
                    {
                        bar.Delete();
                    }

                    // Adding color to Bookmarks. Color and other formatting can help readers
                    // get around more easily in large PDF documents.
                    red.SetColor(1, 0, 0);
                    green.SetColor(0, 1, 0);
                    green.SetFlags(2);                                          // set bold font
                    blue.SetColor(0, 0, 1);
                    blue.SetFlags(3);                                           // set bold and italic

                    doc.Save(output_path + "bookmark.pdf", 0);
                    Console.WriteLine("Done. Result saved in bookmark.pdf");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }


            // The following example illustrates how to traverse the outline tree using
            // Bookmark navigation methods: Bookmark.GetNext(), Bookmark.GetPrev(),
            // Bookmark.GetFirstChild () and Bookmark.GetLastChild ().
            try
            {
                // Open the document that was saved in the previous code sample
                using (PDFDoc doc = new PDFDoc(output_path + "bookmark.pdf"))
                {
                    doc.InitSecurityHandler();

                    Bookmark root = doc.GetFirstBookmark();
                    PrintOutlineTree(root);

                    Console.WriteLine("Done.");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }

            // The following example illustrates how to create a Bookmark to a page
            // in a remote document. A remote go-to action is similar to an ordinary
            // go-to action, but jumps to a destination in another PDF file instead
            // of the current file. See Section 8.5.3 'Remote Go-To Actions' in PDF
            // Reference Manual for details.
            try
            {
                using (PDFDoc doc = new PDFDoc(output_path + "bookmark.pdf"))
                {
                    doc.InitSecurityHandler();

                    // Create file specification (the file referred to by the remote bookmark)
                    Obj file_spec = doc.CreateIndirectDict();
                    file_spec.PutName("Type", "Filespec");
                    file_spec.PutString("F", "bookmark.pdf");

                    FileSpec           spec        = new FileSpec(file_spec);
                    pdftron.PDF.Action goto_remote = pdftron.PDF.Action.CreateGotoRemote(spec, 5, true);

                    Bookmark remoteBookmark1 = Bookmark.Create(doc, "REMOTE BOOKMARK 1");
                    remoteBookmark1.SetAction(goto_remote);
                    doc.AddRootBookmark(remoteBookmark1);

                    // Create another remote bookmark, but this time using the low-level SDF/Cos API.
                    Bookmark remoteBookmark2 = Bookmark.Create(doc, "REMOTE BOOKMARK 2");
                    doc.AddRootBookmark(remoteBookmark2);
                    Obj gotoR = remoteBookmark2.GetSDFObj().PutDict("A");
                    {                                // Create the 'Action' dictionary.
                        gotoR.PutName("S", "GoToR"); // Set action type
                        gotoR.PutBool("NewWindow", true);

                        // Set the file specification
                        gotoR.Put("F", file_spec);

                        // Set the destination.
                        Obj dest = gotoR.PutArray("D");
                        dest.PushBackNumber(9);                          // jump to the tenth page. Note that Acrobat indexes pages from 0.
                        dest.PushBackName("Fit");                        // Fit the page
                    }

                    doc.Save(output_path + "bookmark_remote.pdf", SDFDoc.SaveOptions.e_linearized);
                    Console.WriteLine("Done. Result saved in bookmark_remote.pdf");
                }
            }
            catch (PDFNetException e)
            {
                Console.WriteLine(e.Message);
            }
        }