public static void Main(string[] args) { PdfLibrary.EnsureInitialized(); var isService = !(Debugger.IsAttached || args.Contains("--console")); if (isService) { var pathToExe = Process.GetCurrentProcess().MainModule?.FileName ?? string.Empty; var pathToContentRoot = Path.GetDirectoryName(pathToExe); Directory.SetCurrentDirectory(pathToContentRoot); } IWebHost host = CreateWebHostBuilder(args.Where(arg => arg != "--console").ToArray(), isService).Build(); if (isService) { using var customWebHostService = new CustomWebHostService(host); ServiceBase.Run(customWebHostService); } else { host.Run(); } }
//// [Fact] public void Print_IntegrationTest() { // Arrange PdfLibrary.EnsureInitialized(); var service = new PdfPrintService(Mock.Of <ILogger <PdfPrintService> >()); using Stream stream = GetEmbeddedResourceStream("Pdfium.dummy.pdf"); // Act service.Print(stream, "Some printer name"); }
public void Document_ShouldPointToDocumentContainingPage() { // Arrange PdfLibrary.EnsureInitialized(); using Stream stream = GetEmbeddedResourceStream("dummy.pdf"); using PdfDocument document = PdfDocument.Open(stream); using PdfPage page = document.OpenPage(0); // Act & Assert page.Document.Should().Be(document); }
public void Open_CanOpenDocumentFromStream() { // Arrange PdfLibrary.EnsureInitialized(); using Stream stream = GetEmbeddedResourceStream("dummy.pdf"); // Act using PdfDocument document = PdfDocument.Open(stream); // Assert document.Should().NotBeNull(); }
public void OpenPage_IndexOutOfRange_ShouldThrowIndexOutOfRangeException() { // Arrange PdfLibrary.EnsureInitialized(); using Stream stream = GetEmbeddedResourceStream("dummy.pdf"); using PdfDocument document = PdfDocument.Open(stream); // Act Action action = () => document.OpenPage(5); // Assert action.Should().Throw <IndexOutOfRangeException>(); }
public void OpenPage_ReturnsRequestedPage() { // Arrange PdfLibrary.EnsureInitialized(); using Stream stream = GetEmbeddedResourceStream("dummy.pdf"); using PdfDocument document = PdfDocument.Open(stream); // Act using PdfPage page = document.OpenPage(0); // Assert page.Should().NotBeNull(); }
public void PageCount_ReturnsPageCountOfDocument() { // Arrange PdfLibrary.EnsureInitialized(); using Stream stream = GetEmbeddedResourceStream("dummy.pdf"); using PdfDocument document = PdfDocument.Open(stream); // Act var pageCount = document.PageCount; // Assert pageCount.Should().Be(1); }
public void SizeInInch_ShouldReturnCorrectSize() { // Arrange PdfLibrary.EnsureInitialized(); using Stream stream = GetEmbeddedResourceStream("dummy.pdf"); using PdfDocument document = PdfDocument.Open(stream); using PdfPage page = document.OpenPage(0); // Act SizeF size = page.SizeInInch; // Assert size.Width.Should().BeApproximately(8.5f, 0.01f); size.Height.Should().BeApproximately(11.0f, 0.01f); }
public void RenderTo_ShouldRenderPageToGraphics() { // Arrange PdfLibrary.EnsureInitialized(); using Stream stream = GetEmbeddedResourceStream("dummy.pdf"); using PdfDocument document = PdfDocument.Open(stream); using PdfPage page = document.OpenPage(0); using var bitmap = new Bitmap(1000, 1000, PixelFormat.Format24bppRgb); bitmap.SetResolution(300.0f, 300.0f); // Act using (var graphics = Graphics.FromImage(bitmap)) { graphics.Clear(Color.White); page.RenderTo(graphics, graphics.VisibleClipBounds); } // Assert // bitmap.Save("dummy-snapshot.png", ImageFormat.Png); CompareWithSnapshot(bitmap, "dummy-snapshot.png").Should().BeTrue(); }