我想在VB.NET中使用pdffilewriter [英] I want to use the pdffilewriter in VB.NET

查看:65
本文介绍了我想在VB.NET中使用pdffilewriter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



i希望在VB.net中使用PDFFileWriter,但它不起作用。

我只有空页。你有没有VB.NET 2017的例子?



这是一个很好的课程。



谢谢

好​​问候弗兰克



我尝试过:



这是我的小型测试程序:



Hello,

i want to use the PDFFileWriter in VB.net but it doesn't work.
I have only an empty page. Have you got any examples for VB.NET 2017?

It's a good class.

Thanks
Best regards Frank

What I have tried:

Here is my small testprogram:

Imports PdfFileWriter
Imports System.IO
Imports System.Drawing

Public Class Form1

    Dim ArialFont As PdfFont
    Dim FontSize As Double
    Dim Ascent As Double
    Dim Descent As Double
    Dim FontHeight2 As Double

    Dim Document As PdfDocument
    Dim CenterX As Double = 4.25
    Dim CenterY As Double = 5.5

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim npfad As String = ""

        SaveFileDialog1.Title = "PDF speicher unter..."
        SaveFileDialog1.OverwritePrompt = True

        If SaveFileDialog1.ShowDialog = DialogResult.OK And SaveFileDialog1.FileName > "" Then
            npfad = SaveFileDialog1.FileName
            If UCase(npfad).EndsWith("PDF") = False Then
                npfad = npfad & ".PDF"
            End If

            Dim PDFDokument As New PdfDocument(PaperType.A4, False, UnitOfMeasure.Inch, npfad)
            'PDFDokument.Debug = True

            Dim FontName1 As String = "Arial"
            Dim FontName2 As String = "Times New Roman"

            ArialFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Regular, True)
            Dim ArialNormal As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Regular, True)
            Dim ArialBold As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Bold, True)
            Dim ArialItalic As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Italic, True)
            Dim ArialBoldItalic As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName1, FontStyle.Bold And FontStyle.Italic, True)
            Dim TimesNormal As PdfFont = PdfFont.CreatePdfFont(PDFDokument, FontName2, FontStyle.Regular, True)

            Dim PDFPage As New PdfPage(PDFDokument)
            Dim Contents As New PdfContents(PDFDokument)

            Dim left As Double = CenterX - 0.5 * 1
            Dim Right As Double = CenterX + 0.5 * 1
            Dim Top As Double = CenterY + 0.5 * 1
            Dim Bottom As Double = CenterY - 0.5 * 1

            Contents.DrawText(ArialFont, 10, 10, 10, TextJustify.Center, DrawStyle.Normal, Color.Black, "Hallo")

            ' save state
            Contents.SaveGraphicsState()

            Contents.SetLineWidth(0.1)
            Contents.SetColorStroking(Color.Black)
            Contents.SetColorNonStroking(Color.LightBlue)
            Contents.DrawRectangle(left, Bottom, 3, 3, PaintOp.CloseFillStroke)
            Contents.RestoreGraphicsState()

            'PDFContents.SaveGraphicsState()
            'Contents.Translate(1.1, 1.1)

            'Dim TextBox As New TextBox(Width, 0.25)
            'Dim PosY As Double = Height
            'TextBox.AddText(ArialNormal, 10, "Hallo Welt")
            Dim nText As String = "Hallo Welt"

            Dim Breite As Double = ArialBold.TextWidth(25, nText)
            Dim Höhe As Double = ArialBold.LineSpacing(25)

            'Stop

            Contents.SaveGraphicsState()

            Dim nBarcode As New Barcode128("2018-2928282")
            Contents.SetColorNonStroking(Color.Red)
            Contents.DrawBarcode(3, 7, 0.01, 1, nBarcode, ArialNormal, 8)

            Contents.SetLineWidth(0.01)
            Contents.BeginTextMode()
            Contents.SetColorStroking(Color.DarkBlue)
            Contents.DrawText(ArialBold, 25, 4, 9, TextJustify.Center, 0.02, Color.FromArgb(128, 0, 0, 255), Color.FromArgb(255, 255, 0, 0), "Hallo Frank")
            Contents.DrawLine(10, 10, 50, 20)
            Contents.EndTextMode()
            Contents.DrawRectangle(1, 1, 6, 9, PaintOp.CloseFillStroke)
            Contents.RestoreGraphicsState()
            PDFDokument.CreateFile()

            Process.Start(npfad)
        End If
    End Sub
End Class

推荐答案

问题是您是将PdfContents对象添加到PdfDocument对象中,但需要将其添加到PdfPage对象中。

更改:

The problem is you are adding the PdfContents object to your PdfDocument object but it needs to be added to the PdfPage object.
Change:
Dim PDFPage As New PdfPage(PDFDokument)
Dim Contents As New PdfContents(PDFDokument)

to

Dim PDFPage As New PdfPage(PDFDokument)
Dim Contents As New PdfContents(PDFPage)

这是从 PDF文件编写器C#类库(版本1.20.0) [< a href =https://www.codeproject.com/Articles/570682/PDF-File-Writer-Csharp-Class-Library-Version-1-20target =_ blanktitle =New Window> ^ ]

This is extrapolated from the example on PDF File Writer C# Class Library (Version 1.20.0)[^]

// Step 3: Add new page
Page = new PdfPage(Document);

// Step 4:Add contents to page
Contents = new PdfContents(Page);


这篇关于我想在VB.NET中使用pdffilewriter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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