/// <summary> /// Splitting by page numbers to several one page documents /// </summary> /// <param name="fileName">source file</param> public static void SplittingToOnePageDocuments(string fileName) { //ExStart:SplittingToOnePageDocuments string sourceFile = CommonUtilities.sourcePath + fileName; // Preparing. string password = "******"; List <int> pages = new List <int>(); pages.Add(3); pages.Add(4); PagesOptions pagesSplitOptions = new PagesOptions(FileFormat.Pdf, password, pages); Stream openFile = new FileStream(sourceFile, FileMode.Open); // Main method. MultiDocumentResult splitResult = new DocumentHandler().Split(openFile, pagesSplitOptions); for (int i = 0; i < splitResult.Documents.Count; i++) { // First document Stream documentStream = splitResult.Documents[i].Stream; //output file var fileStream = File.Create(CommonUtilities.outputPath + "OutPut " + i + "." + FileFormat.Pdf); documentStream.CopyTo(fileStream); documentStream.Close(); } //ExEnd:SplittingToOnePageDocuments }
/// <summary> /// Create a new CredentialAppService instance /// </summary> /// <param name="provider">DIP Service provider</param> /// <param name="rsApiOptions">RSoft Api options parameters object</param> /// <param name="localizer">Language localizer string</param> public CredentialAppService ( IServiceProvider provider, IOptions <RSApiOptions> rsApiOptions, IOptions <PagesOptions> pagesOptions, IStringLocalizer <AppResource> localizer ) { _userDomain = provider.GetService <IUserDomainService>(); _apiOptions = rsApiOptions?.Value; _pagesOptions = pagesOptions?.Value; _jsonOptions = new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }; _localizer = localizer; }
/// <summary> /// Remove list of pages from password-protected document of known format /// </summary> /// <param name="fileName">source file</param> public static void RemovePagesFromProtectedKnownFormatDoc(string fileName) { //ExStart:RemovePagesFromProtectedKnownFormatDoc string sourceFile = CommonUtilities.sourcePath + fileName; //Set password, as document is password protected string password = "******"; List <int> pages = new List <int>(); pages.Add(2); PagesOptions pagesOptions = new PagesOptions(FileFormat.Xlsx, password, pages); Stream openFile = new FileStream(sourceFile, FileMode.Open); DocumentResult result = new DocumentHandler().RemovePages(openFile, pagesOptions); Stream documentStream = result.Stream; //output file var fileStream = File.Create(CommonUtilities.outputPath + "OutPut." + FileFormat.Xlsx); documentStream.CopyTo(fileStream); documentStream.Close(); //ExEnd:RemovePagesFromProtectedKnownFormatDoc }
public PageService( IPageRepository pageRepositiry, IPageCollectionRepository pageCollectionRepositiry, IPageMetadataManager pageMetadataManager, IWebsiteContext websiteContext, Url.IPageUrlHelper pageUrlHelper, Views.IViewLocator viewLocator, IOptions <PagesOptions> options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } this.pageRepositiry = pageRepositiry ?? throw new ArgumentNullException(nameof(pageRepositiry)); this.pageCollectionRepositiry = pageCollectionRepositiry ?? throw new ArgumentNullException(nameof(pageCollectionRepositiry)); this.pageMetadataManager = pageMetadataManager ?? throw new ArgumentNullException(nameof(pageMetadataManager)); this.websiteContext = websiteContext ?? throw new ArgumentNullException(nameof(websiteContext)); this.pageUrlHelper = pageUrlHelper ?? throw new ArgumentNullException(nameof(pageUrlHelper)); this.viewLocator = viewLocator ?? throw new ArgumentNullException(nameof(viewLocator)); this.options = options.Value; }
/// <summary> /// Trim document of known format by page numbers list /// </summary> /// <param name="fileName">source file</param> public static void TrimDocumentByPageNumList(string fileName) { //ExStart:TrimDocumentKnownFormat string sourceFile = CommonUtilities.sourcePath + fileName; // Preparation. string password = "******"; int pageNumber1 = 3; int pageNumber2 = 6; List <int> pages = new List <int>(); pages.Add(pageNumber1); pages.Add(pageNumber2); PagesOptions pagesOptions = new PagesOptions(FileFormat.Pdf, password, pages); Stream openFile = new FileStream(sourceFile, FileMode.Open); // Main method. DocumentResult result = new DocumentHandler().Trim(openFile, pagesOptions); Stream documentStream = result.Stream; var fileStream = File.Create(CommonUtilities.outputPath + "OutPut." + FileFormat.Pdf); documentStream.CopyTo(fileStream); documentStream.Close(); //ExEnd:TrimDocumentKnownFormat }
public PageUrlHelper(IOptions <PagesOptions> options) { this.options = options.Value ?? throw new ArgumentNullException(nameof(options.Value)); }