hi ya,
here is the code i am using
Imports PdfSharp.Pdf
Imports PdfSharp.Drawing
Dim tiff As TiffImageSplitter = New TiffImageSplitter()
Public Sub tiff2PDF(ByVal fileName As String)
Dim doc As New PdfDocument()
Dim pageCount As Integer = tiff.getPageCount(fileName)
For i As Integer = 0 To pageCount - 1
Dim page As New PdfPage()
Dim tiffImg As System.Drawing.Image = tiff.getTiffImage(fileName, i)
Dim img As XImage = XImage.FromGdiPlusImage(tiffImg)
page.Width = img.PointWidth
page.Height = img.PointHeight
doc.Pages.Add(page)
Dim xgr As XGraphics = XGraphics.FromPdfPage(doc.Pages(i))
xgr.DrawImage(img, 0, 0)
Next
Dim stream As New MemoryStream()
doc.Save(stream, False)
doc.Close()
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-disposition", "attachment; filename=download.pdf")
Response.AddHeader("content-length", stream.Length.ToString())
Response.BinaryWrite(stream.ToArray())
Response.Flush()
stream.Close()
Response.End()
end sub
here is the class file
Imports Microsoft.VisualBasic
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.IO
Public Class TiffImageSplitter
' Retrive PageCount of a multi-page tiff image
Public Function getPageCount(ByVal fileName As [String]) As Integer
Dim pageCount As Integer = -1
Try
Dim img As Image = Bitmap.FromFile(fileName)
pageCount = img.GetFrameCount(FrameDimension.Page)
img.Dispose()
Catch ex As Exception
pageCount = 0
End Try
Return pageCount
End Function
Public Function getPageCount(ByVal img As Image) As Integer
Dim pageCount As Integer = -1
Try
pageCount = img.GetFrameCount(FrameDimension.Page)
Catch ex As Exception
pageCount = 0
End Try
Return pageCount
End Function
' Retrive a specific Page from a multi-page tiff image
Public Function getTiffImage(ByVal sourceFile As [String], ByVal pageNumber As Integer) As Image
Dim returnImage As Image = Nothing
Try
Dim sourceIamge As Image = Bitmap.FromFile(sourceFile)
returnImage = getTiffImage(sourceIamge, pageNumber)
sourceIamge.Dispose()
Catch ex As Exception
returnImage = Nothing
End Try
' String splittedImageSavePath = "X:\\CJT\\CJT-Docs\\CJT-Images\\result001.tif";
' returnImage.Save(splittedImageSavePath);
Return returnImage
End Function
Public Function getTiffImage(ByVal sourceImage As Image, ByVal pageNumber As Integer) As Image
Dim ms As MemoryStream = Nothing
Dim returnImage As Image = Nothing
Try
ms = New MemoryStream()
Dim objGuid As Guid = sourceImage.FrameDimensionsList(0)
Dim objDimension As New FrameDimension(objGuid)
sourceImage.SelectActiveFrame(objDimension, pageNumber)
sourceImage.Save(ms, ImageFormat.Tiff)
returnImage = Image.FromStream(ms)
Catch ex As Exception[url][/url]
returnImage = Nothing
End Try
Return returnImage
End Function
End Class
i downloaded the latest verision of sharpdf
here is the file i am trying to convert too
http://www.ashford.gov.uk/downloads/221656_1.tif