Knowledgebase (2345)
Children categories
Spire.PDFViewer for ASP.NET contains two controls: PDFViewer and PDFDocumentViewer. Generally, PDFDocumentViewer is used for loading and viewing PDF files on website. But actually, it can also achieve other features such as zoom, fit and page after a simple design.
We've introduced the usage of PDFViewer in the previous article, so this article will illustrate how to zoom PDF File via PDFDocumentViewer in ASP.NET.
Before start, download Spire.PDFViewer for ASP.NET and install it on your system.
Step 1: Create a new ASP.NET Empty Web Application in Visual Studio. Add a new web Form to the project.
Step 2: Add the .dll files from the bin folder as the references of this project.

Step 3: Add the PDFDocumentViewer control into toolbox and drag it into Deafault.aspx.

(Detail manipulations of step 1, 2, 3 refer to this article: How to use Spire.PDFViewer for ASP.NET)
Step 4: Zoom PDF file via Spire. PDFDocumentViewer. Zoom feature is divided into three types in this article:
- Zoom: choose the zoom percentage manually.
- Zoom in: Increase the display page page zoom factor by ten percent.
- Zoom out: decrease the display page page zoom factor by ten percent.
Main codes
Section 1: Call the LoadFromFile() method of PdfDocumentViewer to load a sample PDF file in Default.aspx.cs. Note that you have to add the following if statement and !IsPostBack property before loading the pdf file.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//load the sample PDF file
this.PdfDocumentViewer1.CacheInterval = 1000;
this.PdfDocumentViewer1.CacheTime = 1200;
this.PdfDocumentViewer1.CacheNumberImage = 1000;
this.PdfDocumentViewer1.ScrollInterval = 300;
this.PdfDocumentViewer1.ZoomFactor = 1f;
this.PdfDocumentViewer1.CustomErrorMessages = "";
this.PdfDocumentViewer1.LoadFromFile("files/PDFViewer.pdf");
}
}
Section 2: Design, Drag a DropDownList and two buttons from toolbox into Deafault.aspx, set the properties like "ID", "text" etc. as below.

Generated source code is shown here:
<select id="PdfDocumentViewer1_SelectCurrentZoomLevel" name="PdfDocumentViewer1_SelectCurrentZoomLevel" onchange="pdfdocumentviewer1.SelectDropdownBox(this.value)">
<option value="0.5">50%</option>
<option value="0.75">75%</option>
<option value="1" selected="selected">100%</option>
<option value="1.5">150%</option>
<option value="2">200%</option>
<option value="4">400%</option>
</select>
<input type="button" id="btnZoomIn" value="Zoom In" onclick="pdfdocumentviewer1.ZoomPage()" />
<input type="button" id="btnZoomOut" value="Zoom Out" onclick="pdfdocumentviewer1.NarrowPage()" />
Effect screenshot after designing:

Transferring content between Microsoft Word documents is a frequent need for many users. Whether you're consolidating information from multiple sources or reorganizing the structure of a document, being able to effectively copy and paste text, graphics, and formatting is crucial.
This article demonstrates how to copy content from one Word document to another using C# and Spire.Doc for .NET.
- Copy Specified Paragraphs from One Word Document to Another
- Copy a Section from One Word Document to Another
- Copy the Entire Document and Append it to Another
- Create a Copy of a Word Document
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Copy Specified Paragraphs from One Word Document to Another in C#
With Spire.Doc library for .NET, you can clone individual paragraphs using the Paragraph.Clone() method, and then add the cloned paragraphs to a different Word document using the ParagraphCollection.Add() method. This allows you to selectively copy and transfer content between documents.
To copy specified paragraphs from one Word document to another, follow these steps:
- Create a Document object to load the source file.
- Create another Document object to load the target file.
- Get the specified paragraphs from the source file.
- Clone these paragraphs using Paragraph.Clone() method.
- Add the cloned paragraphs to the target file using ParagraphCollection.Add() method.
- Save the target file to a different Word file.
- C#
using Spire.Doc;
using Spire.Doc.Documents;
namespace CopyParagraphs
{
class Program
{
static void Main(string[] args)
{
// Create a Document object
Document sourceDoc = new Document();
// Load the source file
sourceDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\source.docx");
// Get the specified paragraphs from the source file
Paragraph p1 = sourceDoc.Sections[0].Paragraphs[8];
Paragraph p2 = sourceDoc.Sections[0].Paragraphs[9];
// Create another Document object
Document targetDoc = new Document();
// Load the target file
targetDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\target.docx");
// Get the last section
Section lastSection = targetDoc.LastSection;
// Add the paragraphs from the soure file to the target file
lastSection.Paragraphs.Add((Paragraph)p1.Clone());
lastSection.Paragraphs.Add((Paragraph)p2.Clone());
// Save the target file to a different Word file
targetDoc.SaveToFile("CopyParagraphs.docx", FileFormat.Docx2019);
// Dispose resources
sourceDoc.Dispose();
targetDoc.Dispose();
}
}
}

Copy a Section from One Word Document to Another in C#
A section in a Word document can contain not only paragraphs, but also other elements such as tables. To copy an entire section from one Word document to another, you need to iterate through all the child objects within the section and add them individually to a specified section in the target document.
The steps to copy a section between different Word documents are:
- Create Document objects to load the source file and the target file, respectively.
- Get the specified section from the source file.
- Iterate through the child objects in the section, and clone these objects using DocumentObject.Clone() method.
- Add the cloned child objects to a specified section of the target file using DocumentObjectCollection.Add() method.
- Save the updated target file to a new file.
- C#
using Spire.Doc;
namespace CopySection
{
class Program
{
static void Main(string[] args)
{
// Create a Document object
Document sourceDoc = new Document();
// Load the source file
sourceDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\source.docx");
// Get the specified section from the source file
Section section = sourceDoc.Sections[0];
// Create another Document object
Document targetDoc = new Document();
// Load the target file
targetDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\target.docx");
// Get the last section of the target file
Section lastSection = targetDoc.LastSection;
// Iterate through the child objects in the selected section
foreach (DocumentObject obj in section.Body.ChildObjects)
{
// Add the child object to the last section of the target file
lastSection.Body.ChildObjects.Add(obj.Clone());
}
// Save the target file to a different Word file
targetDoc.SaveToFile("CopySection.docx", FileFormat.Docx2019);
// Dispose resources
sourceDoc.Dispose();
targetDoc.Dispose();
}
}
}
Copy the Entire Document and Append it to Another in C#
To copy the full contents from one Word document into another, you can use the Document.InsertTextFromFile() method. This method appends the source document's contents to the target document, starting on a new page.
The steps to copy the entire document and append it to another are as follows:
- Create a Document object.
- Load a Word file (target file) from the given file path.
- Insert content of a different Word document to the target file using Document.InsertTextFromFile() method.
- Save the updated target file to a new Word document.
- C#
using Spire.Doc;
namespace CopyEntireDocument
{
class Program
{
static void Main(string[] args)
{
// Specify the path of the source document
String sourceFile = "C:\\Users\\Administrator\\Desktop\\source.docx";
// Create a Document object
Document targetDoc = new Document();
// Load the target file
targetDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\target.docx");
// Insert content of the source file to the target file
targetDoc.InsertTextFromFile(sourceFile, FileFormat.Docx);
// Save the target file to a different Word file
targetDoc.SaveToFile("CopyEntireDocuemnt.docx", FileFormat.Docx2019);
// Dispose resources
targetDoc.Dispose();
}
}
}
Create a Copy of a Word Document in C#
Using Spire.Doc library for .NET, you can leverage the Document.Clone() method to easily duplicate a Word document.
Here are the steps to create a copy of a Word document:
- Create a Document object.
- Load a Word file from the given file path.
- Clone the file using Document.Clone() method.
- Save the cloned document to a new Word file.
- C#
using Spire.Doc;
namespace CloneWordDocument
{
class Program
{
static void Main(string[] args)
{
// Create a new document object
Document sourceDoc = new Document();
// Load a Word file
sourceDoc.LoadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx");
// Clone the document
Document newDoc = sourceDoc.Clone();
// Save the cloned document as a docx file
newDoc.SaveToFile("Copy.docx", FileFormat.Docx);
// Dispose resources
sourceDoc.Dispose();
newDoc.Dispose();
}
}
}
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
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. Now developers can easily add page layers by using class PdfPageLayer offered by Spire.PDF. This article will focus on showing how to add layers to a PDF file in C# with the help of Spire.PDF.
Note: Before Start, please download the latest version of Spire.PDF and add Spire.PDF.dll in the bin folder as the reference of Visual Studio.
Here comes to the details:
Step 1: Create a new PDF document
PdfDocument pdfdoc = new PdfDocument();
Step 2: Add a new page to the PDF document.
PdfPageBase page = pdfdoc.Pages.Add();
Step 3: Add a layer named "red line" to the PDF page.
PdfLayer layer = doc.Layers.AddLayer("red line", PdfVisibility.On);
Step 4: Draw a red line to the added layer.
// Create a graphics context for drawing on the specified page's canvas using the created layer PdfCanvas pcA = layer.CreateGraphics(page.Canvas); // Draw a red line on the graphics context using a pen with thickness 2, starting from (100, 350) to (300, 350) pcA.DrawLine(new PdfPen(PdfBrushes.Red, 2), new PointF(100, 350), new PointF(300, 350));
Step 5: Use the same method above to add the other two layers to the PDF page.
layer = doc.Layers.AddLayer("blue line");
PdfCanvas pcB = layer.CreateGraphics(doc.Pages[0].Canvas);
pcB.DrawLine(new PdfPen(PdfBrushes.Blue, 2), new PointF(100, 400), new PointF(300, 400));
layer = doc.Layers.AddLayer("green line");
PdfCanvas pcC = layer.CreateGraphics(doc.Pages[0].Canvas);
pcC.DrawLine(new PdfPen(PdfBrushes.Green, 2), new PointF(100, 450), new PointF(300, 450));
Step 6: Save the document to file.
pdfdoc.SaveToFile("AddLayers.pdf", FileFormat.PDF);
Effective screenshot:

Full codes:
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace AddLayer
{
class Program
{
static void Main(string[] args)
{
// Create a new PdfDocument object
PdfDocument doc = new PdfDocument();
// Load an existing PDF document from the specified file path
doc.LoadFromFile(@"..\..\..\..\..\..\Data\AddLayers.pdf");
// Get the first page of the loaded document
PdfPageBase page = doc.Pages[0];
// Create a new layer named "red line" with visibility set to "On"
PdfLayer layer = doc.Layers.AddLayer("red line", PdfVisibility.On);
// Create a graphics context for drawing on the specified page's canvas using the created layer
PdfCanvas pcA = layer.CreateGraphics(page.Canvas);
// Draw a red line on the graphics context using a pen with thickness 2, starting from (100, 350) to (300, 350)
pcA.DrawLine(new PdfPen(PdfBrushes.Red, 2), new PointF(100, 350), new PointF(300, 350));
// Create a new layer named "blue line" without specifying visibility (default is "Off")
layer = doc.Layers.AddLayer("blue line");
// Create a graphics context for drawing on the first page's canvas using the newly created layer
PdfCanvas pcB = layer.CreateGraphics(doc.Pages[0].Canvas);
// Draw a blue line on the graphics context using a pen with thickness 2, starting from (100, 400) to (300, 400)
pcB.DrawLine(new PdfPen(PdfBrushes.Blue, 2), new PointF(100, 400), new PointF(300, 400));
// Create a new layer named "green line" without specifying visibility (default is "Off")
layer = doc.Layers.AddLayer("green line");
// Create a graphics context for drawing on the first page's canvas using the newly created layer
PdfCanvas pcC = layer.CreateGraphics(doc.Pages[0].Canvas);
// Draw a green line on the graphics context using a pen with thickness 2, starting from (100, 450) to (300, 450)
pcC.DrawLine(new PdfPen(PdfBrushes.Green, 2), new PointF(100, 450), new PointF(300, 450));
// Specify the output file name for the modified PDF
string output = "AddLayers.pdf";
// Save the modified PDF document to the specified output file
doc.SaveToFile(output);
}
}
}