Use C # To open a PDF file
Http://www.o2sol.com/public/webui/samples.shtml
Download XpdfRasterizer. dll and XpdfRasterizerNet. dll.
For example
Using XpdfRasterizerNet;
Protected System. Web. UI. WebControls. Button Button1;
Protected System. Web. UI. HtmlControls. HtmlInputFile File1;
Protected System. Web. UI. WebControls. Label Label1;
Protected System. Web. UI. WebControls. PlaceHolder PlaceHolder1;
Private void Page_Load (object sender, System. EventArgs e)
{
This. Label1.Text = "";
}
# Region Web Form Designer generated code
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web Form Designer.
//
InitializeComponent ();
Base. OnInit (e );
}
/// <Summary>
/// Required method for Designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void InitializeComponent ()
{
This. Button1.Click + = new System. EventHandler (this. button#click );
This. Load + = new System. EventHandler (this. Page_Load );
}
# Endregion
Private string GetFilePath ()
{
/// 4/19/2005 5:44:28
String time = System. DateTime. Now. ToString ();
Time = time. Replace ("/","");
Time = time. Replace ("","");
Time = time. Replace (":","");
// Time + = ". pdf ";
String path = Server. MapPath ("20172jpg. aspx ");
Path = path. Replace ("20172jpg. aspx", @ "Files \" + time );
Return path;
}
Private void button#click (object sender, System. EventArgs e)
{
// Upload
Int len = File1.PostedFile. FileName. Length;
String filetype = File1.PostedFile. FileName. Substring (len-3, 3 );
If (filetype. ToLower ()! = "Pdf ")
{
This. Label1.Text = "Please select pdf file ";
Return;
}
Else
This. Label1.Text = "";
String fileName = GetFilePath ();
String pdffile = fileName + ". pdf ";
If (File1.PostedFile! = Null)
{
Try
{
File1.PostedFile. SaveAs (pdffile );
}
Catch
{
Response. Write ("Upload fail ...");
}
}
// Convert to jpg
Double dpi = 120;
XpdfRasterizerNet. XpdfRasterizerClass rast = new XpdfRasterizerNet. XpdfRasterizerClass ();
Rast. loadFile (pdffile );
For (int page = 1; page <= rast. numPages; page ++)
{
String jpgfile = fileName + page. ToString () + ". bmp ";
Try
{
Rast. writePageBitmap (page, dpi, rast. imageRGB, rast. imageFileBMP, jpgfile );
System. Web. UI. WebControls. Image image = new System. Web. UI. WebControls. Image ();
Image. ImageUrl = jpgfile;
This. PlaceHolder1.Controls. Add (image );
}
Catch
{
Response. Write ("Convert fail ...:");
}
}
Rast. closeFile ();
}