1313using GroupDocs . Viewer . Domain . Containers ;
1414using System . IO ;
1515using GroupDocs . Viewer . Handler . Input ;
16+ using System . Globalization ;
1617
1718namespace GroupDocs . Viewer . Examples . CSharp
1819{
@@ -33,7 +34,6 @@ public static void RenderDocumentAsHtml(String DocumentName,String DocumentPassw
3334
3435 // Create html handler
3536 ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler ( config ) ;
36-
3737
3838 // Guid implies that unique document name
3939 string guid = DocumentName ;
@@ -47,7 +47,7 @@ public static void RenderDocumentAsHtml(String DocumentName,String DocumentPassw
4747 // Set password if document is password protected.
4848 if ( ! String . IsNullOrEmpty ( DocumentPassword ) )
4949 options . Password = DocumentPassword ;
50- options . PageNumbersToConvert = Enumerable . Range ( 1 , 3 ) . ToList ( ) ;
50+ // options.PageNumbersToConvert = Enumerable.Range(1, 3).ToList();
5151 //Get document pages in html form
5252 List < PageHtml > pages = htmlHandler . GetPages ( guid , options ) ;
5353
@@ -175,7 +175,68 @@ public static void RenderDocumentAsHtml(Uri DocumentURL, String DocumentPassword
175175 }
176176 //ExEnd:RenderRemoteDocAsHtml
177177 }
178-
178+
179+ public static void RenderLargeDocumentAsHtml ( String DocumentName , String DocumentPassword = null )
180+ {
181+ //ExStart:RenderAsHtml
182+ //Get Configurations
183+ ViewerConfig config = Utilities . GetConfigurations ( ) ;
184+
185+ // Create html handler
186+ ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler ( config ) ;
187+
188+
189+ // Guid implies that unique document name
190+ string guid = DocumentName ;
191+
192+ //Instantiate the HtmlOptions object
193+ HtmlOptions options = new HtmlOptions ( ) ;
194+
195+ //to get html representations of pages with embedded resources
196+ options . IsResourcesEmbedded = true ;
197+
198+ // Set password if document is password protected.
199+ if ( ! String . IsNullOrEmpty ( DocumentPassword ) )
200+ options . Password = DocumentPassword ;
201+ //Get Pre Render info
202+ int allPages = htmlHandler . GetDocumentInfo ( new DocumentInfoOptions ( guid ) ) . Pages . Count ;
203+
204+ int pageNumber = 1 ;
205+
206+ // Get total iterations and remainder
207+ int totalIterations = allPages / 5 ;
208+ int remainder = allPages % 5 ;
209+
210+ for ( int i = 1 ; i <= totalIterations ; i ++ )
211+ {
212+ // Set range of the pages
213+ options . PageNumbersToConvert = Enumerable . Range ( pageNumber , 5 ) . ToList ( ) ;
214+ // Get pages
215+ List < PageHtml > pages = htmlHandler . GetPages ( guid , options ) ;
216+ //Save each page at disk
217+ foreach ( PageHtml page in pages )
218+ {
219+ //Save each page at disk
220+ Utilities . SaveAsHtml ( "it" + i + "_" + "p" + page . PageNumber + "_" + DocumentName , page . HtmlContent ) ;
221+ }
222+ pageNumber += 5 ;
223+
224+ }
225+ if ( remainder > 0 )
226+ {
227+ options . PageNumbersToConvert = Enumerable . Range ( pageNumber , remainder ) . ToList ( ) ;
228+ List < PageHtml > pages = htmlHandler . GetPages ( guid , options ) ;
229+ //Save each page at disk
230+ foreach ( PageHtml page in pages )
231+ {
232+ //Save each page at disk
233+ Utilities . SaveAsHtml ( "it" + ( totalIterations + 1 ) + "_" + "p" + page . PageNumber + "_" + DocumentName , page . HtmlContent ) ;
234+ }
235+ pageNumber += 5 ;
236+ }
237+
238+ //ExEnd:RenderAsHtml
239+ }
179240 #endregion
180241
181242 #region ImageRepresentation
@@ -471,11 +532,11 @@ public static void LoadFileTree(String Path)
471532 public static void RenderDocFromAzure ( String DocumentName )
472533 {
473534 // Setup GroupDocs.Viewer config
474- ViewerConfig config = new ViewerConfig ( ) ;
475- config . StoragePath = @"C:\storage" ;
535+ ViewerConfig config = Utilities . GetConfigurations ( ) ;
536+
476537
477538 // File guid
478- string guid = @"word.doc" ;
539+ string guid = DocumentName ;
479540
480541 // Use custom IInputDataHandler implementation
481542 IInputDataHandler inputDataHandler = new AzureInputDataHandler ( "<Account_Name>" , "<Account_Key>" , "<Container_Name>" ) ;
@@ -497,11 +558,10 @@ public static void RenderDocFromAzure(String DocumentName)
497558 public static void RenderDocFromFTP ( String DocumentName )
498559 {
499560 // Setup GroupDocs.Viewer config
500- ViewerConfig config = new ViewerConfig ( ) ;
501- config . StoragePath = @"C:\storage" ;
502-
561+ ViewerConfig config = Utilities . GetConfigurations ( ) ;
562+
503563 // File guid
504- string guid = @"word.doc" ;
564+ string guid = DocumentName ;
505565
506566 // Use custom IInputDataHandler implementation
507567 IInputDataHandler inputDataHandler = new FtpInputDataHandler ( ) ;
@@ -517,6 +577,138 @@ public static void RenderDocFromFTP(String DocumentName)
517577 }
518578 }
519579 #endregion
580+
581+ #region OtherImprovements
582+
583+ /* Working from 3.2.0*/
584+ /// <summary>
585+ /// Show grid lines for Excel files in html representation
586+ /// </summary>
587+ /// <param name="DocumentName"></param>
588+ public static void RenderWithGridLinesInExcel ( String DocumentName )
589+ {
590+ // Setup GroupDocs.Viewer config
591+ ViewerConfig config = Utilities . GetConfigurations ( ) ;
592+
593+ ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler ( config ) ;
594+
595+ // File guid
596+ string guid = DocumentName ;
597+
598+ // Set html options to show grid lines
599+ HtmlOptions options = new HtmlOptions ( ) ;
600+ //do same while using ImageOptions
601+ options . CellsOptions . ShowGridLines = true ;
602+
603+ List < PageHtml > pages = htmlHandler . GetPages ( guid , options ) ;
604+
605+ foreach ( PageHtml page in pages )
606+ {
607+ //Save each page at disk
608+ Utilities . SaveAsHtml ( page . PageNumber + "_" + DocumentName , page . HtmlContent ) ;
609+ }
610+ }
611+ /// <summary>
612+ /// Multiple pages per sheet
613+ /// </summary>
614+ /// <param name="DocumentName"></param>
615+ public static void RenderMultiExcelSheetsInOnePage ( String DocumentName )
616+ {
617+ // Setup GroupDocs.Viewer config
618+ ViewerConfig config = Utilities . GetConfigurations ( ) ;
619+
620+ // Create image or html handler
621+ ViewerImageHandler imageHandler = new ViewerImageHandler ( config ) ;
622+ string guid = DocumentName ;
623+
624+ // Set pdf file one page per sheet option to false, default value of this option is true
625+ PdfFileOptions pdfFileOptions = new PdfFileOptions ( ) ;
626+ pdfFileOptions . Guid = guid ;
627+ pdfFileOptions . CellsOptions . OnePagePerSheet = false ;
628+
629+ //Get pdf file
630+ FileContainer fileContainer = imageHandler . GetPdfFile ( pdfFileOptions ) ;
631+
632+ Utilities . SaveFile ( "test.pdf" , fileContainer . Stream ) ;
633+ }
634+ /// <summary>
635+ /// Get all supported document formats
636+ /// </summary>
637+
638+ public static void ShowAllSupportedFormats ( )
639+ {
640+ // Setup GroupDocs.Viewer config
641+ ViewerConfig config = Utilities . GetConfigurations ( ) ;
642+
643+ // Create image or html handler
644+ ViewerImageHandler imageHandler = new ViewerImageHandler ( config ) ;
645+
646+ // Get supported document formats
647+ DocumentFormatsContainer documentFormatsContainer = imageHandler . GetSupportedDocumentFormats ( ) ;
648+ Dictionary < string , string > supportedDocumentFormats = documentFormatsContainer . SupportedDocumentFormats ;
649+
650+ foreach ( KeyValuePair < string , string > supportedDocumentFormat in supportedDocumentFormats )
651+ {
652+ Console . WriteLine ( string . Format ( "Extension: '{0}'; Document format: '{1}'" , supportedDocumentFormat . Key , supportedDocumentFormat . Value ) ) ;
653+ }
654+ Console . ReadKey ( ) ;
655+ }
656+ /// <summary>
657+ /// Show hidden sheets for Excel files in image representation
658+ /// </summary>
659+ /// <param name="DocumentName"></param>
660+ public static void RenderWithHiddenSheetsInExcel ( String DocumentName )
661+ {
662+ // Setup GroupDocs.Viewer config
663+ ViewerConfig config = Utilities . GetConfigurations ( ) ;
664+
665+ ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler ( config ) ;
666+
667+ // File guid
668+ string guid = DocumentName ;
669+
670+ // Set html options to show grid lines
671+ HtmlOptions options = new HtmlOptions ( ) ;
672+ //do same while using ImageOptions
673+ options . CellsOptions . ShowHiddenSheets = true ;
674+
675+ List < PageHtml > pages = htmlHandler . GetPages ( guid , options ) ;
676+
677+ foreach ( PageHtml page in pages )
678+ {
679+ //Save each page at disk
680+ Utilities . SaveAsHtml ( page . PageNumber + "_" + DocumentName , page . HtmlContent ) ;
681+ }
682+ }
683+ /// <summary>
684+ /// create and use file with localized string
685+ /// </summary>
686+ /// <param name="DocumentName"></param>
687+ public static void RenderWithLocales ( String DocumentName )
688+ {
689+ // Setup GroupDocs.Viewer config
690+ ViewerConfig config = Utilities . GetConfigurations ( ) ;
691+ config . LocalesPath = @"D:\from office working\for aspose\GroupDocsViewer\GroupDocs.Viewer.Examples\Data\Locale" ;
692+
693+ CultureInfo cultureInfo = new CultureInfo ( "fr-FR" ) ;
694+ ViewerHtmlHandler htmlHandler = new ViewerHtmlHandler ( config , cultureInfo ) ;
695+
696+ // File guid
697+ string guid = DocumentName ;
698+
699+ // Set html options to show grid lines
700+ HtmlOptions options = new HtmlOptions ( ) ;
701+
702+ List < PageHtml > pages = htmlHandler . GetPages ( guid , options ) ;
703+
704+ foreach ( PageHtml page in pages )
705+ {
706+ //Save each page at disk
707+ Utilities . SaveAsHtml ( page . PageNumber + "_" + DocumentName , page . HtmlContent ) ;
708+ }
709+ }
710+
711+ #endregion
520712 }
521713
522714
0 commit comments