2011-09-08 4 views
2

ITextSharp가 JAVA2D 클래스를 지원하지 않는다고 들었습니다. 즉, 클라이언트 데이터베이스에서 벡터 포인트를 가져와 ITextSharp 응용 프로그램에 "인쇄"할 수 없습니까?벡터 그래픽 (ITextSharp 포함)

나는이 제안을 계속하기 전에 이에 대한 답을 찾고 싶다. 누구나 실제 경험이 있습니까?

답변

2

iTextSharp와 함께 JAVA2D를 사용할 수없는 경우에도 PdfWriter.DirectContent 객체에 직접 작성하여 PDF 그래픽 방식으로 벡터 그래픽을 그릴 수 있습니다. 그것은 벡터 드로잉 프로그램에서 기대할 수있는 표준 MoveTo(), LineTo(), CurveTo() 등의 모든 메소드를 지원합니다. 아래는 iTextSharp 5.1.1.0을 목표로하는 풀 동작 VB.Net WinForms 앱입니다.

Option Explicit On 
Option Strict On 

Imports iTextSharp.text 
Imports iTextSharp.text.pdf 
Imports System.IO 

Public Class Form1 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     Dim OutputFile As String = Path.Combine(My.Computer.FileSystem.SpecialDirectories.Desktop, "VectorTest.pdf") 

     Using FS As New FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None) 
      Using Doc As New Document(PageSize.LETTER) 
       Using writer = PdfWriter.GetInstance(Doc, FS) 
        ''//Open the PDF for writing 
        Doc.Open() 

        Dim cb As PdfContentByte = writer.DirectContent 

        ''//Save the current state so that we can restore it later. This is not required but it makes it easier to undo things later 
        cb.SaveState() 

        ''//Draw a line with a bunch of options set 
        cb.MoveTo(100, 100) 
        cb.LineTo(500, 500) 
        cb.SetRGBColorStroke(255, 0, 0) 
        cb.SetLineWidth(5) 
        cb.SetLineDash(10, 10, 20) 
        cb.SetLineCap(PdfContentByte.LINE_CAP_ROUND) 
        cb.Stroke() 

        ''//This undoes any of the colors, widths, etc that we did since the last SaveState 
        cb.RestoreState() 

        ''//Draw a circle 
        cb.SaveState() 
        cb.Circle(200, 500, 50) 
        cb.SetRGBColorStroke(0, 255, 0) 
        cb.Stroke() 

        ''//Draw a bezier curve 
        cb.RestoreState() 
        cb.MoveTo(100, 300) 
        cb.CurveTo(140, 160, 300, 300) 
        cb.SetRGBColorStroke(0, 0, 255) 
        cb.Stroke() 

        ''//Close the PDF 
        Doc.Close() 
       End Using 
      End Using 
     End Using 
    End Sub 
End Class 

편집 덧붙여

, 당신은 당신이 표준 System.Drawing.Image 클래스를 사용하고 그것을 전달하는 이미지를 iTextSharp 만들 수 있습니다 Java2D에 사용할 수 없습니다 (분명히 자바이며, 닷넷과 함께 작동하지 않을 것입니다)하지만, 정적 방법으로 iTextSharp.text.Image.GetInstance(). 불행히도 System.Drawing.Image은 래스터/비트 맵 객체이므로이 경우에는 도움이되지 않습니다.

+0

좋은 예를 만들고 내 질문에 답해 주셔서 감사합니다. 내 일을 더 쉽게 해줄거야! 곧 ITextSharp를 사용할 예정입니다./R –

관련 문제