'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.LinqImportsSystem.Collections.GenericImportsGrapeCity.Documents.Pdf PublicClassHousePlanAllLayersPublicFunctionCreatePDF(ByVal stream AsStream) AsInteger' The list of PDF names' parts identifying their semantics:Dim fnames AsString() = {"full_electrical_plan.pdf","all_outlets.pdf","data_plan_and_detectors.pdf","HVAC_with_wiring.pdf","lighting_plan.pdf","lighting_plan_with_wiring.pdf","security_system_plan.pdf" }' The common base name:Dim fbase = "how_to_read_electrical_plans_"' The directory containing the PDFs:Dim dir = Path.Combine("Resources", "PDFs") Dim doc = NewGcPdfDocument()Dim page = doc.Pages.Add()Dim g = page.GraphicsDim disposables = NewList(Of IDisposable)()' Combine all PDFs into a single document as layers on the first page:For i = 0To fnames.Length - 1Dim iname = fnames(i)Dim idoc = NewGcPdfDocument()Dim ifs = File.OpenRead(Path.Combine(dir, fbase & iname)) idoc.Load(ifs) disposables.Add(ifs) doc.OptionalContent.AddLayer(iname) doc.OptionalContent.SetLayerDefaultState(iname, False) g.BeginLayer(iname) g.DrawPdfPage(idoc.Pages(0), page.Bounds) g.EndLayer()Next' Make the last layer visible by default: doc.OptionalContent.SetLayerDefaultState(fnames.Last(), True) ' Save the PDF: doc.Save(stream) ' Dispose file streams: disposables.ForEach(Sub(d_) d_.Dispose())Return doc.Pages.CountEndFunctionEndClass