The sample demonstrates how to overlay one page on another and set transparency mode.
Download Overlay.pdf
using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;
namespace Overlay
{
class Program
{
static void Main(string[] args)
{
//load two document
PdfDocument doc1 = new PdfDocument();
doc1.LoadFromFile("Sample1.pdf");
PdfDocument doc2 = new PdfDocument();
doc2.LoadFromFile("Sample3.pdf");
//Create page template
PdfTemplate template = doc1.Pages[0].CreateTemplate();
foreach (PdfPageBase page in doc2.Pages)
{
page.Canvas.SetTransparency(0.25f, 0.25f, PdfBlendMode.Overlay);
page.Canvas.DrawTemplate(template, PointF.Empty);
}
//Save pdf file.
doc2.SaveToFile("Overlay.pdf");
doc1.Close();
doc2.Close();
//Launching the Pdf file.
System.Diagnostics.Process.Start("Overlay.pdf");
}
}
}
Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics
Namespace Overlay
Friend Class Program
Shared Sub Main(ByVal args() As String)
'load two document
Dim doc1 As New PdfDocument()
doc1.LoadFromFile("Sample1.pdf")
Dim doc2 As New PdfDocument()
doc2.LoadFromFile("Sample3.pdf")
'Create page template
Dim template As PdfTemplate = doc1.Pages(0).CreateTemplate()
For Each page As PdfPageBase In doc2.Pages
page.Canvas.SetTransparency(0.25F, 0.25F, PdfBlendMode.Overlay)
page.Canvas.DrawTemplate(template, PointF.Empty)
Next page
'Save pdf file.
doc2.SaveToFile("Overlay.pdf")
doc1.Close()
doc2.Close()
'Launching the Pdf file.
Process.Start("Overlay.pdf")
End Sub
End Class
End Namespace