We have already demonstrated how to view the PDF file on the web with the help of Spire.PDFViewer for ASP.NET. This article we will demonstrate how to use three PDFViewer Control to view multiple PDF files on One Web Form in C#.

Before started, we need to create a new ASP.NET Empty Web Application in Visual Studio and add the Spire.PDFViewer.Asp dll file as the references. Then add the PDFViewer control and the PDFDocumentViewer control into toolbox.

Usually, we can Right-click Default.aspx, select view designer, and then drag the PDFViewer control from toolbox into Deafault.aspx to view one PDF file from web. This article we will use the code to add the PDFViewer control to one Web Form.

Step 1: Right-click Default.aspx, click the “Source” and use the following code to add three PDFViewer control from toolbox into Deafault.aspx. We can set the size for each PDFViewer control.

<div>

<cc1:PdfViewer ID="PdfViewer1" runat="server" Height="378px" 
        style="margin-top: 33px" Width="961px">
      
</cc1:PdfViewer>

</div>

<cc1:PdfViewer ID="PdfViewer2" runat="server"         
     Height="200px" style="margin-top: 20px" Width="961px">
  
</cc1:PdfViewer>   

<cc1:PdfViewer ID="PdfViewer3" runat="server"         
     Height="200px" style="margin-top: 20px" Width="961px">
  
</cc1:PdfViewer>

How to view multiple PDF files from one Web page in C#

Step 2: Add a new folder under the projects and add the sample PDF files need to view on the web.

How to view multiple PDF files from one Web page in C#

Step 3: Double-click Default.aspx.cs, add the code below to load a PDF file.

this.PdfViewer1.LoadFromFile("Document/Test.pdf");
this.PdfViewer2.LoadFromFile("Document/Sample.pdf");
this.PdfViewer3.LoadFromFile("Document/Test2.pdf");

After clicking the debug button, we will view the three PDF files on web.

How to view multiple PDF files from one Web page in C#

A PDF Portfolio can combine a wide range of file types such as Word, Excel, PDF and Image files, compared with merging files into a single PDF file, PDF Portfolio remains the individual identities of the files, and you can easily open, read, edit, and format each of them independently of the other files in the PDF Portfolio.

Spire.PDF allows developers to detect if a PDF file is a Portfolio programmatically using c# and vb.net. The following example uses a PDF Portfolio consists of an image, a PDF document and a Word file:

Detect if a PDF File is a Portfolio in C#, VB.NET

Detail steps:

Step 1: Instantiate a PdfDocument object and load the PDF file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Portfolio.pdf");

Step 2: Detect if the PDF file is a Portfolio.

bool isPortfolio = pdf.IsPortfolio;
if (isPortfolio)
{
    Console.WriteLine("It's a Portfolio!");
}

Screenshot:

Detect if a PDF File is a Portfolio in C#, VB.NET

Full code:

[C#]
using System;
using Spire.Pdf;

namespace Detect_if_a_PDF_is_a_Portfolio
{
    class Program
    {
        static void Main(string[] args)
        {
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile("Portfolio.pdf");

            bool isPortfolio = pdf.IsPortfolio;
            if (isPortfolio)
            {
                Console.WriteLine("It's a Portfolio!");
            }
            Console.ReadKey();
        }
    }
}
[VB.NET]
Imports Spire.Pdf

Namespace Detect_if_a_PDF_is_a_Portfolio
	Class Program
		Private Shared Sub Main(args As String())
			Dim pdf As New PdfDocument()
			pdf.LoadFromFile("Portfolio.pdf")

			Dim isPortfolio As Boolean = pdf.IsPortfolio
			If isPortfolio Then
				Console.WriteLine("It's a Portfolio!")
			End If
			Console.ReadKey()
		End Sub
	End Class
End Namespace

With Spire.Doc, we can set the formats for paragraph in C#. This article will focus on demonstrate how to set the spacing before and after the paragraph in C#.

Set the spacing before and after the paragraph for a newly added paragraph added by the method of paragraph.AppendHTML() to a new blank word document.

//create a new word document and add a section and paragraph to it.
Document doc = new Document();
Section sec = doc.AddSection();
Paragraph para = sec.AddParagraph();

//Add the text strings to the paragraph and set the style
para.AppendHTML("

Add a new paragraph to the word and set the spacing

"); para.ApplyStyle(BuiltinStyle.Heading1); //set the spacing before and after para.Format.BeforeAutoSpacing = false; para.Format.BeforeSpacing = 20; para.Format.AfterAutoSpacing = false; para.Format.AfterSpacing = 20; //save the document to file doc.SaveToFile("Result1.docx");

How to set the spacing before and after the paragraph in C#

//create a new word document and load the sample from file
Document document = new Document();
document.LoadFromFile("sample.docx", FileFormat.Docx);

//Add the text strings to the paragraph and set the style
Paragraph para = new Paragraph(document);        
TextRange textRange1 = para.AppendText("This is a inserted paragraph.");
textRange1.CharacterFormat.TextColor = Color.Blue;
textRange1.CharacterFormat.FontSize = 15;

//set the spacing before and after
para.Format.BeforeAutoSpacing = false;
para.Format.BeforeSpacing = 10;
para.Format.AfterAutoSpacing = false;
para.Format.AfterSpacing = 10;

//insert the added paragraph to the word document
document.Sections[0].Paragraphs.Insert(1, para);

//save the document to file
document.SaveToFile("Result2.docx",FileFormat.Docx2010);

How to set the spacing before and after the paragraph in C#

Monday, 30 October 2017 08:02

Show or Hide PDF Layers in C#

When creating a PDF layer, Spire.PDF allows developers to set an initial visibility state for the layer. While it also supports to change the visibility of existing layers in a PDF document. This article explains how to show or hide the existing layers using Spire.PDF.

PdfLayer.Visibility property is used to change the visibility of a PDF layer. To show a hidden layer, set the PdfLayer.Visibility property to PdfVisibility.On. To hide an existing layer, set the PdfLayer.Visibility to PdfVisibility.Off.

The following example shows how to hide a specific PDF layers:

using (PdfDocument doc = new PdfDocument("AddLayers.pdf"))
{
    //Hide the layer by index
    doc.Layers[1].Visibility = PdfVisibility.Off;

    //Hide the layer by Name
    //doc.Layers["BlueLine"].Visibility = PdfVisibility.Off;

    //Save the file
    doc.SaveToFile("HideLayer.pdf");
}

To show or hide all of the layers:

using (PdfDocument doc = new PdfDocument("AddLayers.pdf"))
{
    for (int i = 0; i < doc.Layers.Count; i++)
    {
        //Show all of the layers 
        //doc.Layers[i].Visibility = PdfVisibility.On;
        
        //Hide all of the layers
        doc.Layers[i].Visibility = PdfVisibility.Off;
    }
    //Save the file
    doc.SaveToFile("HideAllLayers.pdf");
}

Screeshot of the sample PDF document:

Show or Hide PDF Layers in C#

Screenshot after hiding all of the layers:

Show or Hide PDF Layers in C#

Spire.Doc supports to add new shape and shape group to the word document, it also supports to remove the shapes from the word. This article will show you how to reset the size of shape on an existing word document via Spire.Doc.

Firstly, view the original shape on the word document:

C# reset the size of shape on the word

Step 1: Create a new instance of word document and load the document from file.

Document doc = new Document();
doc.LoadFromFile("Sample.docx",FileFormat.Docx2010);

Step 2: Get the first section and the third paragraph that contains the shape.

Section section = doc.Sections[0]; 
Paragraph para = section.Paragraphs[2];

Step 3: Get the shape and reset the width and height for the shape.

ShapeObject shape = para.ChildObjects[0] as ShapeObject;

shape.Width = 400;
shape.Height = 300;

Step 4: Save the document to file.

doc.SaveToFile("result.docx",FileFormat.Docx2010);

Effective screenshot of the shape after reset the size.

C# reset the size of shape on the word

Full codes:

[C#]
Document doc = new Document();
doc.LoadFromFile("Sample.docx",FileFormat.Docx2010);

Section section = doc.Sections[0]; 
Paragraph para = section.Paragraphs[2];

ShapeObject shape = para.ChildObjects[0] as ShapeObject;

shape.Width = 400;
shape.Height = 300;

doc.SaveToFile("result.docx",FileFormat.Docx2010);
[VB.NET]
Dim doc As New Document()
doc.LoadFromFile("Sample.docx", FileFormat.Docx2010)

Dim section As Section = doc.Sections(0)
Dim para As Paragraph = section.Paragraphs(2)

Dim shape As ShapeObject = TryCast(para.ChildObjects(0), ShapeObject)

shape.Width = 400
shape.Height = 300

doc.SaveToFile("result.docx", FileFormat.Docx2010)

When it comes to printing, Spire.PDF offers users a wide range of options to fulfil their printing needs. Two of these options are “print multiple PDF pages per sheet” and “print single PDF page to multiple sheets”. This article elaborates how to achieve these two options using Spire.PDF and C#.

Print Multiple PDF Pages per Sheet

Uses can invoke the SelectMultiPageLayout(int rows, int columns) method of the PdfPrintSettings class to print multiple PDF pages per sheet of paper.

//Initialize a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load the pdf file
pdf.LoadFromFile("Input.pdf");

//Print two PDF pages per sheet
pdf.PrintSettings.SelectMultiPageLayout(1, 2);
pdf.Print();

Below screenshot shows the sample pdf document which contains two pages:

Print Multiple PDF Pages per Sheet and Print Single PDF Page to Multiple Sheets in C#

Screenshot after printing to XPS:

Print Multiple PDF Pages per Sheet and Print Single PDF Page to Multiple Sheets in C#

Print Single PDF Page to Multiple Sheets

The SelectSplitPageLayout() method of the PdfPrintSettings class can be used when printing a large PDF page to multiple sheets. This method splits the PDF page to multiple pages according to the standard A4 paper size: 595pt*842pt.

//Initialize a PdfDocument object
PdfDocument pdf = new PdfDocument();
//Load the pdf file
pdf.LoadFromFile("Input1.pdf");

//Print the PDF page to multiple sheets
pdf.PrintSettings.SelectSplitPageLayout();
pdf.Print();

Below screenshot shows the sample pdf document which contains a single page with a size of 2100pt*750pt:

Print Multiple PDF Pages per Sheet and Print Single PDF Page to Multiple Sheets in C#

Screenshot after printing to XPS:

Print Multiple PDF Pages per Sheet and Print Single PDF Page to Multiple Sheets in C#

We've have demonstrated how to convert PDF page to SVG file format in the previous post. This guidance shows you how we can specify the width and height of output file using the latest version of Spire.PDF with C# and VB.NET.

Step 1: Load a sample PDF document to PdfDocument instance.

PdfDocument document = new PdfDocument();
document.LoadFromFile("pdf-sample.pdf");

Step 2: Specify the output file size through ConvertOptions.SetPdfToSvgOptions() method.

document.ConvertOptions.SetPdfToSvgOptions(800f, 1200f);

Step 3: Save PDF to SVG file format.

document.SaveToFile("result.svg", FileFormat.SVG);

Output:

Convert PDF to SVG with Custom Width and Height in C#, VB.NET

Full Code:

[C#]
PdfDocument document = new PdfDocument();
document.LoadFromFile("pdf-sample.pdf");
document.ConvertOptions.SetPdfToSvgOptions(800f, 1200f);
document.SaveToFile("result.svg", FileFormat.SVG);
[VB.NET]
Dim document As New PdfDocument()
document.LoadFromFile("pdf-sample.pdf")
document.ConvertOptions.SetPdfToSvgOptions(800F, 1200F)
document.SaveToFile("result.svg", FileFormat.SVG)
Thursday, 19 October 2017 09:42

Create Nested Group in Excel in C#, VB.NET

Nested group is a group that contains multiple inner, nested groups. This article demonstrates how to create groups and how to outline the outer and inner groups using Spire.XLS with C# and VB.NET.

Step 1: Create a Workbook instance and get the first worksheet.

Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

Step 2: Insert sample data to cells.

sheet.Range["A1"].Value = "Project plan for project X";
sheet.Range["A3"].Value = "Set up";
sheet.Range["A4"].Value = "Task 1";
sheet.Range["A5"].Value = "Task 2";
sheet.Range["A7"].Value = "Launch";
sheet.Range["A8"].Value = "Task 1";
sheet.Range["A9"].Value = "Task 2";

Step 3: Set the IsSummaryRowBelow property as false, which indicates the summary rows appear above detail rows.

sheet.PageSetup.IsSummaryRowBelow = false;

Step 4: Group the rows that you want to group.

sheet.GroupByRows(2, 9, false);
sheet.GroupByRows(4, 5, false);
sheet.GroupByRows(8, 9, false);

Step 5: Save the file.

workbook.SaveToFile("output.xlsx", ExcelVersion.Version2013);

Output:

Create Nested Group in Excel in C#, VB.NET*

Full Code:

[C#]
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];

CellStyle style = workbook.Styles.Add("style");
style.Font.Color = Color.CadetBlue;
style.Font.IsBold = true;

sheet.PageSetup.IsSummaryRowBelow= false;
sheet.Range["A1"].Value = "Project plan for project X";
sheet.Range["A1"].CellStyleName = style.Name;

sheet.Range["A3"].Value = "Set up";
sheet.Range["A3"].CellStyleName = style.Name;
sheet.Range["A4"].Value = "Task 1";
sheet.Range["A5"].Value = "Task 2";
sheet.Range["A4:A5"].BorderAround(LineStyleType.Thin);
sheet.Range["A4:A5"].BorderInside(LineStyleType.Thin);

sheet.Range["A7"].Value = "Launch";
sheet.Range["A7"].CellStyleName = style.Name;
sheet.Range["A8"].Value = "Task 1";
sheet.Range["A9"].Value = "Task 2";
sheet.Range["A8:A9"].BorderAround(LineStyleType.Thin);
sheet.Range["A8:A9"].BorderInside(LineStyleType.Thin);

sheet.GroupByRows(2, 9, false);
sheet.GroupByRows(4, 5, false);
sheet.GroupByRows(8, 9, false);
workbook.SaveToFile("output.xlsx", ExcelVersion.Version2013);
[VB.NET]
Dim workbook As New Workbook()
Dim sheet As Worksheet = workbook.Worksheets(0)

Dim style As CellStyle = workbook.Styles.Add("style")
style.Font.Color = Color.CadetBlue
style.Font.IsBold = True

sheet.PageSetup.IsSummaryRowBelow = False
sheet.Range("A1").Value = "Project plan for project X"
sheet.Range("A1").CellStyleName = style.Name

sheet.Range("A3").Value = "Set up"
sheet.Range("A3").CellStyleName = style.Name
sheet.Range("A4").Value = "Task 1"
sheet.Range("A5").Value = "Task 2"
sheet.Range("A4:A5").BorderAround(LineStyleType.Thin)
sheet.Range("A4:A5").BorderInside(LineStyleType.Thin)

sheet.Range("A7").Value = "Launch"
sheet.Range("A7").CellStyleName = style.Name
sheet.Range("A8").Value = "Task 1"
sheet.Range("A9").Value = "Task 2"
sheet.Range("A8:A9").BorderAround(LineStyleType.Thin)
sheet.Range("A8:A9").BorderInside(LineStyleType.Thin)

sheet.GroupByRows(2, 9, False)
sheet.GroupByRows(4, 5, False)
sheet.GroupByRows(8, 9, False)
workbook.SaveToFile("output.xlsx", ExcelVersion.Version2013)
Thursday, 19 October 2017 03:17

How to add and delete layer in PDF

Developers can use PDF layer to set some content to be visible and others to be invisible in the same PDF file. It makes the PDF Layer widely be used to deal with related contents within the same PDF. With Spire.PDF, we can add several kinds of layers such as line, image, string, ellipse, rectangle and pie to any page of a new or an existing pdf document. At the same time, it also supports us to delete specific layer from a pdf document.

This article will show you how to use Spire.PDF (from version 3.9.360 or above) to add and remove the layers and set the visibility of the layer in C#. If you use the version older than 3.9.360, please refer to the articles of how to add PDF layer, delete layer and toggle the visibility of PDF layer in C#.

Add PDF Layer and toggle the visibility

How to add and delete layer in PDF

//create a new PDF document
PdfDocument doc = new PdfDocument();

//add a new page to the PDF document.
PdfPageBase page = doc.Pages.Add();

//add a layer named "red line"
PdfLayer layer = doc.Layers.AddLayer("red line");
PdfCanvas pcA = layer.CreateGraphics(doc.Pages[0].Canvas);
pcA.DrawLine(new PdfPen(PdfBrushes.Red, 1), new PointF(0, 100), new PointF(100, 100));

//add a layer named "Ellipse" and toggle the visibility as On
layer = doc.Layers.AddLayer("Ellipse", PdfVisibility.On);
PdfCanvas pcB = layer.CreateGraphics(doc.Pages[0].Canvas);
PdfPen pen = new PdfPen(Color.Green, 1f);
PdfBrush brush = new PdfSolidBrush(Color.Green);
pcB.DrawEllipse(pen,brush, 100,120,200,60 );
 
//add a layer named "Blue line" and toggle the visibility as OFF
layer = doc.Layers.AddLayer("Blue line",PdfVisibility.Off);
PdfCanvas pcC = layer.CreateGraphics(doc.Pages[0].Canvas);
pcC.DrawLine(new PdfPen(PdfBrushes.Blue, 1), new PointF(0, 200), new PointF(100, 200));

//save the document to file
doc.SaveToFile("AddLayers.pdf", FileFormat.PDF)

Delete PDF Layer

How to add and delete layer in PDF

//create a new PDF document and load the document from file
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("AddLayers.pdf");

//Delete the layer named “red line”
doc.Layers.RemoveLayer(("red line"));

//save the document to file
doc.SaveToFile("DeleteLayer.pdf", FileFormat.PDF);

Spire.Presentation supports to convert PowerPoint documents to a variety kinds of file formats such as Image, PDF, SVG and HTML. This article focuses on demonstrating how to convert PowerPoint document to HTML using Spire.Presentation.

Below screenshot shows what the example document looks like:

Convert PowerPoint Document to HTML in C#, VB.NET

Detail steps:

Step 1: Initialize an object of Presentation class.

Presentation ppt = new Presentation();

Step 2: Load the PowerPoint document.

ppt.LoadFromFile("Sample.pptx");

Step 3: Save the document to HTML format.

ppt.SaveToFile(@"E:\Program Files\ToHtml.html", FileFormat.Html);

Screenshot:

Convert PowerPoint Document to HTML in C#, VB.NET

Full code:

[C#]
using Spire.Presentation;

namespace Convert_PowerPoint_To_Html
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an object of Presentation class
            Presentation ppt = new Presentation();
            //Load the PowerPoint document
            ppt.LoadFromFile("Sample.pptx");

            //Save the PowerPoint document to HTML format
            ppt.SaveToFile(@"E:\Program Files\ToHtml.html", FileFormat.Html);
        }
[VB.NET]
Imports Spire.Presentation

Namespace Convert_PowerPoint_To_Html
	Class Program
		Private Shared Sub Main(args As String())
			'Initialize an object of Presentation class
			Dim ppt As New Presentation()
			'Load the PowerPoint document
			ppt.LoadFromFile("Sample.pptx")

			'Save the PowerPoint document to HTML format
			ppt.SaveToFile("E:\Program Files\ToHtml.html", FileFormat.Html)
		End Sub
	End Class
End Namespace