Hey guys i need your help.
So i'm making a projecto that will create a pdf from the images that people scan. So now I'm on my final tests and i check an error that i don't understand...
I get the error OutOfMemoryException error just in some cases depending on the location of the images file.
I was testing choosing the images files for exemple (C:\Documents and Settings\mp\Desktop\teste) that had 5 jpg images and i created the pdf file in another location and it was ok no error no nothing.
Then i tryed puting the images files in (C:\Inetpub\wwwroot\scanner\images) and tge pdf file in some other location and i got error can you guys help me out figure where the problem is?
My function code is this
Code:
Protected Sub ButtonConvert_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ButtonConvert.Click
Dim source As String
Dim pdfPath As String
Dim i As String = 0
pdfPath = directorioPdf.Text + ".pdf"
source = directorioImagens.Text
''''criar o pdf
Dim myPDF As PdfDocument
myPDF = New PdfDocument()
If Directory.Exists(source) Then
''''ciclo percorre todos os ficheiros do folder
For Each fName As String In Directory.GetFiles(source)
If File.Exists(fName) Then
Dim dFile As String = String.Empty
dFile = Path.GetFileName(fName)
Dim dFilePath As String = String.Empty
dFilePath = source & dFile
''''coloca a imagem na pagina correspondente
Dim xgr As XGraphics
myPDF.Pages.Add(New PdfPage())
xgr = XGraphics.FromPdfPage(myPDF.Pages(i))
Dim myImage As XImage = XImage.FromFile(fName)
xgr.DrawImage(myImage, 0, 0)
xgr = Nothing
myImage = Nothing
i = i + 1
End If
Next
End If
''''Salvar pdf
myPDF.Save(pdfPath)
myPDF = Nothing
''''mostrar resultado ao utilizador
resultado.Text = ("A aplicação criou o pdf correctamente")
End Sub
End Class