Announcement

Collapse
No announcement yet.

TIF in PDF umwandeln mit itextsharp

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • TIF in PDF umwandeln mit itextsharp

    Hallo zusammen,

    ich versuche verzweifelt eine TIF Datei mit itextsharp in eine PDF umzuwandeln...

    ...bei der JPG geht das problemlos (als Hintergrund).
    Ich denke Hintergrund scheidet bei einer TIF Datei aus, da es ja möglicherweise mehrere Seiten sind.

    ich habe hier mal meinen Code in dem ich JPG´s als Hintergrund einfüge.

    Hat da jemand ne Idee wie ich das mit ner tif hin bekomme?

    [highlight=vb.net]Public Class Form1

    Private Sub cmd_einfügen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmd_einfügen.Click

    Dim input As String

    Dim output As String

    Dim water As String



    input = "C:\hallo welt.pdf"

    water = "C:\hintergrund.jpg"

    output = "C:\ergebnis.pdf"

    AddWatermarkImage(input, output, water)



    End Sub

    Public Shared Sub AddWatermarkImage(ByVal sourceFile As String, ByVal outputFile As String, ByVal watermarkImage As String)

    Dim reader As iTextSharp.text.pdf.PdfReader = Nothing

    Dim stamper As iTextSharp.text.pdf.PdfStamper = Nothing

    Dim img As iTextSharp.text.Image = Nothing

    Dim underContent As iTextSharp.text.pdf.PdfContentByte = Nothing

    Dim rect As iTextSharp.text.Rectangle = Nothing

    Dim X, Y As Single

    Dim pageCount As Integer = 0


    Try

    If System.IO.File.Exists(sourceFile) Then

    reader = New iTextSharp.text.pdf.PdfReader(sourceFile)

    rect = reader.GetPageSizeWithRotation(1)

    stamper = New iTextSharp.text.pdf.PdfStamper(reader, New System.IO.FileStream(outputFile, IO.FileMode.Create))

    img = iTextSharp.text.Image.GetInstance(watermarkImage)

    If img.Width > rect.Width OrElse img.Height > rect.Height Then

    img.ScaleToFit(rect.Width, rect.Height)

    X = (rect.Width - img.ScaledWidth) / 2

    Y = (rect.Height - img.ScaledHeight) / 2

    Else

    X = (rect.Width - img.Width) / 2

    Y = (rect.Height - img.Height) / 2

    End If

    img.SetAbsolutePosition(X, Y)

    pageCount = reader.NumberOfPages()

    For i As Integer = 1 To pageCount

    underContent = stamper.GetUnderContent(i)

    underContent.AddImage(img)

    Next

    stamper.Close()

    reader.Close()

    Else

    MessageBox.Show("Deitei existiert nicht", "Datei?")

    End If

    Catch ex As Exception

    Throw ex

    End Try

    End Sub
    End Class[/highlight]

    Danke!

    Gruß vom Shark
    Zuletzt editiert von gfoidl; 19.06.2009, 13:08. Reason: Code-Formatierung auf VB.net geändert
Working...
X