'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.Collections.GenericImportsGrapeCity.Documents.Pdf PublicClassHousePlanLayersPublicFunctionCreatePDF(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 AsGcPdfDocument = NothingDim page AsPage = NothingDim g AsGcPdfGraphics = NothingDim disposables = NewList(Of IDisposable)()' Combine all PDFs into a single document.' The first PDF is used as the base,' additional PDFs are added as optional content (layers):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)If i = 0Then doc = idoc page = idoc.Pages.Last g = page.GraphicsElse doc.OptionalContent.AddLayer(iname) doc.OptionalContent.SetLayerDefaultState(iname, False) g.BeginLayer(iname) g.DrawPdfPage(idoc.Pages(0), page.Bounds) g.EndLayer()EndIfNext' Save the PDF: doc.Save(stream) ' Dispose file streams: disposables.ForEach(Sub(d_) d_.Dispose())Return doc.Pages.CountEndFunctionEndClass