//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Text; namespaceDsPdfWeb.Demos{// This example shows how to load a password protected PDF and get its page count and page sizes.// For reference, the loaded PDF is protected with the owner password 'owner' and user password 'user'.publicclassNoPassGetPageInfo {publicintCreatePDF(Stream stream) {usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Wetlands-password-user.pdf"));// Set up DecryptionOptions to allow loading password protected PDFs without password:var dopt = newDecryptionOptions() { ThrowExceptionIfInvalidPassword = false };var docSrc = newGcPdfDocument(); docSrc.Load(fs, dopt); // The PDF to hold the results:var doc = newGcPdfDocument();var page = doc.NewPage();// Set up a TextLayout to format the results:var tl = page.Graphics.CreateTextLayout(); tl.DefaultFormat.Font = StandardFonts.Courier; tl.DefaultFormat.FontSize = 14; tl.MaxWidth = doc.PageSize.Width; tl.MaxHeight = doc.PageSize.Height; tl.MarginAll = tl.Resolution;var captionFmt = newTextFormat(tl.DefaultFormat) { Font = StandardFonts.CourierBold }; // Get and print some of the source PDF stats: tl.AppendLine($"The source PDF contains {docSrc.Pages.Count} page(s).", captionFmt);foreach (var pg in docSrc.Pages) { tl.AppendLine($" Page at index {pg.Index}:", captionFmt);var sz = pg.GetRenderSize(); tl.AppendLine($" Page size is {sz.Width}x{sz.Height}."); tl.AppendLine($" Page has {(pg.Landscape ? "landscape" : "portrait")} orientation."); tl.AppendLine($" Page paper kind is '{pg.PaperKind}'."); } // Render the results: tl.PerformLayout(true);while (true) {var splitResult = tl.Split(null, outTextLayout rest); page.Graphics.DrawTextLayout(tl, PointF.Empty);if (splitResult != SplitResult.Split)break; tl = rest; tl.MarginTop = tl.Resolution; page = doc.Pages.Add(); } // Done: doc.Save(stream);return doc.Pages.Count; } }}