如何在vb.net中计算pdf页面的行数? [英] How can i count the rows of a page on pdf in vb.net?

查看:216
本文介绍了如何在vb.net中计算pdf页面的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算pdf中的行数和页面数吗?
我的pdf是动态生成的
请帮助我
这些代码是我的代码的一部分

i want to count the rows of page and count of page in pdf?
my pdf generated dynamicly
please help me
these code is part of my code

Dim buffer As [Byte]() = util.createPDF(title.Text, header, array)

       Response.ClearContent()
       Response.AddHeader("content-disposition", "attachment; filename=test.pdf")
       Response.ContentType = "application/pdf"
       Response.OutputStream.Write(buffer, 0, buffer.Length)
       Response.OutputStream.Flush()

       Response.OutputStream.Close()

       Response.[End]()

推荐答案

.Net本身不提供与PDF文档进行交互的任何API.
您正在使用哪个库来创建PDF(实用程序).如果它们提供了返回页数的任何方法,则可能需要查看其文档.
.Net on its own does not provide any API to interact with PDF documents.
Which library are you using to create PDF (util?). You might want to look into its documentation if they provide any method whic returns the number of pages.


是cls util和dll itextsharp
这是我的代码
公共类ClsUtils
继承PdfPageEventHelper

公共函数createPDF(ByVal标题为[String],ByVal标头为[String](),ByVal列表为ArrayList)作为Byte()
FontFactory.RegisterDirectory("C:\ WINDOWS \ Fonts")
昏暗的文档作为新文档
昏暗的流作为新的MemoryStream
Dim writer As PdfWriter = PdfWriter.GetInstance(doc,stream)
doc.Open()
writer.PageEvent = Me
暗淡的titleFont作为iTextSharp.text.Font = FontFactory.GetFont("Tahoma",BaseFont.IDENTITY_H,8,iTextSharp.text.Font.BOLD,iTextSharp.text.Color.BLACK)
作为新的ColumnText(writer.DirectContent)变暗
ct.R​​unDirection = PdfWriter.RUN_DIRECTION_RTL
ct.SetSimpleColumn(20、5、400、830)
ct.AddText(新词组(标题,标题字体))
ct.Go()

昏暗的headerFont作为iTextSharp.text.Font = FontFactory.GetFont("Tahoma",BaseFont.IDENTITY_H,8,iTextSharp.text.Font.BOLD,iTextSharp.text.Color.BLACK)
Dim detailsFont as iTextSharp.text.Font = FontFactory.GetFont("Tahoma",BaseFont.IDENTITY_H,7,iTextSharp.text.Font.NORMAL,iTextSharp.text.Color.BLACK)
将Dim表作为新的PdfPTable(DirectCast(list(0),[String]()).Length)
table.RunDirection = PdfWriter.RUN_DIRECTION_RTL
addRowToPdfTable(标题,表格,headerFont)
对于i As Integer = 0列出-计数-1
Dim r As [String]()= DirectCast(list(i),[String]())
addRowToPdfTable(r,table,detailsFont)
下一个
doc.Add(表格)
doc.Close()
昏暗的缓冲区为Byte()= stream.GetBuffer()
stream.Close()
返回缓冲区
最终功能
受保护的子addRowToPdfTable(ByVal行为[String](),ByVal pdfTable为PdfPTable,ByVal字体为iTextSharp.text.Font)
昏暗的pdfCell作为新的PdfPCell
pdfCell.RunDirection = PdfWriter.RUN_DIRECTION_RTL
''以相反的顺序添加单元格作为解决带有RTL表的iTextSharp错误的解决方法
对于i As Integer = row.Length-1到0步骤-1
pdfCell.Phrase =新短语(row(i),字体)
pdfTable.AddCell(pdfCell)
下一个
结束子
公共重载重写Sub OnEndPage(ByVal writer作为PdfWriter,ByVal document作为Document)
如果document.PageNumber = 1,则
返回
如果结束
昏暗的headerFont作为iTextSharp.text.Font = FontFactory.GetFont("Tahoma",BaseFont.IDENTITY_H,8,iTextSharp.text.Font.BOLD,iTextSharp.text.Color.BLACK)
暗淡的titleFont作为iTextSharp.text.Font = FontFactory.GetFont("Tahoma",BaseFont.IDENTITY_H,8,iTextSharp.text.Font.BOLD,iTextSharp.text.Color.BLACK)
作为新的ColumnText(writer.DirectContent)变暗
ct.R​​unDirection = PdfWriter.RUN_DIRECTION_RTL
ct.SetSimpleColumn(20、5、400、830)
ct.AddText(New Phrase("header",titleFont))
ct.Go()

结束子

结束类
yes cls util and the dll itextsharp
this is my code
Public Class ClsUtils
Inherits PdfPageEventHelper

Public Function createPDF(ByVal Title As [String], ByVal header As [String](), ByVal list As ArrayList) As Byte()
FontFactory.RegisterDirectory("C:\WINDOWS\Fonts")
Dim doc As New Document
Dim stream As New MemoryStream
Dim writer As PdfWriter = PdfWriter.GetInstance(doc, stream)
doc.Open()
writer.PageEvent = Me
Dim titleFont As iTextSharp.text.Font = FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)
Dim ct As New ColumnText(writer.DirectContent)
ct.RunDirection = PdfWriter.RUN_DIRECTION_RTL
ct.SetSimpleColumn(20, 5, 400, 830)
ct.AddText(New Phrase(Title, titleFont))
ct.Go()

Dim headerFont As iTextSharp.text.Font = FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)
Dim detailsFont As iTextSharp.text.Font = FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 7, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.BLACK)
Dim table As New PdfPTable(DirectCast(list(0), [String]()).Length)
table.RunDirection = PdfWriter.RUN_DIRECTION_RTL
addRowToPdfTable(header, table, headerFont)
For i As Integer = 0 To list.Count - 1
Dim r As [String]() = DirectCast(list(i), [String]())
addRowToPdfTable(r, table, detailsFont)
Next
doc.Add(table)
doc.Close()
Dim buffer As Byte() = stream.GetBuffer()
stream.Close()
Return buffer
End Function
Protected Sub addRowToPdfTable(ByVal row As [String](), ByVal pdfTable As PdfPTable, ByVal font As iTextSharp.text.Font)
Dim pdfCell As New PdfPCell
pdfCell.RunDirection = PdfWriter.RUN_DIRECTION_RTL
'' add cells in reverse order as a workaround for iTextSharp bug with RTL tables
For i As Integer = row.Length - 1 To 0 Step -1
pdfCell.Phrase = New Phrase(row(i), font)
pdfTable.AddCell(pdfCell)
Next
End Sub
Public Overloads Overrides Sub OnEndPage(ByVal writer As PdfWriter, ByVal document As Document)
If document.PageNumber = 1 Then
Return
End If
Dim headerFont As iTextSharp.text.Font = FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)
Dim titleFont As iTextSharp.text.Font = FontFactory.GetFont("Tahoma", BaseFont.IDENTITY_H, 8, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)
Dim ct As New ColumnText(writer.DirectContent)
ct.RunDirection = PdfWriter.RUN_DIRECTION_RTL
ct.SetSimpleColumn(20, 5, 400, 830)
ct.AddText(New Phrase("header", titleFont))
ct.Go()

End Sub

End Class


这篇关于如何在vb.net中计算pdf页面的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆