public void PDFPageComponent_Pages_Enumerate_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component     = new PDFComponent();
            var pageComponent = component.PageComponent;

            component.OpenDocument(pdfFile, string.Empty);
            Assert.IsTrue(component.IsDocumentOpened);

            Assert.IsNotNull(pageComponent.Pages);

            var pageIndex = 0;

            foreach (var page in pageComponent.Pages)
            {
                Assert.IsNotNull(page);
                Assert.AreEqual(pageIndex++, page.PageIndex);
                Assert.IsNotNull(page.PageLabel);
                Assert.AreEqual(792, page.Height);
                Assert.AreEqual(612, page.Width);
            }

            component.CloseDocument();
            component.Dispose();
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PDFBookmark"/> class.
        /// </summary>
        /// <param name="mainComponent">Main component where this bookmark belongs.</param>
        /// <param name="bookmarkHandle">Handle of this bookmark.</param>
        public PDFBookmark(PDFComponent mainComponent, FPDF_BOOKMARK bookmarkHandle)
        {
            _mainComponent  = mainComponent ?? throw new ArgumentNullException(nameof(mainComponent));
            _bookmarkHandle = bookmarkHandle;

            Bookmarks = new ObservableCollection <IPDFBookmark>();
        }
        public void PDFPageComponent_Properties_Test_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component     = new PDFComponent();
            var pageComponent = component.PageComponent;

            Assert.IsNotNull(pageComponent);
            Assert.IsNotNull(pageComponent[PageLayoutType.Standard]);

            component.OpenDocument(pdfFile, string.Empty);
            Assert.IsTrue(component.IsDocumentOpened);

            Assert.AreEqual(1, pageComponent.CurrentPageIndex);
            Assert.AreEqual(1094, pageComponent.PageCount);

            // Test all layout adapters
            foreach (PageLayoutType type in Enum.GetValues(typeof(PageLayoutType)))
            {
                Assert.IsNotNull(pageComponent[type]);
            }

            // Standard
            Assert.IsTrue(866448 - pageComponent[PageLayoutType.Standard].CumulativeHeight <= 1, "Value: " + pageComponent[PageLayoutType.Standard].CumulativeHeight);
            Assert.IsTrue(792 - pageComponent[PageLayoutType.Standard].HighestGridCellHeight <= 1, "Value: " + pageComponent[PageLayoutType.Standard].HighestGridCellHeight);
            Assert.IsTrue(612 - pageComponent[PageLayoutType.Standard].WidestGridCellWidth <= 1, "Value: " + pageComponent[PageLayoutType.Standard].WidestGridCellWidth);

            // Thumbnail
            Assert.IsTrue(218800 - (int)pageComponent[PageLayoutType.Thumbnail].CumulativeHeight <= 1, "Value: " + (int)pageComponent[PageLayoutType.Thumbnail].CumulativeHeight);
            Assert.IsTrue(100 - (int)pageComponent[PageLayoutType.Thumbnail].HighestGridCellHeight <= 1, "Value: " + (int)pageComponent[PageLayoutType.Thumbnail].HighestGridCellHeight);
            Assert.IsTrue(77 - (int)pageComponent[PageLayoutType.Thumbnail].WidestGridCellWidth <= 1, "Value: " + (int)pageComponent[PageLayoutType.Thumbnail].WidestGridCellWidth);

            component.CloseDocument();
            component.Dispose();
        }
        /// <summary>
        /// <inheritdoc/>
        /// </summary>
        public void AttachedTo(IPDFComponent mainComponent)
        {
            var mc = mainComponent as PDFComponent;

            _mainComponent = mc ?? throw new ArgumentException(
                                       string.Format(CultureInfo.InvariantCulture, "The parameter {0} is not of expected type.", nameof(mainComponent)));
        }
Example #5
0
        public void PDFComponent_Constructor_Call_Success()
        {
            var component = new PDFComponent();

            Assert.IsFalse(component.IsDisposed);
            component.Dispose();
            Assert.IsTrue(component.IsDisposed);
        }
Example #6
0
        public void PDFZoomComponent_Component_CheckType_Success()
        {
            var component     = new PDFComponent();
            var zoomComponent = component.ZoomComponent;

            Assert.IsNotNull(zoomComponent as PDFZoomComponent);

            component.Dispose();
        }
Example #7
0
        public void PDFBookmarkComponent_Component_CheckType_Success()
        {
            var component         = new PDFComponent();
            var bookmarkComponent = component.BookmarkComponent;

            Assert.IsNotNull(bookmarkComponent as PDFBookmarkComponent);

            component.Dispose();
        }
        public void PDFPageComponent_Component_CheckType_Success()
        {
            var component     = new PDFComponent();
            var pageComponent = component.PageComponent;

            Assert.IsNotNull(pageComponent as PDFPageComponent);

            component.CloseDocument();
            component.Dispose();
        }
Example #9
0
        public void PDFComponent_OpenDocument_DocumentDoesNotExist_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "FileDoesNotExist.pdf");

            var component = new PDFComponent();

            component.OpenDocument(pdfFile);
            Assert.IsFalse(component.IsDocumentOpened);
            component.Dispose();
        }
Example #10
0
        public void PDFComponent_OpenDocument_PasswordProtected_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "PwdProtected(Pwd is pwd).pdf");

            var component = new PDFComponent();

            component.OpenDocument(pdfFile);
            Assert.IsFalse(component.IsDocumentOpened);
            component.OpenDocument(pdfFile, "pwd");
            Assert.IsTrue(component.IsDocumentOpened);
            component.CloseDocument();
            component.Dispose();
        }
Example #11
0
        public void PDFComponent_OpenDocument_DocumentExists_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component = new PDFComponent();

            component.OpenDocument(pdfFile);
            Assert.IsTrue(component.IsDocumentOpened);
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);
            component.Dispose();
        }
Example #12
0
        public void PDFComponent_FileWithPath_Get_Success()
        {
            var pdfFile = _constDiversePagesPDF;
            var pdfPath = Path.Combine(_pdfFilesFolder, pdfFile);

            var component = new PDFComponent();

            Assert.IsNull(component.FileWithPath);
            component.OpenDocument(pdfPath);
            Assert.AreEqual(pdfPath, component.FileWithPath);
            component.CloseDocument();
            Assert.IsNull(component.FileWithPath);

            component.Dispose();
        }
Example #13
0
        public void PDFComponent_ChildComponents_RequireThem_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component = new PDFComponent();

            var pageComponent = component.PageComponent;

            Assert.IsNotNull(pageComponent);
            var zoomComponent = component.ZoomComponent;

            Assert.IsNotNull(zoomComponent);
            var bookmarkComponent = component.BookmarkComponent;

            Assert.IsNotNull(bookmarkComponent);

            component.OpenDocument(pdfFile);
            Assert.IsTrue(component.IsDocumentOpened);

            pageComponent = component.PageComponent;
            Assert.IsNotNull(pageComponent);
            zoomComponent = component.ZoomComponent;
            Assert.IsNotNull(zoomComponent);
            bookmarkComponent = component.BookmarkComponent;
            Assert.IsNotNull(bookmarkComponent);

            component.CloseDocument();

            pageComponent = component.PageComponent;
            Assert.IsNotNull(pageComponent);
            zoomComponent = component.ZoomComponent;
            Assert.IsNotNull(zoomComponent);
            bookmarkComponent = component.BookmarkComponent;
            Assert.IsNotNull(bookmarkComponent);

            component.Dispose();

            Assert.IsTrue(pageComponent.IsDisposed);
            Assert.IsTrue(zoomComponent.IsDisposed);
            Assert.IsTrue(bookmarkComponent.IsDisposed);

            pageComponent = component.PageComponent;
            Assert.IsNull(pageComponent);
            zoomComponent = component.ZoomComponent;
            Assert.IsNull(zoomComponent);
            bookmarkComponent = component.BookmarkComponent;
            Assert.IsNull(bookmarkComponent);
        }
Example #14
0
        public void PDFComponent_DocumentInformation_Get_Success()
        {
            var pdfFile   = Path.Combine(_pdfFilesFolder, _constDiversePagesPDF);
            var component = new PDFComponent();

            component.OpenDocument(pdfFile);
            var info = component.DocumentInformation;

            Assert.AreEqual("Diverse pages", info.Title);
            Assert.AreEqual("Miloš Konečný", info.Author);
            Assert.AreEqual("Diverse pages", info.Subject);
            Assert.AreEqual("-", info.Keywords);
            Assert.AreEqual("Miloš Konečný", info.Creator);
            Assert.AreEqual("PDFsharp 1.50.4740 (www.pdfsharp.com)", info.Producer);
            Assert.AreEqual(DateTimeOffset.Parse("2021-02-12T11:37:53+01:00", CultureInfo.InvariantCulture), info.CreationDate);
            Assert.AreEqual(DateTimeOffset.Parse("2021-02-12T11:37:53+01:00", CultureInfo.InvariantCulture), info.ModDate);
            component.Dispose();
        }
Example #15
0
        public void PDFBookmarkComponent_EnumerateBookmarks_CheckCount_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component         = new PDFComponent();
            var bookmarkComponent = component.BookmarkComponent;

            component.OpenDocument(pdfFile, string.Empty);
            Assert.IsTrue(component.IsDocumentOpened);

            var bookmarkCount          = 0;
            Queue <IPDFBookmark> queue = new Queue <IPDFBookmark>(bookmarkComponent.Bookmarks);

            while (queue.Count != 0)
            {
                var bookmark = queue.Dequeue();
                Assert.IsNotNull(bookmark);
                Assert.IsFalse(string.IsNullOrEmpty(bookmark.Text));
                Assert.IsNotNull(bookmark.Action);
                Assert.IsNotNull(bookmark.Action.Destination);
                Assert.IsNotNull(bookmark.Destination);
                var destA = bookmark.Action.Destination;
                var destB = bookmark.Destination;
                Assert.AreEqual(destA.PageIndex, destB.PageIndex);
                Assert.AreEqual(destA.X, destB.X);
                Assert.AreEqual(destA.Y, destB.Y);
                Assert.AreEqual(destA.Zoom, destB.Zoom);

                bookmarkCount++;
                foreach (var childBookmark in bookmark.Bookmarks)
                {
                    queue.Enqueue(childBookmark);
                }
            }

            Assert.AreEqual(218, bookmarkCount);

            component.CloseDocument();
            component.Dispose();
        }
Example #16
0
        public void PDFZoomComponent_StartZoom_Success()
        {
            var pdfFile = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");

            var component     = new PDFComponent();
            var zoomComponent = component.ZoomComponent;

            Assert.AreEqual(1d, zoomComponent.CurrentZoomFactor);

            component.OpenDocument(pdfFile, string.Empty);
            Assert.IsTrue(component.IsDocumentOpened);
            Assert.AreEqual(1d, zoomComponent.CurrentZoomFactor);

            zoomComponent.CurrentZoomFactor = 2.1d;
            Assert.AreEqual(2.1d, zoomComponent.CurrentZoomFactor);

            component.CloseDocument();
            Assert.AreEqual(1d, zoomComponent.CurrentZoomFactor);

            component.CloseDocument();
            component.Dispose();
        }
Example #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PDFBitmap"/> class.
 /// </summary>
 /// <param name="mainComponent">Main component where this bookmark belongs.</param>
 public PDFBitmap(PDFComponent mainComponent)
 {
     _mainComponent = mainComponent ?? throw new ArgumentNullException(nameof(mainComponent));
 }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PDFAction"/> class.
 /// </summary>
 /// <param name="mainComponent">Main component where this destination belongs.</param>
 /// <param name="actionHandle">Handle of associated action.</param>
 public PDFAction(PDFComponent mainComponent, FPDF_ACTION actionHandle)
 {
     _mainComponent = mainComponent ?? throw new ArgumentNullException(nameof(mainComponent));
     _actionHandle  = actionHandle;
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PDFLink"/> class.
 /// </summary>
 /// <param name="mainComponent">Main component where this bookmark belongs.</param>
 /// <param name="linkHandle">Handle of this link.</param>
 public PDFLink(PDFComponent mainComponent, FPDF_LINK linkHandle)
 {
     _mainComponent = mainComponent ?? throw new ArgumentNullException(nameof(mainComponent));
     _linkHandle    = linkHandle;
 }
Example #20
0
        public void PDFComponent_Attach_NewComponent_Success()
        {
            // Prepare 'IPDFDocumentObserver'
            var childComponent        = new Mock <IPDFChildComponent>();
            var documentObserver      = childComponent.As <IPDFDocumentObserver>();
            var documentClosedCounter = 0;

            documentObserver.Setup(a => a.DocumentClosed()).Callback(() => documentClosedCounter++);
            var documentClosingCounter = 0;

            documentObserver.Setup(a => a.DocumentClosing()).Callback(() => documentClosingCounter++);
            var documentOpenedCounter = 0;
            var openedFile            = string.Empty;

            documentObserver.Setup(a => a.DocumentOpened(It.IsAny <string>())).Callback <string>((file) =>
            {
                documentOpenedCounter++;
                openedFile = file;
            });
            var documentFailedCounter = 0;
            var failedFile            = string.Empty;

            documentObserver.Setup(a => a.DocumentOpenFailed(It.IsAny <string>())).Callback <string>((file) =>
            {
                documentFailedCounter++;
                failedFile = file;
            });
            var documentOpeningCounter = 0;
            var openingFile            = string.Empty;

            documentObserver.Setup(a => a.DocumentOpening(It.IsAny <string>())).Callback <string>((file) =>
            {
                documentOpeningCounter++;
                openingFile = file;
            });

            var pdfFileExists       = Path.Combine(_pdfFilesFolder, "Precalculus.pdf");
            var pdfFileDoesNotExist = Path.Combine(_pdfFilesFolder, "FileDoesNotExist.pdf");

            var component = new PDFComponent();

            component.Attach(childComponent.Object);

            // Check before any operation processed
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(0, documentOpenedCounter);
            Assert.AreEqual(0, documentFailedCounter);
            Assert.AreEqual(0, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(string.Empty, openingFile);

            // Open pdf document
            component.OpenDocument(pdfFileExists);
            Assert.IsTrue(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(1, documentOpenedCounter);
            Assert.AreEqual(0, documentFailedCounter);
            Assert.AreEqual(1, documentOpeningCounter);
            Assert.AreEqual(pdfFileExists, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(pdfFileExists, openingFile);

            // Reset values
            openedFile  = string.Empty;
            openingFile = string.Empty;

            // Close pdf document
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(1, documentClosedCounter);
            Assert.AreEqual(1, documentClosingCounter);
            Assert.AreEqual(1, documentOpenedCounter);
            Assert.AreEqual(0, documentFailedCounter);
            Assert.AreEqual(1, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(string.Empty, openingFile);

            // Reset values
            documentClosedCounter  = 0;
            documentClosingCounter = 0;
            documentOpenedCounter  = 0;
            documentFailedCounter  = 0;
            documentOpeningCounter = 0;

            // Open pdf document that does not exist
            component.OpenDocument(pdfFileDoesNotExist);
            Assert.IsFalse(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(0, documentOpenedCounter);
            Assert.AreEqual(1, documentFailedCounter);
            Assert.AreEqual(1, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(pdfFileDoesNotExist, failedFile);
            Assert.AreEqual(pdfFileDoesNotExist, openingFile);

            // Reset values
            failedFile  = string.Empty;
            openingFile = string.Empty;

            // Close pdf document
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(0, documentOpenedCounter);
            Assert.AreEqual(1, documentFailedCounter);
            Assert.AreEqual(1, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(string.Empty, openingFile);

            // Reset values
            documentClosedCounter  = 0;
            documentClosingCounter = 0;
            documentOpenedCounter  = 0;
            documentFailedCounter  = 0;
            documentOpeningCounter = 0;

            // Close not opened pdf document
            component.CloseDocument();
            Assert.IsFalse(component.IsDocumentOpened);

            // Check values
            Assert.AreEqual(0, documentClosedCounter);
            Assert.AreEqual(0, documentClosingCounter);
            Assert.AreEqual(0, documentOpenedCounter);
            Assert.AreEqual(0, documentFailedCounter);
            Assert.AreEqual(0, documentOpeningCounter);
            Assert.AreEqual(string.Empty, openedFile);
            Assert.AreEqual(string.Empty, failedFile);
            Assert.AreEqual(string.Empty, openingFile);

            component.Dispose();
        }
Example #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PDFPage"/> class.
 /// </summary>
 /// <param name="mainComponent">Main component where this page belongs.</param>
 /// <param name="pageIndex">Index of associated page.</param>
 public PDFPage(PDFComponent mainComponent, int pageIndex)
 {
     _mainComponent = mainComponent ?? throw new ArgumentNullException(nameof(mainComponent));
     PageIndex      = pageIndex;
 }
Example #22
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PDFDestination"/> class.
 /// </summary>
 /// <param name="mainComponent">Main component where this destination belongs.</param>
 /// <param name="destinationHandle">Handle of associated destination.</param>
 public PDFDestination(PDFComponent mainComponent, FPDF_DEST destinationHandle)
 {
     _mainComponent     = mainComponent ?? throw new ArgumentNullException(nameof(mainComponent));
     _destinationHandle = destinationHandle;
 }