Imports System.Data.SqlClient
Imports ChartDirector
'iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
'iTextSharp.text.FontクラスがSystem.Drawing.Fontクラスと
'iFont
Imports iFont = iTextSharp.text.Font
Imports iImage = iTextSharp.text.Image
'
Imports System.IO
Imports System.Drawing
Imports System.Diagnostics
Private Sub makeDocument()
'
'PDF
Dim doc As Document = New Document(PageSize.A4)
Try
'
Response.Cache.SetCacheability(HttpCacheability.Public)
Response.Cache.SetExpires(DateTime.Now.AddSeconds(5))
Response.ContentType = "application/pdf"
Response.AddHeader("Content-disposition", "inline; filename=tmp.pdf")
'
PdfWriter.GetInstance(doc, Response.OutputStream)
'
Dim fontname As String = "msmincho.ttc,1"
'
Dim baseFont As BaseFont = baseFont.CreateFont(GetFontFullPath(fontname), baseFont.IDENTITY_H, baseFont.EMBEDDED)
'()
fnt = New iFont(baseFont, 9, iFont.NORMAL)
fntTitle = New iFont(baseFont, 14, iFont.NORMAL)
'Add a Header that will show up on PAGE 1
Dim header As HeaderFooter = New HeaderFooter(New Phrase("TITLE", fnt), False)
doc.Header = header
' doc.Open()
For i As Integer = 0 To UBound(Rid)
doc.NewPage()
'
Call Data(Rid(i))
Call Basic(doc)
Call PrintImages(doc)
Next i
Catch ex As Exception
'
Response.Clear()
Response.ContentType = "text/plain"
Response.Write("err" & vbCrLf & ex.ToString())
Finally
'
doc.Close()
End Try
Response.Flush()
Response.End()
End Sub
Private Function Basic() As Table
Dim inTable As New Table(4)
inTable.Width = 65
inTable.Alignment = Element.ALIGN_LEFT
inTable.Widths = New Single() {0.25F, 0.25F, 0.25F, 0.25F}
inTable.DefaultHorizontalAlignment = Element.ALIGN_LEFT
inTable.DefaultVerticalAlignment = Element.ALIGN_TOP
inTable.Padding = sngPadding
inTable.Spacing = sngSpacing
inTable.BorderColor = New iTextSharp.text.Color(0, 0, 0)
inTable.Border = 0
Dim cel As Cell
'cel = New Cell(New Phrase(inCellLeading, vbCrLf, fnt))
'cel.Colspan = 4
'cel.Border = 0
'inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, "単位(千円)", fnt))
cel.Colspan = 4
cel.Border = 0
cel.HorizontalAlignment = Element.ALIGN_RIGHT
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, 金", fnt))
cel.Border = 0
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, iAnnlYear(0) & "年", fnt))
cel.BackgroundColor = New iTextSharp.text.Color(192, 192, 192)
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, iAnnlYear(1) & "年", fnt))
cel.BackgroundColor = New iTextSharp.text.Color(192, 192, 192)
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, iAnnlYear(2) & "年", fnt))
cel.BackgroundColor = New iTextSharp.text.Color(192, 192, 192)
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, "X金", fnt))
cel.BackgroundColor = New iTextSharp.text.Color(192, 192, 192)
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, asdf(a(0), "##,##0"), fnt))
cel.HorizontalAlignment = Element.ALIGN_RIGHT
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, asdf(a(1), "##,##0"), fnt))
cel.HorizontalAlignment = Element.ALIGN_RIGHT
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, asdf(a(2), "##,##0"), fnt))
cel.HorizontalAlignment = Element.ALIGN_RIGHT
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, "Y金", fnt))
cel.BackgroundColor = New iTextSharp.text.Color(192, 192, 192)
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, asdf(a(0), "##,##0"), fnt))
cel.HorizontalAlignment = Element.ALIGN_RIGHT
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, asdf(a(1), "##,##0"), fnt))
cel.HorizontalAlignment = Element.ALIGN_RIGHT
inTable.AddCell(cel)
cel = New Cell(New Phrase(inCellLeading, asdf(a(2), "##,##0"), fnt))
cel.HorizontalAlignment = Element.ALIGN_RIGHT
inTable.AddCell(cel)
Return inTable
End Function
Private Sub PrintImages(ByRef doc As Document, Optional ByVal ptyRid As Long = 0)
Dim scaleX As Single
Dim scaleY As Single
Dim positionX As Single
Dim positionY As Single
Dim innerWidth As Single
Dim imgOffset As Single '
innerWidth = 595 - (doc.LeftMargin + doc.RightMargin) 'A4サイズのPoints-
imgOffset = 5.0
Dim img As iImage
Dim graphFileName As String
graphFileName = "asdf/asdf .jpg"
img = iImage.GetInstance(graphFileName) '
'
scaleX = 595 - innerWidth * 0.65 - (doc.RightMargin + doc.LeftMargin) - imgOffset
scaleY = 300
img.ScaleToFit(scaleX, scaleY)
img.SetAbsolutePosition(595 - img.ScaledWidth - doc.RightMargin, 380) '
doc.Add(img)
File.Delete(graphFileName)
End Sub
Private Function CreateAssetsGraph() As String
Dim chartImage As System.Drawing.Image
' Create a XYChart object of size 250 x 250 pixels.
Dim c As XYChart = New XYChart(250, 250)
' Set the plotarea at (30, 20) and of size 200 x 200 pixels
c.setPlotArea(60, 30, 155, 170)
' Add a legend box at (45, 12) (top of the chart) using horizontal layout and 9
' pts msuigothic font Set the background and border color to Transparent.
c.addLegend(45, 15, False, "msuigothic", 7).setBackground(Chart.Transparent)
' Add a title to the chart using 9 pts msuigothic.
c.addTitle("", "msuigothic", 9, &H0)
' Set the y axis label format to nn
c.yAxis().setLabelFormat("{value}")
'Add a title to the y axis
c.yAxis().setTitle("", "msuigothic", 7, &H0)
c.yAxis().setTitlePos(8)
' Set the labels on the x axis
c.xAxis().setLabels(iAnnlYear)
'Add a title to the x axis
c.xAxis().setTitle("年", "msuigothic", 7, &H0)
c.xAxis().setTitlePos(6)
' Add a line layer to the chart
Dim layer As LineLayer = c.addLineLayer()
' Add the first line. Plot the points with a 7 pixel square symbol
layer.addDataSet(adata, &HFF4040, "a").setDataSymbol(Chart.SquareSymbol, 7)
' Add the second line. Plot the points with a 7 pixel diamond symbol
layer.addDataSet(bdata, &H40FF40, "b").setDataSymbol(Chart.DiamondSymbol, 7)
' Add the second line. Plot the points with a 7 pixel triangle symbol
layer.addDataSet(cdata, &H4040FF, "c").setDataSymbol(Chart.TriangleSymbol, 7)
' Enable data label on the data points. Set the label format to nn%.
' layer.setDataLabelFormat("{value|0}%")
' output the chart
Dim grpDir As String
grpDir = ConfigurationSettings.AppSettings("FilePath") & "/asdf/" & 1234& "/"
If Not Directory.Exists(grpDir) Then Directory.CreateDirectory(grpDir)
grpDir += "asdf.jpg"
chartImage = c.makeImage()
chartImage.Save(grpDir, Imaging.ImageFormat.Jpeg)
Return grpDir