请教大佬,用什么方法可以将一个图片转成一个PDF文件
请教大佬,用什么方法可以将一个图片转成一个PDF文件,看到段VB的代码,VFP里也能实现吗?''' <summary>
''' jpg图片转pdf文件
''' </summary>
''' <param name="jpgfile">jpg文件</param>
''' <param name="pdf">PDF文件</param>
Public Sub ConvertJPG2PDF(ByVal jpgfile As String, ByVal pdf As String)
Dim document = New Document(iTextSharp.text.PageSize.A4, 1, 1, 1, 1)
Dim stream = New FileStream(pdf, FileMode.Create, FileAccess.Write, FileShare.None)
PdfWriter.GetInstance(document, stream)
document.Open()
Dim imageStream = New FileStream(jpgfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Dim image As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imageStream)
If (image.Height > (iTextSharp.text.PageSize.A4.Height - 25)) Then
image.ScaleToFit((iTextSharp.text.PageSize.A4.Width - 25), (iTextSharp.text.PageSize.A4.Height - 25))
ElseIf (image.Width > (iTextSharp.text.PageSize.A4.Width - 25)) Then
image.ScaleToFit((iTextSharp.text.PageSize.A4.Width - 25), (iTextSharp.text.PageSize.A4.Height - 25))
End If
image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE
document.Add(image)
document.Close()
End Sub
[此贴子已经被作者于2023-6-25 14:00编辑过]