Skip to content

Commit 1e031a1

Browse files
Updates for Viewer 3.2.0
1 parent efeecc4 commit 1e031a1

File tree

4 files changed

+361
-20
lines changed

4 files changed

+361
-20
lines changed

Examples/GroupDocs.Viewer.Examples.CSharp/GroupDocs.Viewer.Examples/Program.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static void Main(string[] args)
2222
#region ViewerHtmlPresentation
2323

2424
//Render a power point presentation in html form
25-
//ViewGenerator.RenderDocumentAsHtml("word.doc");
25+
// ViewGenerator.RenderDocumentAsHtml("test.docx");
2626

2727
//Render a spreadsheet in html form
2828
//ViewGenerator.RenderDocumentAsHtml("spreadsheet.xlsx");
@@ -50,7 +50,7 @@ static void Main(string[] args)
5050
// ViewGenerator.RenderDocumentAsImages("word.doc",1,2);
5151

5252
//Render a word document in images form and also apply a text as watermark on each page.
53-
// ViewGenerator.RenderDocumentAsImages("word.doc", "Show me as watermark", Color.Purple);
53+
// ViewGenerator.RenderDocumentAsImages("f1.pdf", "Show me as watermark", Color.Purple);
5454

5555
//Render a word document in images form and set the rotation angle to display the rotated page.
5656
// ViewGenerator.RenderDocumentAsImages("word.doc", 180);
@@ -62,7 +62,7 @@ static void Main(string[] args)
6262

6363
#region GeneralRepresentation
6464
//Render the word document in the form of pdf markup
65-
ViewGenerator.RenderDocumentAsPDF("test.pdf");
65+
// ViewGenerator.RenderDocumentAsPDF("test.pdf");
6666

6767
//Render the document as it is (Original form)
6868
//ViewGenerator.RenderDocumentAsOriginal("factsheet.pdf");
@@ -75,6 +75,20 @@ static void Main(string[] args)
7575
//ViewGenerator.RenderDocFromAzure("word.doc");
7676
#endregion
7777

78+
#region OtherImprovements
79+
//Show grid lines for Excel files in html representation
80+
//ViewGenerator.RenderWithGridLinesInExcel("spreadsheet.xlsx");
81+
//Multiple pages per sheet
82+
// ViewGenerator.RenderMultiExcelSheetsInOnePage("testcc1.xlsx");
83+
//Show hidden sheets for Excel files in image representation
84+
// ViewGenerator.RenderWithHiddenSheetsInExcel("spreadsheet.xlsx");
85+
//Render a document from ftp location
86+
//ViewGenerator.RenderWithLocales("word.doc");
87+
//Get all supported document formats
88+
//ViewGenerator.ShowAllSupportedFormats();
89+
90+
#endregion
91+
7892

7993
}
8094
}

Examples/GroupDocs.Viewer.Examples.CSharp/GroupDocs.Viewer.Examples/ViewGenerator.cs

Lines changed: 202 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using GroupDocs.Viewer.Domain.Containers;
1414
using System.IO;
1515
using GroupDocs.Viewer.Handler.Input;
16+
using System.Globalization;
1617

1718
namespace 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

Examples/GroupDocs.Viewer.Examples.VisualBasic/Module1.vb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Namespace GroupDocs.Viewer.Examples
2424
'#Region "ViewerHtmlPresentation"
2525

2626
'Render a power point presentation in html form
27-
ViewGenerator.RenderDocumentAsHtml("sample.pptx")
27+
'ViewGenerator.RenderDocumentAsHtml("sample.pptx")
2828

2929
'Render a spreadsheet in html form
3030
'ViewGenerator.RenderDocumentAsHtml("spreadsheet.xlsx")
@@ -77,6 +77,19 @@ Namespace GroupDocs.Viewer.Examples
7777
'ViewGenerator.RenderDocFromAzure("word.doc");
7878
'#End Region
7979

80+
' #Region "OtherImprovements"
81+
'Show grid lines for Excel files in html representation
82+
'ViewGenerator.RenderWithGridLinesInExcel("spreadsheet.xlsx");
83+
'Multiple pages per sheet
84+
' ViewGenerator.RenderMultiExcelSheetsInOnePage("testcc1.xlsx");
85+
'Show hidden sheets for Excel files in image representation
86+
' ViewGenerator.RenderWithHiddenSheetsInExcel("spreadsheet.xlsx");
87+
'Render a document from ftp location
88+
'ViewGenerator.RenderWithLocales("word.doc");
89+
'Get all supported document formats
90+
'ViewGenerator.ShowAllSupportedFormats();
91+
92+
'#End Region
8093
End Sub
8194
End Module
8295
End Namespace

0 commit comments

Comments
 (0)