miscal

how do I open a PDF document stored in resources of my application

Re: Windows Forms General opening PDF cocument fro mresources

nobugz

Depends what kind of PDF reader you use. If you use Acrobat, you'll have to save the resource to a temporary file.





Re: Windows Forms General opening PDF cocument fro mresources

miscal

ok. suppose I will save it to a temp file, how do I persorm the saving to a temporary file



Re: Windows Forms General opening PDF cocument fro mresources

nobugz

Project + properties, Resources tab, click the arrow on the "Add Resource" button, Add Existing File. Navigate to your .pdf. Rename it if necessary, I called it "SamplePdf". Here's a sample form that displays it:

using System;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace WindowsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) {
byte[] pdf = Properties.Resources.SamplePdf;
using (FileStream tmp = new FileStream(@"temp.pdf", FileMode.Create)) {
tmp.Write(pdf, 0, pdf.Length);
}
Process.Start(@"temp.pdf");
}
}
}





Re: Windows Forms General opening PDF cocument fro mresources

miscal

can you please specify the code in .NET I'm find it dificult translating it.



Re: Windows Forms General opening PDF cocument fro mresources

nobugz

It is .NET code, C# to be specific. What do you use




Re: Windows Forms General opening PDF cocument fro mresources

miscal

VB



Re: Windows Forms General opening PDF cocument fro mresources

nobugz

Imports System.IO
Imports System.Diagnostics

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim pdf As Byte() = My.Resources.SamplePdf
Using tmp As New FileStream("test.pdf", FileMode.Create)
tmp.Write(pdf, 0, pdf.Length)
End Using
Process.Start("test.pdf")
End Sub
End Class

Make sure you mention you need VB.NET code next time, this forum is 95% C#.





Re: Windows Forms General opening PDF cocument fro mresources

miscal

No problem, thank you very much for your help.