Knowledgebase (2330)
Children categories
Automatically Display Bookmarks or Thumbnails When PDF is Opened in C#/VB.NET
2015-04-16 02:14:27 Written by KoohjiWhen a user opens a PDF document they see the initial view of the PDF. By default, the Bookmarks Panel or Thumbnails Panel is not shown when the PDF is opened. In this article, we're going to demonstrate how to set document properties so that the Bookmarks Panel or Thumbnails Panel will be open every time the file is launched.
Check the test file below, only the page content is showing when the document is opened.

Code Snippet and Effect:
Step 1: Create a new PDF document and load the test file.
PdfDocument Pdf = new PdfDocument();
Pdf.LoadFromFile("Test.pdf");
Step 2: In the class of ViewerPreferences, there is a PageMode property that specifies how the document should be displayed when opened. Set PageMode as UseOutlines, save the changes to a new PDF file named "ShowBookmarks".
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines;
Pdf.SaveToFile("ShowBookmarks.pdf");
Open the newly-generated file, Bookmarks Panel will be automatically displayed as below:

Step 3: If we set PageMode as UseThumbs, and save the changes to another PDF file named "ShowThumbnails", then we will get following effect if we open this file.
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs;
Pdf.SaveToFile("ShowThumbnails.pdf");

Full Code:
using Spire.Pdf;
namespace Bookmarks
{
class Program
{
static void Main(string[] args)
{
PdfDocument Pdf = new PdfDocument();
Pdf.LoadFromFile("Test.pdf");
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines;
Pdf.SaveToFile("ShowBookmarks.pdf");
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs;
Pdf.SaveToFile("ShowThumbnails.pdf");
}
}
}
Imports Spire.Pdf
Namespace Bookmarks
Class Program
Private Shared Sub Main(args As String())
Dim Pdf As New PdfDocument()
Pdf.LoadFromFile("Test.pdf")
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines
Pdf.SaveToFile("ShowBookmarks.pdf")
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs
Pdf.SaveToFile("ShowThumbnails.pdf")
End Sub
End Class
End Namespace
Spire.Presentation has powerful functions to export PowerPoint documents into different image file formats. In the previous articles, we have already shown you how to convert PowerPoint documents into TIFF, PNG and JPG. This article will demonstrate how to convert PowerPoint documents into EMF image. With Spire.Presentation for .NET, we can save presentation slides as an EMF image with the same size with the original slide's size and we can also set a specific size for the resulted EMF image.
Convert Presentation slides to EMF with the default size:
Step 1: Create a presentation document.
Presentation presentation = new Presentation();
Step 2: Load the PPTX file from disk.
presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
Step 3: Save the presentation slide to EMF image by the method of SaveAsEMF().
presentation.Slides[2].SaveAsEMF("Result.emf");
Effective screenshot:

Convert Presentation slides to EMF with a specific size of 1075*710:
Step 1: Create a presentation document.
Presentation presentation = new Presentation();
Step 2: Load the PPTX file from disk.
presentation.LoadFromFile("sample.pptx");
Step 3: Save the presentation slide to EMF image with a specific size of 1075*710 by the method of SaveAsEMF(string filePath, int width, int height).
presentation.Slides[2].SaveAsEMF("Result2.emf", 1075, 710);
Effective screenshot:

Full codes:
using Spire.Presentation;
namespace PPStoEMF
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2010);
//presentation.Slides[2].SaveAsEMF("Result.emf");
presentation.Slides[2].SaveAsEMF("Result2.emf", 1075, 710);
}
}
}
We can set Asian typography for paragraph for .doc files, there are four text alignments: Top, Center, Baseline, Bottom and Auto. In this article let's see how to set alignment when append HTML string code to .doc in C#.
Download Spire.Doc 5.3.83 or upper version, then add reference to your project.
Here are the steps:
Step 1: Create a HTML file contain the following code.
<html> <body> <i>f</i>(<i>x</i>)=<img align="middle" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACcAAAAlCAYAAADBa/A+AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADvSURBVFhH7ZNbCsUwCES7/03nIkSwRh1rL00+PCCJVaeTPq5xMG2uSpuLuC7fwlZzZOxYc0TZnDwZ76WYzjVRjQnn57oQmdC5x9ses6IHUO7xd3NW8xNzVPPCwrtOLBXdbAlHgpJMX9SzVGQz7fUw55Eo87ZnqVAzh8x5z8jrHpl6pBNPb6bNVWlzVW7m5N+zKyT9Wqu0OYn3fVl8am754IHBz5+cpGxOP3qda9CNLNAMVESmmG3mMjw1lzrwXF0iEap5gUj1zNUlI0Jk+4i05lxNWCR1ysIh0Ixb1SJQCNQJ1pERgRU30uaqHGxujB+eJddCfZBWMwAAAABJRU5ErkJggg==" />
Step 2: Create a new document and add new section.
Document doc2 = new Document(); doc2.AddSection();
Step 3: Create new paragraph p and set its property of TextAlignment as "Center".
p.AppendText("Alignment:Center ");
p.AppendHTML(File.ReadAllText(@"test.html"));
p.Format.TextAlignment = TextAlignment.Center;
Step 4: Set other options to make a contrast, Auto is Baseline by default.
Paragraph p1 = doc2.Sections[0].AddParagraph();
p1.AppendText("Alignment:Baseline ");
p1.AppendHTML(File.ReadAllText(@"test.html"));
p1.Format.TextAlignment = TextAlignment.Baseline;
Paragraph p2 = doc2.Sections[0].AddParagraph();
p2.AppendText("Alignment:Bottom ");
p2.AppendHTML(File.ReadAllText(@"test.html"));
p2.Format.TextAlignment = TextAlignment.Bottom;
Paragraph p3 = doc2.Sections[0].AddParagraph();
p3.AppendText("Alignment:Top ");
p3.AppendHTML(File.ReadAllText(@"test.html"));
p3.Format.TextAlignment = TextAlignment.Top;
Paragraph p4 = doc2.Sections[0].AddParagraph();
p4.AppendText("Alignment:Auto ");
p4.AppendHTML(File.ReadAllText(@"test.html"));
p4.Format.TextAlignment = TextAlignment.Auto;
Step 5: Save and review.
doc2.SaveToFile(@"test.doc", FileFormat.Doc);
System.Diagnostics.Process.Start("test.doc");
The screen shot:

Full Code Here:
using Spire.Doc;
using Spire.Doc.Documents;
using System.IO;
namespace SetTextAlignment
{
class Program
{
static void Main(string[] args)
{
Document doc2 = new Document();
doc2.AddSection();
Paragraph p = doc2.Sections[0].AddParagraph();
p.AppendText("Alignment:Center ");
p.AppendHTML(File.ReadAllText(@"test.html"));
p.Format.TextAlignment = TextAlignment.Center;
Paragraph p1 = doc2.Sections[0].AddParagraph();
p1.AppendText("Alignment:Baseline ");
p1.AppendHTML(File.ReadAllText(@"test.html"));
p1.Format.TextAlignment = TextAlignment.Baseline;
Paragraph p2 = doc2.Sections[0].AddParagraph();
p2.AppendText("Alignment:Bottom ");
p2.AppendHTML(File.ReadAllText(@"test.html"));
p2.Format.TextAlignment = TextAlignment.Bottom;
Paragraph p3 = doc2.Sections[0].AddParagraph();
p3.AppendText("Alignment:Top ");
p3.AppendHTML(File.ReadAllText(@"test.html"));
p3.Format.TextAlignment = TextAlignment.Top;
Paragraph p4 = doc2.Sections[0].AddParagraph();
p4.AppendText("Alignment:Auto ");
p4.AppendHTML(File.ReadAllText(@"test.html"));
p4.Format.TextAlignment = TextAlignment.Auto;
doc2.SaveToFile(@"test.doc", FileFormat.Doc);
System.Diagnostics.Process.Start("test.doc");
}
}
}