473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C# : Web : - How to Convert .doc,rtf,.xls files to pdf

29
Hi all,

can u pls tell me how to convert
.doc,rtf,.xls files to pdf in C# .Net


thx
Feb 14 '08 #1
6 14692
Friend please to try this codeing

Expand|Select|Wrap|Line Numbers
  1. ==============================
  2.  
  3. mports BCL.easyPDF.Interop.EasyPDFPrinter
  4. Imports System.Windows.Forms
  5.  
  6. Public Class Form1
  7.     Private oPrinter As Printer = Nothing
  8.     Private oPrintJob As PrintJob = Nothing
  9.     Private oPDFSetting As PDFSetting = Nothing
  10.     Private oWatermarkText As String = Nothing
  11.     Private oWatermarkBool As Boolean
  12.  
  13.     ' #################################################################################
  14.     ' Sub CheckBox1_CheckedChanged
  15.     ' Description: Check if users enables or disables the watermark option from the UI.
  16.     ' #################################################################################
  17.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
  18.         If (CheckBox1.Enabled = True) Then
  19.             oWatermarkBool = True
  20.         Else
  21.             oWatermarkBool = False
  22.         End If
  23.     End Sub
  24.  
  25.     ' #################################################################################
  26.     ' Function ConvertToPDF, return String
  27.     ' Description: Return the watermark text.           
  28.     ' #################################################################################
  29.     Public Function GetWatermarkText() As String
  30.         Return oWatermarkText
  31.     End Function
  32.  
  33.  
  34.     ' #################################################################################
  35.     ' Sub ConvertToPDF
  36.     ' Description: Initialize the printer driver name and check the watermark condition
  37.     '              and print to pdf file.              
  38.     ' #################################################################################
  39.     Private Sub ConvertToPDF(ByVal inFile As String, ByVal outFile As String)
  40.         Try
  41.             ' This is how our printer driver gets initialized
  42.             oPrinter = CreateObject("easyPDF.Printer.5")
  43.             oPrintJob = oPrinter.PrintJob
  44.  
  45.             ' Use PDFSetting because we want to use Watermark feature
  46.             oPDFSetting = oPrintJob.PDFSetting
  47.  
  48.             ' Check the watermark properties if the users has entered the text or not
  49.             ' oWatermarkBool is a global variable for enable/disable watermark
  50.             ' GetWatermarkText will return a value of oWatermarkText
  51.             If (oWatermarkBool And (oWatermarkText <> Nothing)) Then
  52.                 oPDFSetting.Watermark(0) = oWatermarkBool
  53.                 oPDFSetting.WatermarkText(0) = GetWatermarkText()
  54.             End If
  55.  
  56.             ' Printing to pdf from whatever inFile format is
  57.             oPrintJob.PrintOut(inFile, outFile)
  58.  
  59.             MessageBox.Show("Success!!!")
  60.  
  61.             ' All the conversion errors will get caught here and the message box
  62.             ' will pop up notifying users for the errors.
  63.         Catch ex As System.Runtime.InteropServices.COMException
  64.             MessageBox.Show(ex.Message)
  65.             If (ex.ErrorCode = prnResult.PRN_R_CONVERSION_FAILED And Not oPrintJob Is Nothing) Then
  66.                 MessageBox.Show(oPrintJob.ConversionResultMessage)
  67.             End If
  68.         End Try
  69.  
  70.         ' Clean up the object from the memory
  71.         oPrinter = Nothing
  72.  
  73.     End Sub
  74.  
  75.  
  76.     ' #################################################################################
  77.     ' Sub Button1_Click 
  78.     ' Description: open the "Open File Dialog" and "Save File Dialog"
  79.     '              asking users to choose the input file and the target file name, 
  80.     '              this case is pdf.
  81.     ' #################################################################################
  82.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  83.         Dim openFile As OpenFileDialog
  84.         Dim savePDFFile As SaveFileDialog
  85.         Dim inFileName As String
  86.         Dim outFileName As String
  87.         Dim pos As Integer
  88.  
  89.         ' "Open File Dialog" instantiation
  90.         openFile = New System.Windows.Forms.OpenFileDialog
  91.         openFile.Filter = "All Files (*.*)|*.*"
  92.         openFile.Title = "Select a File"
  93.         If (openFile.ShowDialog() <> System.Windows.Forms.DialogResult.OK) Then
  94.             Return
  95.         End If
  96.         inFileName = openFile.FileName
  97.  
  98.         outFileName = inFileName
  99.         pos = inFileName.LastIndexOf(".")
  100.         If (pos > 0) Then
  101.             outFileName = outFileName.Substring(0, pos)
  102.         End If
  103.         outFileName += ".pdf"
  104.  
  105.         ' "Save File Dialog" instantiation
  106.         savePDFFile = New System.Windows.Forms.SaveFileDialog
  107.         savePDFFile.FileName = outFileName
  108.         savePDFFile.Filter = "pdf files (*.pdf)|*.pdf"
  109.         savePDFFile.Title = "Save PDF File"
  110.         If (savePDFFile.ShowDialog() <> System.Windows.Forms.DialogResult.OK) Then
  111.             Return
  112.         End If
  113.         outFileName = savePDFFile.FileName
  114.  
  115.         ' Once we know the input file and the output file, we pass these information to
  116.         ' the ConvertToPDF function for printing to pdf file.
  117.         ConvertToPDF(inFileName, outFileName)
  118.     End Sub
  119.  
  120.     ' #################################################################################
  121.     ' Sub TextBox1_TextChanged
  122.     ' Description: Assign the string text of the watermark to oWatermarkText variable.
  123.     ' #################################################################################
  124.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  125.         oWatermarkText = TextBox1.Text
  126.     End Sub
  127.  
  128. End Class
  129. =======================================
Feb 14 '08 #2
tim007
29
Thanks Prabakaran...

let me try this in C# as i need to impliment this in C#

this line of code
imports BCL.easyPDF.Interop.EasyPDFPrinter

i would need this dll right ?

thanks again vl try and get back to u
Feb 15 '08 #3
tim007
29
No it didnt work ..couldnt get the dll
Feb 26 '08 #4
vel
12
hi did you get the solution for this convertion problem.
Jun 30 '08 #5
Curtis Rutland
3,256 Expert 2GB
No it didnt work ..couldnt get the dll
Looks like you need a 3rd party DLL to use his solution.

Actually...there is no native PDF functionality, so you will need a third-party dll regardless. I suggest either searching for the one he used (start here, i found this from a quick google search) and if you can't find it, move on to Sourceforge. They have plenty of .NET PDF solutions.
Jun 30 '08 #6
Seems to be a great converter?
Nov 1 '18 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
5
by: bbb | last post by:
Hi, I need to convert XML files from Japanese encoding to UTF-8. I was using the following code: using ( FileStream fs = File.OpenRead(fromFile) ) { int fileSize = (int)fs.Length; int buffer...
3
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what...
2
by: Craig | last post by:
Hi there, I'm trying to convert some PNG files to bitmap files which can then be converted to X11 bitmaps using the im.tobitmap() function. But the error I get when using the im.tobitmap()...
10
by: gokul | last post by:
Hi, Before i convert .doc binary format files to .txt files and i added some content to .txt files. Now i again convert back to .doc binary format. Pls Help Me How to Convert .txt files to...
6
by: leonel.gayard | last post by:
Hi, Does anyone know a good python library to convert a RTF file into PDF ? This should be done automaticaly: I have a web page that takes some values and inserts them into a RTF template,...
1
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in...
2
by: edw | last post by:
I want to convert rfc822 (.eml) files to MAPI (.msg) files. I do not need to log in to Outlook to retrieve the messages, since the messages have all been downloaded from the exchange server and...
3
by: Sun | last post by:
Hi everyone . I have two files named a.txt and b.txt. I open a.txt with ultraeditor.exe. here is the first row of the file: neu für then I switch to the HEX mode: 00000000h: FF FE 6E 00 65...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.