Am i in the wrong forum with this Query, could somebody direct me to the correct one?C# convert Excel to PDF or any image format

I have a C# application and i am trying to figure out the best way - or any way to retrive data from my excel file and convert it to a pdf file for printing.

Thanks,
Pam

My main objective is to get the document to print wth all the current excel formatting on the client machines.. which is why i was looking for direct convert to a pdf format... but if i can even figure out how to convert to an image format like .tif, .bmp or a .jpeg i can still convert it to .pdf from there at run time... Currently i am trying to directly print it as:

Microsoft.Office.Interop.Excel.ApplicationClass app = new ApplicationClass();
if (app == null)
{
MessageBox.Show("ERROR: EXCEL couldn't be started!");
return;//System.Windows.Forms.Application.Exit();
}
Microsoft.Office.Interop.Excel.Workbook workBook = app.Workbooks.Open(Path,0,true,5,"","",true,Microsoft.Office.Interop.Excel.XlPlatform.xlWindows,"\t",false,false,0,true,1,0);
Microsoft.Office.Interop.Excel.Worksheet workSheet = (Microsoft.Office.Interop.Excel.Worksheet)workBook.Sheets[1];//.ActiveSheet;
int index = 2;
while (index < 7)
{
workSheet = (Microsoft.Office.Interop.Excel.
Worksheet)workBook.Sheets[++index];//.ActiveSheet;
workSheet.PrintOut(1, 1, 1, false, true, false, false, "");
}

Is there any way to get the PrintOut commant to print any other format besides .prn



Answer this question

Am i in the wrong forum with this Query, could somebody direct me to the correct one?C# convert Excel to PDF or any image format

  • Landon Parks

    you could always read the spreadsheet to a dataset and then export it to pdf

    i know there is the save as pdf possibility in office 2007, but have been unable to find anything good for any other versions of office

    i believe that you should move away from excel via the dataset...



  • John Turnbull

    Unfortunately, that is not even an option... this is a analyst's spreadsheet with a multilude of calculations...
  • Anarchy

    This is a C# desktop, tax related, application, it will run on the client machines and all the generated output is currently being put together in a pdf file as a single point of information.

    The spreadsheet contains information that needs to be added to the pdf too and i am just not sure how to get it there.

    The only way i have come across so far is to install a pdf driver and point the machine to it as the default and print to a pdf file... and then add this pdf to the existing pdf. For this i would need to purchase licenced copied of the drivers per user :(

    So I am looking for any way that i can retrieve data from excel and convert it to either a pdf or any image file format like .tif that is easily converted to .pdf.

    I don't know if i made my problem any clearer..

    Thanks,
    Pam


  • EGShaw

    Hi,

    why would you want to convert your file to a .pdf file before printing

    regardless of the format, the file printed is the same,

    you would need to export (save as) pdf to get a .pdf file...

    Could you give me some more information about the what and why

    also, is this in a web application

    Kind regards



  • averge joe

    Hi

    one of the things i did in the past was create a crystal reports report, which is by defautl printable to a pdf file..

    could you do that instead of generating a .xls file

    http://support.businessobjects.com/communitycs/technicalpapers/rtm_reportingoffadonetdatasets.pdf



  • RLRTech

    Bumping it up
  • Am i in the wrong forum with this Query, could somebody direct me to the correct one?C# convert Excel to PDF or any image format