Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 将打印文档转换为图像_Vb.net_Printdocument - Fatal编程技术网

Vb.net 将打印文档转换为图像

Vb.net 将打印文档转换为图像,vb.net,printdocument,Vb.net,Printdocument,在我的应用程序中,我创建了一个打印文档。现在我想将打印文档转换为图像 我该怎么做 在我使用像这样的编码之前。(如果有其他解决方案,请在图像中的每一行画一条线?易于将打印文档转换为图像) Dim printArea As RectangleF=新矩形F(0,0,13.6*mInch,21.1*mInch) '为指定的矩形创建bmp图像 将bm调整为新位图(Convert.ToInt32(数学地板(打印区域宽度)),Convert.ToInt32(数学地板(打印区域高度))) 'bm.SetPixe

在我的应用程序中,我创建了一个
打印文档
。现在我想将
打印文档
转换为
图像

我该怎么做

在我使用像这样的编码之前。(如果有其他解决方案,请在图像中的每一行画一条线?易于将打印文档转换为图像)

Dim printArea As RectangleF=新矩形F(0,0,13.6*mInch,21.1*mInch)
'为指定的矩形创建bmp图像
将bm调整为新位图(Convert.ToInt32(数学地板(打印区域宽度)),Convert.ToInt32(数学地板(打印区域高度)))
'bm.SetPixel(13.5*mInch,21*mInch,彩色,蓝色)
'创建bmp图像的图形
尺寸g作为图形=图形。从图像(bm)
如果是Rdr.Read,那么
g、 抽绳(黑色钢笔、0.4英寸、0.4英寸、13.5英寸、0.4英寸)
“底线
g、 抽绳(黑色钢笔、0.4英寸、21英寸、13.5英寸、21英寸)
"左边界线",
g、 抽绳(黑色钢笔,分带(0.4*mInch),分带(0.4*mInch),分带(0.4*mInch),分带(21*mInch))
"右边界线",
g、 抽绳(黑色钢笔、分带(13.5*mInch)、分带(0.4*mInch)、分带(13.5*mInch)、分带(21*mInch))
xTop=0.4
如果File.Exists(xPath)=True,则
g、 DrawImage(Image.FromFile(xPath)_
辛特(0.8*米奇)、辛特(0.7*米奇)、辛特(4.5*米奇)、辛特(1.5*米奇))
如果结束
'g.DrawString(“Gloier”,新字体(mTextFont.Name,mTextFont.Size+4,FontStyle.Bold+FontStyle.Italic,GraphicsUnit.Point),画笔.黑色,1.7*mInch,xTop*mInch)
xTop=1.7
drawRect=新矩形F(1*mInch,xTop*mInch,12.0*mInch,0.6*mInch)
g、 DrawString(“收据”、新字体(mTextFont.Name、mTextFont.Size+3、FontStyle.Bold+FontStyle.Italic、GraphicsUnit.Point)、Brush.Black、drawRect、xformat)
xTop=xTop+1.8
g、 抽绳(“编号”,mTextFont,画笔。黑色,8.5*mInch,xTop*mInch)
g、 抽绳(“:”,mTextFont,画笔。黑色,9.5*mInch,xTop*mInch)
g、 抽绳(Rdr.Item(“receiptno”)、新字体(mTextFont.Name、mTextFont.Size+2、FontStyle.Bold、GraphicsUnit.Point)、画笔。黑色、10.0*mInch、xTop*mInch)
xTop=xTop+0.8
g、 抽绳(“日期”,mTextFont,画笔。黑色,8.5*mInch,xTop*mInch)
g、 抽绳(“:”,mTextFont,画笔。黑色,9.5*mInch,xTop*mInch)
g、 抽绳(Rdr.Item(“edate”)、mTextFont、画笔。黑色、10.0*mInch、xTop*mInch)
''--Hr线路
xTop=xTop+1
g、 抽绳(黑色钢笔,扣(0.4*mInch),扣(xTop*mInch),扣(13.5*mInch),扣(xTop*mInch))
xTop=xTop+0.3
'xTop=6.1
g、 DrawString(“Account”,新字体(mTextFont.Name,mTextFont.Size,FontStyle.Bold,GraphicsUnit.Point),画笔.黑色,0.7*mInch,xTop*mInch)
xTop=xTop+0.7
''--Hr线路
g、 抽绳(黑色钢笔,扣(0.4*mInch),扣(xTop*mInch),扣(13.5*mInch),扣(xTop*mInch))
xTop=xTop+0.3
drawRect=新矩形F(0.7*mInch,xTop*mInch,11.5*mInch,0.8*mInch)
g、 DrawString(Rdr.Item(“称呼”)&“&Rdr.Item(“partyname”)、新字体(mTextFont.Name、mTextFont.Size、FontStyle.Bold、GraphicsUnit.Point)、画笔.黑色、drawRect)
如果(关系项(“称呼”)和“&关系项(“partyname”))。长度>80,则
xTop=xTop+(0.5*2)
其他的
xTop=xTop+0.5
如果结束
Dim X长度为整数
如果(Rdr.Item(“门号”)和“,”和Rdr.Item(“街道名称”)).ToString.Length>80,则xLength=80,否则xLength=(Rdr.Item(“门号”)和“,”和Rdr.Item(“街道名称”).ToString.Length-1
g、 抽绳((Rdr.Item(“doorno”)和“,”和Rdr.Item(“streetname”))。ToString.Substring(0,x长度),mTextFont,画笔。黑色,0.7*mInch,xTop*mInch)
xTop=xTop+0.5
如果(Rdr.Item(“区域”)和“,”和Rdr.Item(“城市”)).ToString.Length>80,则xLength=80,否则xLength=(Rdr.Item(“区域”)和“,”和Rdr.Item(“城市”).ToString.Length-1
g、 抽绳((Rdr.Item(“area”)和“,”和Rdr.Item(“city”))。ToString.Substring(0,X长度),mTextFont,画笔。黑色,0.7*mInch,xTop*mInch)
如果不修剪(Rdr.Item(“备注”))=String.Empty,则
xTop=xTop+0.6
xformat.Alignment=StringAlignment.Near
drawRect=新矩形F(0.7*mInch,xTop*mInch,11.5*mInch,2.0*mInch)
g、 抽绳(Rdr.Item(“备注”)、mTextFont、Brush.Black、drawRect)
如果结束
xTop=10.5
g、 抽绳(“模式”,mTextFont,画笔。黑色,0.7*mInch,xTop*mInch)
g、 抽绳(“:”,mTextFont,画笔。黑色,4.5*mInch,xTop*mInch)
g、 抽绳(Rdr.Item(“transtype”)、新字体(mTextFont.Name、mTextFont.Size、FontStyle.Bold、GraphicsUnit.Point)、画笔.黑色、4.8*mInch、xTop*mInch)
如果不是Rdr.Item(“transtype”).ToString.ToUpper.Trim=“现金”,则
xTop=xTop+0.5
g、 抽绳(“事务参考号”,mTextFont,画笔。黑色,0.7*mInch,xTop*mInch)
g、 抽绳(“:”,mTextFont,画笔。黑色,4.5*mInch,xTop*mInch)
g、 抽绳(Rdr.Item(“transrefno”)、mTextFont、画笔。黑色、4.8*mInch、xTop*mInch)
xTop=xTop+0.5
g、 抽绳(“交易参考日期”,mTextFon
  Dim printArea As RectangleF = New RectangleF(0, 0, 13.6 * mInch, 21.1 * mInch)
            'create a bmp image for specified rectangle
            Dim bm As New Bitmap(Convert.ToInt32(Math.Floor(printArea.Width)), Convert.ToInt32(Math.Floor(printArea.Height)))
            'bm.SetPixel(13.5 * mInch, 21 * mInch, Color.Blue)
            'create the graphics of bmp image 
            Dim g As Graphics = Graphics.FromImage(bm)

            If Rdr.Read Then

                g.DrawLine(Pens.Black, CInt(0.4 * mInch), CInt(0.4 * mInch), CInt(13.5 * mInch), CInt(0.4 * mInch))

                'Bottom border line
                g.DrawLine(Pens.Black, CInt(0.4 * mInch), CInt(21 * mInch), CInt(13.5 * mInch), CInt(21 * mInch))

                'Left border line
                g.DrawLine(Pens.Black, CInt(0.4 * mInch), CInt(0.4 * mInch), CInt(0.4 * mInch), CInt(21 * mInch))

                'Right border line
                g.DrawLine(Pens.Black, CInt(13.5 * mInch), CInt(0.4 * mInch), CInt(13.5 * mInch), CInt(21 * mInch))

                xTop = 0.4

                If File.Exists(xPath) = True Then
                    g.DrawImage(Image.FromFile(xPath), _
                             CInt(0.8 * mInch), CInt(0.7 * mInch), CInt(4.5 * mInch), CInt(1.5 * mInch))
                End If

                ' g.DrawString("Gloier", New Font(mTextFont.Name, mTextFont.Size + 4, FontStyle.Bold + FontStyle.Italic, GraphicsUnit.Point), Brushes.Black, 1.7 * mInch, xTop * mInch)

                xTop = 1.7

                drawRect = New RectangleF(1 * mInch, xTop * mInch, 12.0 * mInch, 0.6 * mInch)
                g.DrawString("RECEIPT", New Font(mTextFont.Name, mTextFont.Size + 3, FontStyle.Bold + FontStyle.Italic, GraphicsUnit.Point), Brushes.Black, drawRect, xformat)

                xTop = xTop + 1.8
                g.DrawString("No.", mTextFont, Brushes.Black, 8.5 * mInch, xTop * mInch)
                g.DrawString(":", mTextFont, Brushes.Black, 9.5 * mInch, xTop * mInch)
                g.DrawString(Rdr.Item("receiptno"), New Font(mTextFont.Name, mTextFont.Size + 2, FontStyle.Bold, GraphicsUnit.Point), Brushes.Black, 10.0 * mInch, xTop * mInch)
                xTop = xTop + 0.8
                g.DrawString("Date", mTextFont, Brushes.Black, 8.5 * mInch, xTop * mInch)
                g.DrawString(":", mTextFont, Brushes.Black, 9.5 * mInch, xTop * mInch)
                g.DrawString(Rdr.Item("edate"), mTextFont, Brushes.Black, 10.0 * mInch, xTop * mInch)

                ''---Hr.Line
                xTop = xTop + 1
                g.DrawLine(Pens.Black, CInt(0.4 * mInch), CInt(xTop * mInch), CInt(13.5 * mInch), CInt(xTop * mInch))

                xTop = xTop + 0.3
                'xTop = 6.1
                g.DrawString("Account", New Font(mTextFont.Name, mTextFont.Size, FontStyle.Bold, GraphicsUnit.Point), Brushes.Black, 0.7 * mInch, xTop * mInch)

                xTop = xTop + 0.7
                ''---Hr.Line
                g.DrawLine(Pens.Black, CInt(0.4 * mInch), CInt(xTop * mInch), CInt(13.5 * mInch), CInt(xTop * mInch))

                xTop = xTop + 0.3

                drawRect = New RectangleF(0.7 * mInch, xTop * mInch, 11.5 * mInch, 0.8 * mInch)
                g.DrawString(Rdr.Item("salutation") & " " & Rdr.Item("partyname"), New Font(mTextFont.Name, mTextFont.Size, FontStyle.Bold, GraphicsUnit.Point), Brushes.Black, drawRect)

                If (Rdr.Item("salutation") & " " & Rdr.Item("partyname")).Length > 80 Then
                    xTop = xTop + (0.5 * 2)
                Else
                    xTop = xTop + 0.5
                End If

                Dim xLength As Integer
                If (Rdr.Item("doorno") & "," & Rdr.Item("streetname")).ToString.Length > 80 Then xLength = 80 Else xLength = (Rdr.Item("doorno") & "," & Rdr.Item("streetname")).ToString.Length - 1

                g.DrawString((Rdr.Item("doorno") & "," & Rdr.Item("streetname")).ToString.Substring(0, xLength), mTextFont, Brushes.Black, 0.7 * mInch, xTop * mInch)

                xTop = xTop + 0.5
                If (Rdr.Item("area") & "," & Rdr.Item("city")).ToString.Length > 80 Then xLength = 80 Else xLength = (Rdr.Item("area") & "," & Rdr.Item("city")).ToString.Length - 1
                g.DrawString((Rdr.Item("area") & "," & Rdr.Item("city")).ToString.Substring(0, xLength), mTextFont, Brushes.Black, 0.7 * mInch, xTop * mInch)


                If Not Trim(Rdr.Item("remarks")) = String.Empty Then
                    xTop = xTop + 0.6
                    xformat.Alignment = StringAlignment.Near
                    drawRect = New RectangleF(0.7 * mInch, xTop * mInch, 11.5 * mInch, 2.0 * mInch)
                    g.DrawString(Rdr.Item("remarks"), mTextFont, Brushes.Black, drawRect)
                End If

                xTop = 10.5
                g.DrawString("Mode", mTextFont, Brushes.Black, 0.7 * mInch, xTop * mInch)
                g.DrawString(":", mTextFont, Brushes.Black, 4.5 * mInch, xTop * mInch)
                g.DrawString(Rdr.Item("transtype"), New Font(mTextFont.Name, mTextFont.Size, FontStyle.Bold, GraphicsUnit.Point), Brushes.Black, 4.8 * mInch, xTop * mInch)

                If Not Rdr.Item("transtype").ToString.ToUpper.Trim = "CASH" Then
                    xTop = xTop + 0.5
                    g.DrawString("Transaction Ref.No.", mTextFont, Brushes.Black, 0.7 * mInch, xTop * mInch)
                    g.DrawString(":", mTextFont, Brushes.Black, 4.5 * mInch, xTop * mInch)
                    g.DrawString(Rdr.Item("transrefno"), mTextFont, Brushes.Black, 4.8 * mInch, xTop * mInch)

                    xTop = xTop + 0.5
                    g.DrawString("Transaction Ref.Date", mTextFont, Brushes.Black, 0.7 * mInch, xTop * mInch)
                    g.DrawString(":", mTextFont, Brushes.Black, 4.5 * mInch, xTop * mInch)
                    g.DrawString(Rdr.Item("transrefdate"), mTextFont, Brushes.Black, 4.8 * mInch, xTop * mInch)

                    If Not Rdr.Item("bankname").ToString.Trim = String.Empty Then
                        xTop = xTop + 0.5
                        g.DrawString("Bank Name", mTextFont, Brushes.Black, 0.7 * mInch, xTop * mInch)
                        g.DrawString(":", mTextFont, Brushes.Black, 4.5 * mInch, xTop * mInch)
                        g.DrawString(Rdr.Item("bankname"), mTextFont, Brushes.Black, 4.8 * mInch, xTop * mInch)
                    End If

                End If

                xTop = 12.5
                ''---Hr.Line
                g.DrawLine(Pens.Black, CInt(0.4 * mInch), CInt(xTop * mInch), CInt(13.5 * mInch), CInt(xTop * mInch))

                xTop = xTop + 0.2

                g.DrawString("AMOUNT : " & ShareVarProfile2.Currency1, New Font(mTextFont.Name, mTextFont.Size, FontStyle.Bold, GraphicsUnit.Point), Brushes.Black, 8.5 * mInch, xTop * mInch)

                drawRect = New RectangleF(11.3 * mInch, (xTop - 0.05) * mInch, 3 * mInch, 0.4 * mInch)
                xformat.Alignment = StringAlignment.Far
                g.DrawString(Format(Rdr.Item("rcvdamount"), ShareVarProfile2.DecimalFormatAmt), New Font(mTextFont.Name, mTextFont.Size + 1, FontStyle.Bold, GraphicsUnit.Point), Brushes.Black, drawRect, xformat)
                '       
                xTop = xTop + 0.7
                ''---Hr.Line

                g.DrawLine(Pens.Black, CInt(0.4 * mInch), CInt(xTop * mInch), CInt(13.5 * mInch), CInt(xTop * mInch))

                xTop = xTop + 0.75

                xformat.Alignment = StringAlignment.Near
                xformat.FormatFlags = StringFormatFlags.NoClip
                drawRect = New RectangleF(0.7 * mInch, xTop * mInch, 12 * mInch, 0.8 * mInch)
                g.DrawString("Received " & OwnFunctions.RsInWords(Rdr.Item("rcvdamount")), New Font(mTextFont.Name, mTextFont.Size, FontStyle.Italic), Brushes.Black, drawRect, xformat)


                If Rdr.Item("transtype").ToString.Trim.ToUpper = "CHEQUE" Then
                    xTop = xTop + 1.5
                    g.DrawString("Note : Cheque Subject to Jurisdiction in Tirunelveli only.", New Font(mTextFont.Name, mTextFont.Size - 1, GraphicsUnit.Point), Brushes.Black, 0.7 * mInch, xTop * mInch)
                End If

                g.DrawString("For " & ShareVarProfile2.CompName, mTextFont, Brushes.Black, 10.5 * mInch, 17.8 * mInch)

                g.DrawString("Party Signature With Seal", mTextFont, Brushes.Black, 0.7 * mInch, 17.8 * mInch)

                g.DrawString(mRcptSign, mTextFont, Brushes.Black, 0.7 * mInch, 17.3 * mInch)

                xformat.Alignment = StringAlignment.Center
                drawRect = New RectangleF(1 * mInch, 18.2 * mInch, 11.8 * mInch, 0.8 * mInch)
                g.DrawString(mRcptFooter, New Font(mTextFont.Name, mTextFont.Size - 2, GraphicsUnit.Point), Brushes.Black, drawRect, xformat)

                xTop = 18.8

                Dim xAddress As String = String.Empty

                If ShareVarProfile2.Address1 <> String.Empty And ShareVarProfile2.Address2 <> String.Empty Then
                    xAddress = ShareVarProfile2.Address1 & ", " & ShareVarProfile2.Address2 & " | "
                ElseIf ShareVarProfile2.Address1 <> String.Empty Then
                    xAddress = ShareVarProfile2.Address1 & " | "
                Else
                    xAddress = ShareVarProfile2.Address2 & " | "
                End If

                If ShareVarProfile2.Address3 <> String.Empty Then
                    xAddress += ShareVarProfile2.Address3 & " | "
                End If

                If ShareVarProfile2.Area <> String.Empty Then
                    xAddress += ShareVarProfile2.Area & " | "
                End If

                If ShareVarProfile2.District <> String.Empty Then
                    xAddress += ShareVarProfile2.District & " | "
                End If

                If ShareVarProfile2.State <> String.Empty Then
                    xAddress += ShareVarProfile2.State & " | "
                End If

                If ShareVarProfile2.PinCode <> String.Empty Then
                    xAddress += ShareVarProfile2.PinCode
                End If

                If xAddress <> String.Empty Then If xAddress.Substring(xAddress.Length - 1, 1) = "|" Then xAddress = xAddress.Remove(xAddress.Length - 1, 1)

                xformat.Alignment = StringAlignment.Far
                drawRect = New RectangleF(1 * mInch, xTop * mInch, 11.8 * mInch, 0.4 * mInch)
                If xAddress <> String.Empty Then
                    g.DrawString(xAddress, New Font(mTextFont.Name, mTextFont.Size - 3, GraphicsUnit.Point), Brushes.Black, drawRect, xformat)
                    xTop += 0.4
                End If

                Dim xEmailWeb As String = String.Empty

                If ShareVarProfile2.EMail <> String.Empty And ShareVarProfile2.WebSite <> String.Empty Then
                    xEmailWeb = ShareVarProfile2.EMail & " | " & ShareVarProfile2.WebSite
                ElseIf ShareVarProfile2.EMail <> String.Empty Then
                    xEmailWeb = ShareVarProfile2.EMail
                Else
                    xEmailWeb = ShareVarProfile2.WebSite
                End If

                drawRect = New RectangleF(1 * mInch, xTop * mInch, 11.8 * mInch, 0.4 * mInch)
                If xEmailWeb <> String.Empty Then
                    g.DrawString(xEmailWeb, New Font(mTextFont.Name, mTextFont.Size - 3, GraphicsUnit.Point), Brushes.Black, drawRect, xformat)
                    xTop += 0.4
                End If

                Dim xTinCst As String = String.Empty

                If ShareVarProfile2.StaturyNo1 <> String.Empty And ShareVarProfile2.StaturyNo2 <> String.Empty Then
                    xTinCst = "TIN : " & ShareVarProfile2.EMail & " | CST No.: " & ShareVarProfile2.StaturyNo2
                ElseIf ShareVarProfile2.StaturyNo1 <> String.Empty Then
                    xTinCst = "TIN : " & ShareVarProfile2.StaturyNo1
                Else
                    xTinCst = "CST No.: " & ShareVarProfile2.StaturyNo2
                End If

                drawRect = New RectangleF(1 * mInch, xTop * mInch, 11.8 * mInch, 0.4 * mInch)
                If xTinCst <> String.Empty Then
                    g.DrawString(xTinCst, New Font(mTextFont.Name, mTextFont.Size - 3, GraphicsUnit.Point), Brushes.Black, drawRect, xformat)
                    xTop += 0.4
                End If

                xTop = 20
                ''---Hr.Line
                g.DrawLine(Pens.Black, CInt(0.4 * mInch), CInt(xTop * mInch), CInt(13.5 * mInch), CInt(xTop * mInch))

                xTop += 0.3
                g.DrawString("UNBEATABLE QUALITY", New Font(mTextFont.Name, mTextFont.Size + 2, GraphicsUnit.Point), Brushes.Black, 1 * mInch, xTop * mInch)

                drawRect = New RectangleF(6 * mInch, xTop * mInch, 7.5 * mInch, 0.8 * mInch)
                g.DrawString(ShareVarProfile2.PhoneNo, New Font(mTextFont.Name, mTextFont.Size + 2, GraphicsUnit.Point), Brushes.Black, drawRect, xformat)


            End If

            Rdr.Close()

            bm.Save(Application.StartupPath & "\Documents\Receipt" & Val(xSplitReciptTmNo(0)) & ".bmp")