本文介绍了如何使用VB.NET打开pdf文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb.net上开发了一个项目,在Resources中保存了一个.pdf文件。我尝试了以下代码,但它没有读取.pdf文件。请问哪里有错误?。



谢谢。



Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()

Dim root As String = assembly.GetName()。Name

Dim stream As System.IO.Stream = assembly.GetManifestResourceStream( root +。+CraneNuclear.pdf)

Dim buffer(Convert.ToInt32(stream.Length) - 1)As Byte

Stream.Read(buffer, 0,buffer.Length)

Stream.Close()

Dim f As New IO.FileStream(CraneNuclear.pdf,IO.FileMode.Create,IO.FileAccess 。写)

f.Write(buffer,0,buffer.Length)

f.Close()



Process.Start(CraneNuclear.pdf)



我尝试过:



I have a project developed on vb.net and a .pdf file saved in Resources. I have tried the following code but it does not read the .pdf file. Please where is the error ?.

Thanks.

Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim root As String = assembly.GetName().Name
Dim stream As System.IO.Stream = assembly.GetManifestResourceStream(root + "." + "CraneNuclear.pdf")
Dim buffer(Convert.ToInt32(stream.Length) - 1) As Byte
Stream.Read(buffer, 0, buffer.Length)
Stream.Close()
Dim f As New IO.FileStream("CraneNuclear.pdf", IO.FileMode.Create, IO.FileAccess.Write)
f.Write(buffer, 0, buffer.Length)
f.Close()

Process.Start("CraneNuclear.pdf")

What I have tried:

Dim assembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
 Dim root As String = assembly.GetName().Name
 Dim stream As System.IO.Stream = assembly.GetManifestResourceStream(root + "." + "CraneNuclear.pdf")
 Dim buffer(Convert.ToInt32(stream.Length) - 1) As Byte
 Stream.Read(buffer, 0, buffer.Length)
 Stream.Close()
 Dim f As New IO.FileStream("CraneNuclear.pdf", IO.FileMode.Create, IO.FileAccess.Write)
 f.Write(buffer, 0, buffer.Length)
 f.Close()

 Process.Start("CraneNuclear.pdf")

推荐答案

Dim ProcessApplication As String = "AcroRd32"
Dim ProcessArguement As String = "CraneNuclear.pdf"

Dim MyPDF As New ProcessStartInfo(ProcessApplication)
MyPDF.Arguments = ProcessArguement

Process.Start(MyPDF)





我将从这个POC开始,然后回到 Reflection ,找出未按预期发生的事情。



请注意,您很可能需要使用PDF的路径



I would start with this POC and then work your way back into Reflection to figure out what is not happening as expected.

Please note that you most likely will need to work with the paths for the PDFs


这篇关于如何使用VB.NET打开pdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 20:59
查看更多