得到错误的system.IO

时间:2015-04-14 06:10:41

标签: vb.net itextsharp

在我的应用程序中,我遇到以下错误

1)'System.IO.File'没有构造函数。

2)'ParentFile'不是'System.IO.File'的成员。

   Public Const DEST As String = "results/objects/custom_dashed_line.pdf"

'JAVA TO VB CONVERTER WARNING: Method 'throws' clauses are not available   
in .NET:
'ORIGINAL LINE: public static void main(String[] args) throws IOException, 
DocumentException
Public Shared Sub Main(ByVal args() As String)
    Dim file As New File(DEST)
    file.ParentFile.mkdirs()
    Call (New CustomDashedLine()).createPdf(DEST)

我尝试在iText可编程pdf软件上从下面的示例将代码转换为vb,我在上面的代码行上出错了

CustomDashedLine

发布于星期六,01/03/2015 - 12:35,由iText管理员

/ **  * Bruno Lowagie在回答以下问题时所写的例子:  * How to create a custom dashed line separator?  * /     包sandbox.objects;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.draw.DottedLineSeparator;

public class CustomDashedLine {

class CustomDashedLineSeparator extends DottedLineSeparator {
    protected float dash = 5;
    protected float phase = 2.5f;

    public float getDash() {
        return dash;
    }

    public float getPhase() {
        return phase;
    }

    public void setDash(float dash) {
        this.dash = dash;
    }

    public void setPhase(float phase) {
        this.phase = phase;
    }

public void draw(PdfContentByte canvas, float llx, float lly, float  
urx, float ury, float y) {
        canvas.saveState();
        canvas.setLineWidth(lineWidth);
        canvas.setLineDash(dash, gap, phase);
        drawLine(canvas, llx, urx, y);
        canvas.restoreState();
}
 }

  public static final String DEST  
= "results/objects/custom_dashed_line.pdf";

  public static void main(String[] args) throws IOException,  
DocumentException {
    File file = new File(DEST);
    file.getParentFile().mkdirs();
    new CustomDashedLine().createPdf(DEST);
}

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    document.add(new Paragraph("Before dashed line"));
    CustomDashedLineSeparator separator = new CustomDashedLineSeparator();
    separator.setDash(10);
    separator.setGap(7);
    separator.setLineWidth(3);
    Chunk linebreak = new Chunk(separator);
    document.add(linebreak);
    document.add(new Paragraph("After dashed line"));
    document.close();
  }
}

0 个答案:

没有答案