Im using the itextsharp library,
Wondering on a multi-page tif, right now my code is producing vertical pages only... Even for pages within the TIF that are horizontal;
I am lost as to why, and a way to fix this....
[tt]
Public Function ConvertTIFtoPDF(ByVal SourceFilename As String, ByVal TargetFile As String) As Boolean
Try
If File.Exists(SourceFilename) Then
Dim document As Document = New Document(PageSize.A4, 50, 50, 50, 50)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, New System.IO.FileStream(TargetFile, System.IO.FileMode.Create, System.IO.FileAccess.Write))
Dim bitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(SourceFilename)
Dim numberOfPages As Integer = bitmap.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)
document.Open()
Dim cb As PdfContentByte = writer.DirectContent
Dim page As Integer = 0
Do While (page < numberOfPages)
bitmap.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, page)
''Console.WriteLine("Page " & page & " Phs Dim:" & bitmap.PhysicalDimension.ToString)
'Console.WriteLine("Page " & page & " Size:" & bitmap.Size.ToString)
Dim stream As New System.IO.MemoryStream
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(stream.ToArray)
' This step is really slow
img.ScalePercent((72.0F / bitmap.HorizontalResolution * 100))
img.SetAbsolutePosition(0, 0)
cb.AddImage(img)
document.NewPage()
page = (page + 1)
Loop
document.Close()
Return True
Else
Return False
End If
Catch ex As Exception
Return False
'Debug.WriteLine(ex.ToString)
End Try
End Function
[/tt]
Wondering on a multi-page tif, right now my code is producing vertical pages only... Even for pages within the TIF that are horizontal;
I am lost as to why, and a way to fix this....
[tt]
Public Function ConvertTIFtoPDF(ByVal SourceFilename As String, ByVal TargetFile As String) As Boolean
Try
If File.Exists(SourceFilename) Then
Dim document As Document = New Document(PageSize.A4, 50, 50, 50, 50)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, New System.IO.FileStream(TargetFile, System.IO.FileMode.Create, System.IO.FileAccess.Write))
Dim bitmap As System.Drawing.Bitmap = New System.Drawing.Bitmap(SourceFilename)
Dim numberOfPages As Integer = bitmap.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)
document.Open()
Dim cb As PdfContentByte = writer.DirectContent
Dim page As Integer = 0
Do While (page < numberOfPages)
bitmap.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, page)
''Console.WriteLine("Page " & page & " Phs Dim:" & bitmap.PhysicalDimension.ToString)
'Console.WriteLine("Page " & page & " Size:" & bitmap.Size.ToString)
Dim stream As New System.IO.MemoryStream
bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png)
Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(stream.ToArray)
' This step is really slow
img.ScalePercent((72.0F / bitmap.HorizontalResolution * 100))
img.SetAbsolutePosition(0, 0)
cb.AddImage(img)
document.NewPage()
page = (page + 1)
Loop
document.Close()
Return True
Else
Return False
End If
Catch ex As Exception
Return False
'Debug.WriteLine(ex.ToString)
End Try
End Function
[/tt]