Foxtable(狐表)用户栏目专家坐堂 → PDF转图片无效


  共有967人关注过本帖树形打印复制链接

主题:PDF转图片无效

帅哥哟,离线,有人找我吗?
keli0917
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:276 积分:2600 威望:0 精华:0 注册:2018/5/21 16:49:00
PDF转图片无效  发帖心情 Post By:2024/7/28 20:37:00 [显示全部帖子]

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=77213&skin=0这个网址的

ConvertPDF2Image("d:\test.pdf", "d:\test", "test", 1, 5, ImageFormat.Jpeg, Definition.One)


使用这个方法PDF转图片,我这个PDF文档无法转换是怎么回事?有些PDF是可以的。
 


[此贴子已经被作者于2024/7/28 21:35:45编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
keli0917
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:276 积分:2600 威望:0 精华:0 注册:2018/5/21 16:49:00
  发帖心情 Post By:2024/7/28 21:52:00 [显示全部帖子]

好。那既然转换图片行不通。那么,专业报表,能将PDF格式的附件,加入打印吗

 回到顶部
帅哥哟,离线,有人找我吗?
keli0917
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:276 积分:2600 威望:0 精华:0 注册:2018/5/21 16:49:00
  发帖心情 Post By:2024/7/28 21:54:00 [显示全部帖子]

Dim doc As New PrintDoc '定义一个报表
Dim
 rt As New prt.RenderTable() '定义一个表格对象
Dim
 rx As New prt.RenderText '定义一个文本对象
Dim
 CurRow As Row = Tables("员工").Current
'加入标题

rx.text = 
"员工资料卡"
rx.Style.FontBold = 
True '字体加粗
rx.Style.FontSize = 
16 '大体大小为16磅
rx.Style.TextAlignHorz = prt.AlignHorzEnum.Center 
'水平居中排列
rx.Style.Spacing.Bottom = 
3 '和下面的对象(表格)距离3毫米
doc.Body.Children.Add(rx) 
'加入到报表中
'指定行数、列数、列宽、行高

rt.Rows.Count = 
7 '设置总行数
rt.Cols.Count = 
5 '设置总列数
rt.Height = 
80 '设置表格的高度为80毫米
rt.Rows(
6).Height = 40 '设置第7行(显示备注的行)的高度为40毫米,剩余高度被平均分排到其他行
rt.Cols(
0).Width = 24 '设置前四列的宽度,剩余的宽度被分配给5列(显示图片的那列)
rt.Cols(
1).Width = 35
rt.Cols(
2).Width = 24
rt.Cols(
3).Width = 40
'设置合并单元格

rt.Cells(
0,4).SpanRows = 6 '第1行第5个单元格向下合并6行(用于显示照片)
rt.Cells(
4,1).SpanCols = 3 '第5行第2个单元格向右合并3列(用于显示地址)
rt.Cells(
6,0).SpanCols = 5 '第7行第1个单元格向右合并5列(用于显示备注)
'设置表格样式

rt.CellStyle.Spacing.All = 
1 '单元格内容缩进1毫米
rt.Style.GridLines.All = New prt.Linedef 
'设置网格线
rt.Style.TextAlignVert = prt.AlignVertEnum.Center 
'内容垂直居中
rt.Rows(
6).Style.TextAlignVert = prt.AlignVertEnum.Top '唯独第7行是备注,内容靠上对齐
'下面很简单,指定每一个单元格的内容

rt.Cells(
0,0).Text= "姓名"
rt.Cells(
0,1).Text = CurRow("姓名")
rt.Cells(
0,2).Text= "出生日期"
rt.Cells(
0,3).Text = CurRow("出生日期")
rt.Cells(
1,0).Text= "部门"
rt.Cells(
1,1).Text = CurRow("部门")
rt.Cells(
1,2).Text= "雇佣日期"
rt.Cells(
1,3).Text = CurRow("雇佣日期")
rt.Cells(
2,0).Text= "性别"
rt.Cells(
2,1).Text = CurRow("性别")
rt.Cells(
2,2).Text= "职务"
rt.Cells(
2,3).Text = CurRow("职务")
rt.Cells(
3,0).Text= "城市"
rt.Cells(
3,1).Text = CurRow("城市")
rt.Cells(
3,2).Text= "邮政编码"
rt.Cells(
3,3).Text = CurRow("邮政编码")
rt.Cells(
4,0).Text= "地址"
rt.Cells(
4,1).Text = CurRow("地址")
rt.Cells(
5,0).Text= "家庭电话"
rt.Cells(
5,1).Text = CurRow("家庭电话")
rt.Cells(
5,2).Text= "办公电话"
rt.Cells(
5,3).Text = CurRow("办公电话")
rt.Cells(
6,0).Text = CurRow("备注")


rt.Cells(
0,4).Image = GetImage(CurRow("照片"))
doc.Body.Children.Add(rt) 
'将表格对象加入到报表中
Doc.Preview() 
'预览报表


这里的照片,如果是一个PDF文件,可以吗?

 回到顶部
帅哥哟,离线,有人找我吗?
keli0917
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:276 积分:2600 威望:0 精华:0 注册:2018/5/21 16:49:00
  发帖心情 Post By:2024/7/29 14:02:00 [显示全部帖子]

https://www.cnblogs.com/ywtk/p/3429377.html
这个引用Acrpbat.DLL转换图片的方法,能在FOXTABLE中使用吗?
本机已经安装Adobe Acrobat ,并正常使用。

1.引用Adobe Acrobat安装目录下的: Acrobat.dll 
2.将C#代码,转换成VB.NET。在FOXTABLE的全局代码里写

Public Shared Sub ConvertPDF2Image(ByVal pdfInputPath As String, ByVal imageOutputPath As String, ByVal imageName As String, ByVal startPageNum As Integer, ByVal endPageNum As Integer, ByVal imageFormat As ImageFormat, ByVal resolution As Double)
    Dim pdfDoc As Acrobat.CAcroPDDoc = Nothing
    Dim pdfPage As Acrobat.CAcroPDPage = Nothing
    Dim pdfRect As Acrobat.CAcroRect = Nothing
    Dim pdfPoint As Acrobat.CAcroPoint = Nothing
    pdfDoc = CType(Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.PDDoc", ""), Acrobat.CAcroPDDoc)

    If Not pdfDoc.Open(pdfInputPath) Then
        Throw New FileNotFoundException()
    End If

    If Not Directory.Exists(imageOutputPath) Then
        Directory.CreateDirectory(imageOutputPath)
    End If

    If startPageNum <= 0 Then
        startPageNum = 1
    End If

    If endPageNum > pdfDoc.GetNumPages() OrElse endPageNum <= 0 Then
        endPageNum = pdfDoc.GetNumPages()
    End If

    If startPageNum > endPageNum Then
        Dim tempPageNum As Integer = startPageNum
        startPageNum = endPageNum
        endPageNum = startPageNum
    End If

    If imageFormat Is Nothing Then
        imageFormat = ImageFormat.Jpeg
    End If

    If resolution <= 0 Then
        resolution = 1
    End If

    For i As Integer = startPageNum To endPageNum
        pdfPage = CType(pdfDoc.AcquirePage(i - 1), Acrobat.CAcroPDPage)
        pdfPoint = CType(pdfPage.GetSize(), Acrobat.CAcroPoint)
        pdfRect = CType(Microsoft.VisualBasic.Interaction.CreateObject("AcroExch.Rect", ""), Acrobat.CAcroRect)
        Dim imgWidth As Integer = CInt((CDbl(pdfPoint.x) * resolution))
        Dim imgHeight As Integer = CInt((CDbl(pdfPoint.y) * resolution))
        pdfRect.Left = 0
        pdfRect.right = CShort(imgWidth)
        pdfRect.Top = 0
        pdfRect.bottom = CShort(imgHeight)
        pdfPage.CopyToClipboard(pdfRect, 0, 0, CShort((100 * resolution)))
        Dim clipboardData As IDataObject = Clipboard.GetDataObject()

        If clipboardData.GetDataPresent(DataFormats.Bitmap) Then
            Dim pdfBitmap As Bitmap = CType(clipboardData.GetData(DataFormats.Bitmap), Bitmap)
            pdfBitmap.Save(Path.Combine(imageOutputPath, imageName) & ".jpg", imageFormat)
            pdfBitmap.Dispose()
        End If
    Next

    pdfDoc.Close()
    Marshal.ReleaseComObject(pdfPage)
    Marshal.ReleaseComObject(pdfRect)
    Marshal.ReleaseComObject(pdfDoc)
    Marshal.ReleaseComObject(pdfPoint)
End Sub

到全局代码这步点确定提示:

编译错误:无法加载引用的库”C:\foxtable\Normal\Acrobat.dl”.试图加载格式
不正确的程序。



[此贴子已经被作者于2024/7/29 14:03:07编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
keli0917
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:276 积分:2600 威望:0 精华:0 注册:2018/5/21 16:49:00
  发帖心情 Post By:2024/7/29 14:04:00 [显示全部帖子]

我已经把Acrobat.dl复制到C:\foxtable\Normal\Acrobat.dl

 回到顶部
帅哥哟,离线,有人找我吗?
keli0917
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:276 积分:2600 威望:0 精华:0 注册:2018/5/21 16:49:00
  发帖心情 Post By:2024/7/29 14:10:00 [显示全部帖子]

是不是,Microsoft.CSharp.dll和Microsoft.VisualBasic.dll也要添加引用?

 回到顶部
帅哥哟,离线,有人找我吗?
keli0917
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:276 积分:2600 威望:0 精华:0 注册:2018/5/21 16:49:00
  发帖心情 Post By:2024/7/29 19:53:00 [显示全部帖子]

https://www.cnblogs.com/ywtk/p/3291034.html


Public  Function PDFToImg(ByVal pdfFile As String, ByVal imgPath As String) As Integer
    Dim doc As PDFFile = PDFFile.Open(pdfFile)
    Dim pageCount As Integer = doc.PageCount
    Dim pdfFileName As String = Path.GetFileName(pdfFile)
    Dim imgFile As String = Path.Combine(imgPath, "page")
    If pageCount = 0 Then Return 0

    If pageCount = 1 Then
        imgFile += ".jpg"

        If File.Exists(imgFile) Then
            File.Delete(imgFile)
        End If
    Else

        For i As Integer = 0 To pageCount - 1
            Dim _imgFile As String = imgFile & (i).ToString() & ".jpg"

            If File.Exists(_imgFile) Then
                File.Delete(_imgFile)
            End If
        Next

        imgFile += "%d.jpg"
    End If

    Dim prc As Process = New Process()
    prc.StartInfo.UseShellExecute = False
    prc.StartInfo.CreateNoWindow = True
    prc.EnableRaisingEvents = True
    prc.Exited += New EventHandler(prc_Exited)
    prc.StartInfo.Arguments = "-dSAFER -dBATCH -dNOPAUSE -r150 -sDEVICE=jpeg -dGraphicsAlphaBits=4" & " -sOutputFile=" & imgFile & "  " & pdfFile
    prc.StartInfo.FileName = "C:\Program Files\gs\gs9.06\bin\gswin32.exe"
    prc.Start()
    Return pageCount
End Function


上面这个代码修改一下能在FOXTABLE中使用吗?可以的话帮忙修改一下咯。
我已经安装并在WINDOW的命令行下调试成功。

 回到顶部
帅哥哟,离线,有人找我吗?
keli0917
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:276 积分:2600 威望:0 精华:0 注册:2018/5/21 16:49:00
  发帖心情 Post By:2024/7/29 21:00:00 [显示全部帖子]

搞定了。写一个函数调用外部程序就可以。

 回到顶部