public async Task With_footer() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); ConversionResult result = await prizmDocServer.ConvertToPdfAsync("documents/example.docx", footer : new HeaderFooterOptions() { Lines = new List <HeaderFooterLine>() { new HeaderFooterLine() { Left = "Bottom Left", Center = "THIS IS FOOTER CONTENT", Right = "Bottom Right", }, }, }); string[] pagesText = await TextUtil.ExtractPagesText(result.RemoteWorkFile); foreach (string page in pagesText) { StringAssert.Contains(page, "Bottom Left"); StringAssert.Contains(page, "THIS IS FOOTER CONTENT"); StringAssert.Contains(page, "Bottom Right"); } }
private static async Task MainAsync() { File.Delete("thumbnail.png"); var prizmDocServer = new PrizmDocServerClient(Environment.GetEnvironmentVariable("BASE_URL"), Environment.GetEnvironmentVariable("API_KEY")); // PrizmDoc Server does not currently allow you to extract pages // and convert to PNG in a single operation. But you can still get // a first-page thumbnail efficiently as a two-step process: // // 1. Extract just the first page as a PDF (which you never need to download) // 2. Convert that PDF to a thumbnail PNG // Extract the first page as an intermediate PDF. We won't ever bother // downloading this from PrizmDoc Server. ConversionResult tempFirstPagePdf = await prizmDocServer.ConvertToPdfAsync(new ConversionSourceDocument("project-proposal.docx", pages : "1")); // Convert the PDF to PNGs, specifying a max width and height. We'll get // back a collection of results, one per page. In our case, there is only // one page. IEnumerable <ConversionResult> thumbnailPngs = await prizmDocServer.ConvertAsync(new ConversionSourceDocument(tempFirstPagePdf.RemoteWorkFile), new DestinationOptions(DestinationFileFormat.Png) { PngOptions = new PngDestinationOptions() { MaxWidth = "512px", MaxHeight = "512px", }, }); // Save the single result. await thumbnailPngs.Single().RemoteWorkFile.SaveAsync("thumbnail.png"); }
private static async Task MainAsync() { File.Delete("output.pdf"); var prizmDocServer = new PrizmDocServerClient(Environment.GetEnvironmentVariable("BASE_URL"), Environment.GetEnvironmentVariable("API_KEY")); // Take a DOCX file and convert it to a PDF. ConversionResult result = await prizmDocServer.ConvertToPdfAsync("project-proposal.docx"); // Save the result to "output.pdf". await result.RemoteWorkFile.SaveAsync("output.pdf"); }
public async Task With_local_file_path() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); ConversionResult result = await prizmDocServer.ConvertToPdfAsync("documents/example.docx"); Assert.IsTrue(result.IsSuccess); Assert.AreEqual(2, result.PageCount); ConversionSourceDocument resultSourceDocument = result.Sources.ToList()[0]; Assert.IsNotNull(resultSourceDocument.RemoteWorkFile); Assert.IsNull(resultSourceDocument.Password); Assert.AreEqual("1-2", resultSourceDocument.Pages); await result.RemoteWorkFile.SaveAsync("output.pdf"); FileAssert.IsPdf("output.pdf"); }
public async Task Just_the_first_page() { PrizmDocServerClient prizmDocServer = Util.CreatePrizmDocServerClient(); ConversionSourceDocument sourceDocument = new ConversionSourceDocument("documents/example.docx", pages: "1"); ConversionResult result = await prizmDocServer.ConvertToPdfAsync(sourceDocument); Assert.IsTrue(result.IsSuccess); Assert.AreEqual(1, result.PageCount); ConversionSourceDocument resultSourceDocument = result.Sources.ToList()[0]; Assert.AreEqual(sourceDocument.RemoteWorkFile, resultSourceDocument.RemoteWorkFile); Assert.IsNull(resultSourceDocument.Password); Assert.AreEqual("1", resultSourceDocument.Pages); await result.RemoteWorkFile.SaveAsync("output.pdf"); FileAssert.IsPdf("output.pdf"); }
private static async Task MainAsync() { File.Delete("output.pdf"); var prizmDocServer = new PrizmDocServerClient(Environment.GetEnvironmentVariable("BASE_URL"), Environment.GetEnvironmentVariable("API_KEY")); // Take a DOCX file, append headers and footers to each page (expanding // the page size), and convert it to a PDF. ConversionResult result = await prizmDocServer.ConvertToPdfAsync( "project-proposal.docx", header : new HeaderFooterOptions { Color = "#0000FF", // blue Lines = new List <HeaderFooterLine> { new HeaderFooterLine { Left = "Top Left", Center = "Top", Right = "Top Right" }, new HeaderFooterLine { Center = "Page {{pageNumber}} of {{pageCount}}" }, }, }, footer : new HeaderFooterOptions { Color = "#FF0000", // red Lines = new List <HeaderFooterLine> { new HeaderFooterLine { Center = "BATES{{pageNumber+4000,10}}" }, new HeaderFooterLine { Left = "Bottom Left", Center = "Bottom", Right = "Bottom Right" }, }, }); // Save the result to "output.pdf". await result.RemoteWorkFile.SaveAsync("output.pdf"); }