'''' 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.ImagingImportsGrapeCity.Documents.Drawing PublicClassPdfToTiffGcImagingPublicFunctionCreatePDF(ByVal stream AsStream) AsInteger' Arbitrary target DPI for the generated TIFF, adjust as needed:ConsttargetDPIAsInteger = 200Dim ptToDpi As Func(OfSingle, Integer) = Function(pts AsSingle) CInt(Math.Round(CDbl(pts) * targetDPI / 72.0)) Dim inputDoc = NewGcPdfDocument()Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "SlidePages.pdf")) inputDoc.Load(fs) ' NOTE: to produce a TIFF disk file, you would create a GcTiffWriter' with the file path as the parameter. But due to the demo browser requirements,' we create a GcTiffWriter on a memory stream instead:' Using tiffWriter As New GcTiffWriter("result.tiff")Using msTiff AsNewMemoryStream()Using tiffWriter AsNewGcTiffWriter(msTiff)ForEach pIn In inputDoc.Pages' Create GcBitmap with same size as the PDF page, adjusted for the target DPI:Using bmp AsNewGcBitmap(ptToDpi(pIn.Size.Width), ptToDpi(pIn.Size.Height), True, ptToDpi(72), ptToDpi(72))' Draw the PDF page on the bitmap and apply in-place grayscale effect:Using g = bmp.CreateGraphics(Color.White) pIn.Draw(g, NewRectangleF(0, 0, bmp.Width, bmp.Height))EndUsing bmp.ApplyEffect(GrayscaleEffect.Get())' Convert full color bitmap to grayscale bitmap and append it as a frame to the TIFF:Using gbmp = bmp.ToGrayscaleBitmap() tiffWriter.AppendFrame(gbmp)EndUsingEndUsingNextEndUsing' At this point tiffWriter has the newly created TIFF. If it was created on' a disk file, that file would contain the TIFF when tiffWriter is disposed.'' To use this sample in the demo browser, we have to convert the TIFF' back to a PDF that is returned to the controller. msTiff.Position = 0Dim doc = NewGcPdfDocument()Using tiffReader AsNewGcTiffReader(msTiff)Dim disposables AsNewList(Of IDisposable)()ForEach tp In tiffReader.FramesDim img = tp.ToImage(ImageBinding.InMemoryData)Dim pOut = doc.Pages.Add(NewSizeF(img.Width / img.HorizontalResolution * 72, img.Height / img.VerticalResolution * 72)) pOut.Graphics.DrawImage(img, pOut.Bounds, Nothing, ImageAlign.Default) disposables.Add(img)Next' Save the PDF: doc.Save(stream)' We can only dispose images after saving the PDF: disposables.ForEach(Sub(d_) d_.Dispose())Return doc.Pages.CountEndUsingEndUsingEndUsingEndFunctionEndClass