Hi all,
can u pls tell me how to convert
.doc,rtf,.xls files to pdf in C# .Net
thx
6 14692
Friend please to try this codeing - ==============================
-
-
mports BCL.easyPDF.Interop.EasyPDFPrinter
-
Imports System.Windows.Forms
-
-
Public Class Form1
-
Private oPrinter As Printer = Nothing
-
Private oPrintJob As PrintJob = Nothing
-
Private oPDFSetting As PDFSetting = Nothing
-
Private oWatermarkText As String = Nothing
-
Private oWatermarkBool As Boolean
-
-
' #################################################################################
-
' Sub CheckBox1_CheckedChanged
-
' Description: Check if users enables or disables the watermark option from the UI.
-
' #################################################################################
-
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
-
If (CheckBox1.Enabled = True) Then
-
oWatermarkBool = True
-
Else
-
oWatermarkBool = False
-
End If
-
End Sub
-
-
' #################################################################################
-
' Function ConvertToPDF, return String
-
' Description: Return the watermark text.
-
' #################################################################################
-
Public Function GetWatermarkText() As String
-
Return oWatermarkText
-
End Function
-
-
-
' #################################################################################
-
' Sub ConvertToPDF
-
' Description: Initialize the printer driver name and check the watermark condition
-
' and print to pdf file.
-
' #################################################################################
-
Private Sub ConvertToPDF(ByVal inFile As String, ByVal outFile As String)
-
Try
-
' This is how our printer driver gets initialized
-
oPrinter = CreateObject("easyPDF.Printer.5")
-
oPrintJob = oPrinter.PrintJob
-
-
' Use PDFSetting because we want to use Watermark feature
-
oPDFSetting = oPrintJob.PDFSetting
-
-
' Check the watermark properties if the users has entered the text or not
-
' oWatermarkBool is a global variable for enable/disable watermark
-
' GetWatermarkText will return a value of oWatermarkText
-
If (oWatermarkBool And (oWatermarkText <> Nothing)) Then
-
oPDFSetting.Watermark(0) = oWatermarkBool
-
oPDFSetting.WatermarkText(0) = GetWatermarkText()
-
End If
-
-
' Printing to pdf from whatever inFile format is
-
oPrintJob.PrintOut(inFile, outFile)
-
-
MessageBox.Show("Success!!!")
-
-
' All the conversion errors will get caught here and the message box
-
' will pop up notifying users for the errors.
-
Catch ex As System.Runtime.InteropServices.COMException
-
MessageBox.Show(ex.Message)
-
If (ex.ErrorCode = prnResult.PRN_R_CONVERSION_FAILED And Not oPrintJob Is Nothing) Then
-
MessageBox.Show(oPrintJob.ConversionResultMessage)
-
End If
-
End Try
-
-
' Clean up the object from the memory
-
oPrinter = Nothing
-
-
End Sub
-
-
-
' #################################################################################
-
' Sub Button1_Click
-
' Description: open the "Open File Dialog" and "Save File Dialog"
-
' asking users to choose the input file and the target file name,
-
' this case is pdf.
-
' #################################################################################
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
-
Dim openFile As OpenFileDialog
-
Dim savePDFFile As SaveFileDialog
-
Dim inFileName As String
-
Dim outFileName As String
-
Dim pos As Integer
-
-
' "Open File Dialog" instantiation
-
openFile = New System.Windows.Forms.OpenFileDialog
-
openFile.Filter = "All Files (*.*)|*.*"
-
openFile.Title = "Select a File"
-
If (openFile.ShowDialog() <> System.Windows.Forms.DialogResult.OK) Then
-
Return
-
End If
-
inFileName = openFile.FileName
-
-
outFileName = inFileName
-
pos = inFileName.LastIndexOf(".")
-
If (pos > 0) Then
-
outFileName = outFileName.Substring(0, pos)
-
End If
-
outFileName += ".pdf"
-
-
' "Save File Dialog" instantiation
-
savePDFFile = New System.Windows.Forms.SaveFileDialog
-
savePDFFile.FileName = outFileName
-
savePDFFile.Filter = "pdf files (*.pdf)|*.pdf"
-
savePDFFile.Title = "Save PDF File"
-
If (savePDFFile.ShowDialog() <> System.Windows.Forms.DialogResult.OK) Then
-
Return
-
End If
-
outFileName = savePDFFile.FileName
-
-
' Once we know the input file and the output file, we pass these information to
-
' the ConvertToPDF function for printing to pdf file.
-
ConvertToPDF(inFileName, outFileName)
-
End Sub
-
-
' #################################################################################
-
' Sub TextBox1_TextChanged
-
' Description: Assign the string text of the watermark to oWatermarkText variable.
-
' #################################################################################
-
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
-
oWatermarkText = TextBox1.Text
-
End Sub
-
-
End Class
-
=======================================
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
No it didnt work ..couldnt get the dll
hi did you get the solution for this convertion problem.
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.
Seems to be a great converter?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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()...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| | |