Hey guys.
So I have this problem. I made a method that takes an image as a stream and then makes a pdf with the image.
This image comes from a scanner. When I scann the document he is beeing resize to 1700x2347 and i don't know why. This is
a problem because when I pass the image to the pdf page it doesn't fit because A4 page as something as 1248x1760...
Is there a way that I can force the size of the image, something like myimage.weight and myimage.width?
My code is this
Code:
Public Function SetImage(ByVal img As Byte(), ByVal path As String, ByVal nome1 As String) As Boolean
If img IsNot Nothing Then
Try
''''criar o pdf
Dim myPDF As PdfDocument
myPDF = New PdfDocument()
''''
Dim newImage As System.Drawing.Image
Using ms = New MemoryStream(img, 0, img.Length)
ms.Write(img, 0, img.Length)
newImage = System.Drawing.Image.FromStream(ms, True)
newImage.Save(path & Guid.NewGuid().ToString & ".jpg")
'newImage.Save(path & "teste.jpg")
''''passar imagem para pdf
Dim xgr As XGraphics
myPDF.Pages.Add(New PdfPage())
xgr = XGraphics.FromPdfPage(myPDF.Pages(0))
'Dim myImage As XImage = newImage
xgr.DrawImage(newImage, 0, 0)
xgr = Nothing
''''
''''salvar pdf
myPDF.Save("C:\Inetpub\wwwroot\scanner2\Files\teste.pdf")
myPDF = Nothing
''''
End Using
Return True
Catch ex As Exception
Return False
End Try
Else
Return False
End If
End Function