Advertisement
Advertisement
| 02.13.2008 at 09:37AM PST, ID: 23160373 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: |
Imports microsoft.Office.Interop.Word
Partial Class _Default
Inherits System.Web.UI.Page
Dim wordApplication As ApplicationClass = Nothing
Dim wordDocument As Document = Nothing
Dim paramSourceDocPath As String = "E:\test.docx"
Dim paramExportFilePath As String = "E:\test.pdf"
Dim paramExportFormat As WdExportFormat = WdExportFormat.wdExportFormatPDF
Try
wordApplication = New ApplicationClass()
wordDocument = wordApplication.Documents.Open(paramSourceDocPath)
If Not wordDocument is Nothing Then
wordDcoument.ExportAsFixedFormat(paramExportFilePath,paramExportFormat)
End If
Catch ex As Exception
Finally
If Not wordDocument Is Nothing Then
wordDocument.Close(False)
wordDocument = Nothing
End If
If Not wordApplication Is Nothing Then
wordApplication.Quit()
wordApplication = Nothing
End If
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
End Class
|
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 02.13.2008 at 10:17AM PST, ID: 20886622 |
| 02.13.2008 at 11:26AM PST, ID: 20887219 |
| 02.15.2008 at 05:34PM PST, ID: 20907507 |
| 02.17.2008 at 04:26PM PST, ID: 20916621 |
| 02.18.2008 at 05:00AM PST, ID: 20919441 |
| 02.18.2008 at 06:35AM PST, ID: 20920173 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: |
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Microsoft.Office
Imports Microsoft.Office.Interop.Word
Public Class DOCX2PDF
Inherits System.Web.UI.Page
Protected objWord As Microsoft.Office.Interop.Word.ApplicationClass = New ApplicationClass()
Protected strPathToUpload As String
Protected strPathToConvert As String
Private fltDocFormat As Object = 17
'Private fltDocFormat As WdExportFormat = WdExportFormat.wdExportFormatPDF
Protected missing As Object = System.Reflection.Missing.Value
Protected [readOnly] As Object = False
Protected isVisible As Object = False
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)
'Code to check if user has selected any file on the form
If Not (fUpload.HasFile) Then
lblMessage.Text = "Please choose file to upload"
Else
Try
'To check the file extension if it is word document or something else
Dim strFileName As String = fUpload.FileName
Dim strSep As String() = fUpload.FileName.Split("."c)
Dim arrLength As Integer = strSep.Length - 1
Dim strExt As String = strSep(arrLength).ToString().ToUpper()
'Save the uploaded file to the folder
strPathToUpload = Server.MapPath("Uploaded")
'Map-path to the folder where html to be saved
strPathToConvert = Server.MapPath("WordToPdf")
Dim FileName As Object = strPathToUpload + "\" + fUpload.FileName
Dim FileToSave As Object = strPathToConvert + "\" + Replace(fUpload.FileName, ".docx", "") + ".pdf"
'Dim FileToSave As Object = strPathToConvert + "\test.xps"
If strExt.ToUpper().Equals("DOCX") Then
fUpload.SaveAs(strPathToUpload + "\" + fUpload.FileName)
lblMessage.Text = "File uploaded successfully"
'open the file internally in word. In the method all the parameters should be passed by object reference
objWord.Documents.Open(FileName, [readOnly], missing, missing, missing, missing, _
missing, missing, missing, missing, isVisible, missing, _
missing, missing, missing, missing)
'Do the background activity
objWord.Visible = False
Dim oDoc As Microsoft.Office.Interop.Word.Document = objWord.ActiveDocument
oDoc.SaveAs(FileToSave, fltDocFormat, missing, missing, missing, missing, _
missing, missing, missing, missing, missing, missing, _
missing, missing, missing, missing)
lblMessage.Text = fUpload.FileName + " converted successfully"
Else
lblMessage.Text = "Invalid file selected!"
End If
'Close/quit word
objWord.Quit(missing, missing, missing)
Catch ex As Exception
Response.Write(ex.Message)
End Try
End If
End Sub
End Class
|
| 02.18.2008 at 06:27PM PST, ID: 20925244 |
| 02.19.2008 at 04:15AM PST, ID: 20927522 |
| 02.19.2008 at 07:18PM PST, ID: 20934747 |
| 02.20.2008 at 02:02AM PST, ID: 20936295 |
| 02.20.2008 at 03:34AM PST, ID: 20936739 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: |
test.asp
--------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
xmlHttp=new XMLHttpRequest();
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.viewPDF.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","http://12.345.23.1/doc2pdf/convert.aspx",true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<form name="myForm">
<a href="browser.docx">Document</a> <input type="button" onClick="ajaxFunction();" value="Convert"/>
<div id="viewPDF"></div>
</form>
</body>
</html>
convert.aspx
------------
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Microsoft.Office
Imports Microsoft.Office.Interop.Word
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected objWord As Microsoft.Office.Interop.Word.ApplicationClass = New ApplicationClass()
' Protected objWord As Microsoft.Office.Interop.Word.Application = New ApplicationId()
'This creates new object of Word.ApplicationClass
Protected strPathToUpload As String
'Path to upload files "Uploaded"
Protected strPathToConvert As String
'Path to convert uploaded files and save
Private fltDocFormat As Object = 17
'Private fltDocFormat As WdExportFormat = WdExportFormat.wdExportFormatPDF
'For filtered PDF Output
Protected missing As Object = System.Reflection.Missing.Value
'Is just to skeep the parameters which are passed as boject reference, these are seems to be optional parameters
Protected [readOnly] As Object = False
Protected isVisible As Object = False
'The process has to be in invisible mode
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs)
'Code to check if user has selected any file on the form
If Not (fUpload.HasFile) Then
lblMessage.Text = "Please choose file to upload"
Else
Try
'To check the file extension if it is word document or something else
Dim strFileName As String = fUpload.FileName
Dim strSep As String() = fUpload.FileName.Split("."c)
Dim arrLength As Integer = strSep.Length - 1
Dim strExt As String = strSep(arrLength).ToString().ToUpper()
'Save the uploaded file to the folder
strPathToUpload = Server.MapPath("Uploaded")
'Map-path to the folder where html to be saved
strPathToConvert = Server.MapPath("WordToPdf")
Dim FileName As Object = strPathToUpload + "\" + fUpload.FileName
Dim FileToSave As Object = strPathToConvert + "\" + Replace(fUpload.FileName, ".docx", "") + ".pdf"
'Dim FileToSave As Object = strPathToConvert + "\test.xps"
If strExt.ToUpper().Equals("DOCX") Then
fUpload.SaveAs(strPathToUpload + "\" + fUpload.FileName)
lblMessage.Text = "File uploaded successfully"
'open the file internally in word. In the method all the parameters should be passed by object reference
objWord.Documents.Open(FileName, [readOnly], missing, missing, missing, missing, _
missing, missing, missing, missing, isVisible, missing, _
missing, missing, missing, missing)
'Do the background activity
objWord.Visible = False
Dim oDoc As Microsoft.Office.Interop.Word.Document = objWord.ActiveDocument
oDoc.SaveAs(FileToSave, fltDocFormat, missing, missing, missing, missing, _
missing, missing, missing, missing, missing, missing, _
missing, missing, missing, missing)
lblMessage.Text = fUpload.FileName + " converted successfully to pdf"
Else
lblMessage.Text = "Invalid file selected!"
End If
'Close/quit word
objWord.Quit(missing, missing, missing)
Catch ex As Exception
Response.Write(ex.Message)
End Try
End If
End Sub
End Class
|
| 02.21.2008 at 03:36PM PST, ID: 20953091 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: |
'--------------THIS IS ASP PAGE (OR REGULAR HTML)--------------
<html>
<head>
<title>Untitled Page</title>
<script type="text/javascript">
function ajaxFunction()
{
var pdfpath = "http://localhost/WebApplication1/pdf/";
var convertserver = "http://localhost/WebApplication2/convert.aspx?filetoconvert=";
var sourcedocx = "testdocument.docx";
//right now the code has hardcoded document name
//get this value from other fields in the page or other source
var xmlHttp;
xmlHttp=new XMLHttpRequest();
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
//document.myForm.viewPDF.value=xmlHttp.responseText;
var resp = xmlHttp.responseText;
alert(resp);
pdfpath = pdfpath + resp;
document.getElementById("PDFView").href = pdfpath;
document.getElementById("PDFTitle").style.visibility='visible';
}
}
xmlHttp.open("GET",convertserver + sourcedocx, true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<form name="myForm" action ="">
<input type="button" onclick="ajaxFunction();" value="Convert"/>
<a href="" id="PDFView">
<p id="PDFTitle" style="position: relative; left: 0px; top: 0px; visibility:hidden">
Click here to download the PDF.
</p>
</a>
</form>
</body>
</html>
'-----THIS IS ASP.Net CODE - convert.aspx (Create a blank asp.net page and put these codes) --------------
Public Partial Class convert
Inherits System.Web.UI.Page
Protected objWord As Microsoft.Office.Interop.Word.ApplicationClass = New Microsoft.Office.Interop.Word.ApplicationClass()
' Protected objWord As Microsoft.Office.Interop.Word.Application = New ApplicationId()
'This creates new object of Word.ApplicationClass
Protected strPathToUpload As String = "\\server\share\docxfolder"
'Path to upload files "Uploaded"
Protected strPathToConvert As String = "\\server\share\pdffolder"
'Path to convert uploaded files and save
Private fltDocFormat As Object = 17
'Private fltDocFormat As WdExportFormat = WdExportFormat.wdExportFormatPDF
'For filtered PDF Output
Protected missing As Object = System.Reflection.Missing.Value
'Is just to skeep the parameters which are passed as boject reference, these are seems to be optional parameters
Protected [readOnly] As Object = False
Protected isVisible As Object = False
'The process has to be in invisible mode
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
'get file name
Dim strFileName As String = Request.Params.Item("filetoconvert")
If strFileName <> Nothing AndAlso strFileName <> "" Then
Dim FileName As Object = strPathToUpload + "\" & strFileName
Dim PDFFileName As String = Replace(strFileName, ".docx", "") + ".pdf"
Dim FileToSave As Object = strPathToConvert + "\" & PDFFileName
'open the file internally in word. In the method all the parameters should be passed by object reference
objWord.Documents.Open(FileName, [readOnly], missing, missing, missing, missing, _
missing, missing, missing, missing, isVisible, missing, _
missing, missing, missing, missing)
'Do the background activity
objWord.Visible = False
Dim oDoc As Microsoft.Office.Interop.Word.Document = objWord.ActiveDocument
oDoc.SaveAs(FileToSave, fltDocFormat, missing, missing, missing, missing, _
missing, missing, missing, missing, missing, missing, _
missing, missing, missing, missing)
'Close/quit word
objWord.Quit(missing, missing, missing)
Response.Clear()
Response.Write(PDFFileName)
Response.End()
Response.Close()
End If
Catch ex As Exception
If Not (ex.Message = "Thread was being aborted.") Then
Response.Write(ex.Message)
End If
End Try
End Sub
End Class
|
| 02.22.2008 at 02:10AM PST, ID: 20955931 |
| 02.23.2008 at 01:37AM PST, ID: 20964302 |
| 02.23.2008 at 01:38AM PST, ID: 20964306 |
| 02.23.2008 at 02:13PM PST, ID: 20967002 |