我做了'进口' - 错误类型预期 [英] I did an 'imports' - error TYPE EXPECTED

查看:123
本文介绍了我做了'进口' - 错误类型预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做了:

Imports iTextSharp.text.rtf

然后这个:

Dim grx As graphic = New graphic

在第一个图形上我得到预期类型

and on the first "graphic" I am getting a "type expected"

graphic是iTextSharp.text.rtf的成员

graphic is a member of iTextSharp.text.rtf

这是周围的代码:

Public Sub New1()
    Console.WriteLine("Chapter 4 example 4: Simple Graphic")
    Dim document As Document = New Document
    Try
        PdfWriter.GetInstance(document, New FileStream("Chap0404.pdf", FileMode.Create))
        document.Open()
        Dim grx As graphic = New graphic
        grx.Rectangle(100, 700, 100, 100)
        grx.MoveTo(100, 700)
        grx.LineTo(200, 800)
        grx.Stroke()
        document.Add(grx)
    Catch de As DocumentException
        Console.Error.WriteLine(de.Message)
    Catch ioe As IOException
        Console.Error.WriteLine(ioe.Message)
    End Try
    document.Close()
End Sub

以下是整个教程:(对不起它不是教程,但这就是他们所说的)

Here's the entire tutorial: (sorry its not a tutorial but thats what they call it)

Imports System
Imports System.IO
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Namespace iTextSharp.tutorial.Chap04

Public Class Chap0404

    Public Sub New()
        Console.WriteLine("Chapter 4 example 4: Simple Graphic")
        Dim document As Document = New Document
        Try
            PdfWriter.GetInstance(document, New FileStream("Chap0404.pdf", FileMode.Create))
            document.Open
            Dim grx As Graphic = New Graphic
            grx.Rectangle(100, 700, 100, 100)
            grx.MoveTo(100, 700)
            grx.LineTo(200, 800)
            grx.Stroke
            document.Add(grx)
        Catch de As DocumentException
            Console.Error.WriteLine(de.Message)
        Catch ioe As IOException
            Console.Error.WriteLine(ioe.Message)
        End Try
        document.Close
    End Sub
End Class 

End Namespace

End Namespace

推荐答案

在玩了一段时间后,我认为结论是你所遵循的教程适用于过时的版本iText / iTextSharp。

After playing with this for a while I think the conclusion is that the tutorial you're following applies to an out-of-date version of iText / iTextSharp.

他们的 sourceforge 网站链接从2006年1月到匹配的示例,以及您对VB的翻译.NET看起来很准确 - 问题是当前版本的iTextSharp不包含 Graphic 类型,经过一些搜索后它似乎不是重命名 - 整个图形API更有可能被显着改变。

Their sourceforge site links to a matching example from January of 2006, and your translation to VB.NET looks accurate--the problem is that the current version of iTextSharp doesn't contain a Graphic type, and after some searching it doesn't appear to have been just renamed--it's more likely that the full graphics API has been significantly altered.

sourceforge页面有一个免责声明(最后一行),链接的示例可能无法正常工作再一次,

The sourceforge page has a disclaimer (last line) that the linked examples might not work anymore,


请注意,部分示例不适用于最新版本的iTextSharp。

Note that some of the example won't work with the most recent version of iTextSharp.

根据给定的证据和Reflector的使用,我发现了预期的 Graphic.Stroke()方法仅存在于 PdfContentByte 类中;但是 Document.Add()需要一个实现 IElement 的类,其中 PdfContentByte 没有。

With the given evidence, and the use of Reflector, I found that the expected Graphic.Stroke() method only exists within the PdfContentByte class; however Document.Add() expects a class that implements IElement, which PdfContentByte doesn't do.

这个变化是我可以做的最小的 关闭 编译,但它显着改变了代码的意图,可能无法按预期运行。这是我的更新版本供您参考:

That change is the smallest I could make to get close to compiling, but it significantly alters the intent of the code and probably won't function as expected. Here's my updated version for your reference though:

Public Class Chap0404

    Public Sub New()
        Console.WriteLine("Chapter 4 example 4: Simple Graphic")
        Dim document As Document = New Document
        Try
            Dim writer As PdfWriter = PdfWriter.GetInstance(document, New FileStream("Chap0404.pdf", FileMode.Create))
            document.Open()
            Dim grx As PdfContentByte = New PdfContentByte(writer)
            grx.Rectangle(100, 700, 100, 100)
            grx.MoveTo(100, 700)
            grx.LineTo(200, 800)
            grx.Stroke()
            'document.Add(grx)
        Catch de As DocumentException
            Console.Error.WriteLine(de.Message)
        Catch ioe As IOException
            Console.Error.WriteLine(ioe.Message)
        End Try
        document.Close()
    End Sub
End Class

这篇关于我做了'进口' - 错误类型预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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