In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the C # how to achieve PDF page merge related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this C# how to achieve PDF page merge article will have a harvest, let's take a look.
Program environment
Method 1
Introduce Spire.Pdf.dll file into the program; download Free Spire.PDF for .NET locally, extract it, and install it. After the installation is complete, locate the Spire.Pdf.dll in the BIN folder under the installation path. Then open solution Explorer in Visual Studio, right-click "reference" and "add reference" to add a reference to the dll file under the local path BIN folder.
Method 2
Install via NuGet. It can be installed in the following two ways:
1. You can open solution Explorer in Visual Studio, right-click "references", "manage NuGet packages", then search for "Free Spire.PDF" and click "install". Wait for the program to be installed.
two。 Copy the following to the PM console installation:
Install-Package FreeSpire.PDF-Version 8.2.0
Code example 1. Page merging from two PDF document pages
(before merging) you need to merge the contents of file 1 into the space on the second page of file 2:
C#
Using Spire.Pdf;using Spire.Pdf.Graphics;using System.Drawing;namespace MergePages {class Program {static void Main (string [] args) {/ / load two PDF documents PdfDocument pdf1 = new PdfDocument (); pdf1.LoadFromFile ("test1.pdf"); PdfDocument pdf2 = new PdfDocument (); pdf2.LoadFromFile ("test2.pdf") / / create template PdfTemplate template = pdf1.Pages [0] .CreateTemplate (); / get page 2 of document 2 PdfPageBase page2 = pdf2.Pages [1]; / / set transparency page2.Canvas.SetTransparency (1f, 1f, PdfBlendMode.Overlay) / / draw the template page2.Canvas.DrawTemplate (template, new PointF (0300)) at the specified location on the page; / / Save the document pdf2.SaveToFile ("mergepages.pdf");}
The effect of the merger:
VB.NET
Imports Spire.PdfImports Spire.Pdf.GraphicsImports System.DrawingNamespace MergePages Class Program Private Shared Sub Main (args As String ()) 'load two PDF documents Dim pdf1 As New PdfDocument () pdf1.LoadFromFile ("test1.pdf") Dim pdf2 As New PdfDocument () pdf2.LoadFromFile ("test2.pdf")' create template Dim Template As PdfTemplate = pdf1.Pages (0) .CreateTemplate () 'get page 2 in document 2 Dim page2 As PdfPageBase = pdf2.Pages (1)' set transparency page2.Canvas.SetTransparency (1F 1F, PdfBlendMode.Overlay) 'draw template page2.Canvas.DrawTemplate (template, New PointF (0300)) at the specified location on the page' save the document pdf2.SaveToFile ("mergepages.pdf") End Sub End ClassEnd Namespace2. Implement page merging in the same PDF document
(before merging) draw the contents of page 2 in the same document to the space on page 1, and delete the extra blank pages:
C#
Using Spire.Pdf;using Spire.Pdf.Graphics;using System.Drawing;namespace MergePage2 {class Program {static void Main (string [] args) {/ / load PDF document PdfDocument pdf = new PdfDocument ("sample.pdf"); / / create template PdfTemplate template = pdf.Pages [1] .CreateTemplate () / / get the first page PdfPageBase page1 = pdf.Pages [0]; / / get the second page PdfPageBase page2 = pdf.Pages [1]; / / set transparency and overlap style page2.Canvas.SetTransparency (1f, 1f, PdfBlendMode.Overlay) / / draw the contents of the second page to the specified location on the first page page1.Canvas.DrawTemplate (template, new PointF (0240)); / / delete the second page `pdf.Pages.RemoveAt (1); / / Save the document pdf.SaveToFile ("MergePage2.pdf", FileFormat.PDF);}
The effect of the merger:
VB.NET
Imports Spire.PdfImports Spire.Pdf.GraphicsImports System.DrawingNamespace MergePage2 Class Program Private Shared Sub Main (args As String ()) 'load PDF document Dim pdf As New PdfDocument ("sample.pdf")' create template Dim template As PdfTemplate = pdf.Pages (1) .CreateTemplate () 'get the first page Dim page1 As PdfPageBase = pdf.Pages (0) 'get the second page Dim page2 As PdfPageBase = pdf.Pages (1)' set transparency and overlap style page2.Canvas.SetTransparency (1F 1F, PdfBlendMode.Overlay) 'draw the contents of the second page to the specified location on the first page page1.Canvas.DrawTemplate (template, New PointF (0240))' delete the second page `pdf.Pages.RemoveAt (1) 'save the document pdf.SaveToFile ("MergePage2.pdf") FileFormat.PDF) End Sub End ClassEnd Namespace's article on "how to merge PDF pages in C #" ends here. Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to merge PDF pages in C#". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.