'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.GraphicsImports GCTEXT = GrapeCity.Documents.TextImports GCDRAW = GrapeCity.Documents.Drawing PublicClassSplitA3toA4x2PublicFunctionCreatePDF(ByVal stream AsStream) AsInteger' A3 and A4 page sizes:' A3 is 11.69" x 16.54":Dim sizeA3 = NewSizeF(11.69F * 72, 16.54F * 72)' A4 is 8.27" x 11.60":Dim sizeA4 = NewSizeF(8.27F * 72, 11.60F * 72) ' Create a sample source PDF with A3 landscape oriented pages:Dim docA3 = NewGcPdfDocument() With { .PageSize = sizeA3, .Landscape = True } ' First page is a horizontal image filling the whole page:Dim p0 = docA3.Pages.Add()Dim imgA3 = GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "aurora.jpg")) p0.Graphics.DrawImage(imgA3, NewRectangleF(PointF.Empty, docA3.PageSize), Nothing, GCDRAW.ImageAlign.StretchImage) ' Add a few more A3 pages as two columns of random 'lorem ipsum' text:Dim p1 = docA3.Pages.Add()Dim g = p1.GraphicsDim tl = g.CreateTextLayout() tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12 tl.TextAlignment = GCTEXT.TextAlignment.Justified tl.FirstLineIndent = 72 / 2 tl.ParagraphSpacing = 72 / 8' Add random text: tl.Append(Util.LoremIpsum(37))' Specify 1/4" margins all around:ConstmarginAsSingle = 72 / 4 tl.MarginAll = marginDim colWidth = p1.Size.Width / 2 tl.MaxWidth = colWidth tl.MaxHeight = p1.Size.Height tl.PerformLayout(True)' In a loop, split and render the text in a 2 column layout, adding pages as needed:Dim col AsInteger = 0Do' 'rest' will accept the text that did not fit:Dim rest AsGCTEXT.TextLayout = NothingDim splitResult = tl.Split(Nothing, rest) g.DrawTextLayout(tl, NewPointF(col * colWidth, 0))If splitResult <> GCTEXT.SplitResult.SplitThenExitDoEndIf tl = rest col += 1If col = 2Then docA3.Pages.Add() g = docA3.Pages.Last.Graphics col = 0EndIfLoop' At this point, 'docA3' is a PDF with landscape oriented A3 pages,' the first page contains an image filling the whole page,' other pages contain random text in two vertical column layout. ' Create the resulting (target) PDF with A4 page size:Dim doc = NewGcPdfDocument() With { .PageSize = sizeA4, .Landscape = False } ' FormXObjects are rendered on graphics like images, but without losing fidelity.' We create two image alignments for the left and the right halves of the source A3 page:Dim iaLeft = NewGCDRAW.ImageAlign(GCDRAW.ImageAlignHorz.Left, GCDRAW.ImageAlignVert.Top, False, False, True, False, False)Dim iaRight = NewGCDRAW.ImageAlign(GCDRAW.ImageAlignHorz.Right, GCDRAW.ImageAlignVert.Top, False, False, True, False, False)ForEach pA3 In docA3.Pages' Create FormXObject representing the source page:Dim fxoA3 = NewFormXObject(doc, pA3)' Draw its left and right halves on separate pages of the target PDF:Dim pLeft = doc.Pages.Add() pLeft.Graphics.DrawForm(fxoA3, pLeft.Bounds, pLeft.Bounds, iaLeft)Dim pRight = doc.Pages.Add() pRight.Graphics.DrawForm(fxoA3, pLeft.Bounds, pLeft.Bounds, iaRight)Next ' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass