Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Convert Office files to PDF

Posted on 2010-01-07
14
Medium Priority
?
459 Views
Last Modified: 2012-05-08
Hello all,
We have 2 issues:
1) We have Office 2003 files we want to convert to PDF programmatically.  We'd like to use the Adobe PDF printer but have not been able to find anything for .Net programming.  I don't know if I've just been going down the wrong path in my research or what.  I'd like to get some direction for code and/or examples and information on how to do this in .Net.  
2) We also have Office 2007 files we'd like to convert to PDF programmatically.  We found both SaveAs and ExportAsFixedFormat.  I don't know which is the better one to use, if there is one.  Having said that, I have coded and tested both SaveAs and ExportAsFixedFormat for Word, Excel and PowerPoint and it all works great with the exception of the SaveAs for Excel which does not contain a FileFormat for PDF.  

Please let me know if any further information is needed.  Thank you in advance!
0
Comment
Question by:chilekitty
  • 7
  • 5
  • 2
14 Comments
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 26204597
For 1)
Research on how to print a document to any printer.  Then just choose the Adobe PDF printer and that will take care of everything for you.

2)  Does ExportAsFixedFormat offer PDF for Excel?  If so use that one.
0
 

Author Comment

by:chilekitty
ID: 26204747
Thank you for the quick response.....
1) Won't I need the distiller?  Or does that matter?  Is that all there is to it?
2) It does not offer PDF; I have referenced Microsoft.Office.Interop for all 3 but Excel does not contain that file type.  So which procedure is best SaveAs or ExportAsFixedFormat?
Thanks,
Suzi
0
 
LVL 41

Accepted Solution

by:
Kyle Abrahams earned 2000 total points
ID: 26204900
1)  The adobe PDF printer should automatically take a print job and convert it to PDF no?  If not I know of the cutePDF writer (freeware) which does the same thing.  I think the distiller is for taking files in one directory and automatically converting them.

An easy test before coding would be to try to print to the pdf writer.  If it converts the file with no distiller then it will work the same whether a user or program does it.

With regards to saveas vs export:
saveas:
http://msdn.microsoft.com/en-us/library/aa220734(office.11).aspx

export:
http://msdn.microsoft.com/en-us/library/bb256835.aspx

It looks like the export only does PDF/XPS whereas the saveas can do a whole bunch of them.  Not sure what your requirements are regarding that.

2)  
http://www.pcreview.co.uk/forums/thread-3728103.php

Let me know if you have more issues/questions.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:x77
ID: 26204934
http://juixe.com/techknow/index.php/2006/01/25/word-to-pdf/
Set word = CreateObject("Word.Application")
Set docs = wdo.Documents
' Remember current active printer
Set sPrevPrinter = wdo.ActivePrinter
' Select the PDFCreator as your printer
word.ActivePrinter = "PDFCreator"
' Open the Word document
Set document = docs.Open(sMyDocumentFile)
' Print the document file to the PDFCreator
word.ActiveDocument.PrintOut
document.Close WdDoNotSaveChanges
word.ActivePrinter = sPrevPrinter
word.Quit WdDoNotSaveChanges
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 26204949
Yep, like I said, print right to the PDF printer.
0
 

Author Comment

by:chilekitty
ID: 26204964
Again...thanks for responding so quickl :)
1)Let me do a bit more research based on your suggestion; maybe I was looking too hard.
2)I will read up on these...
Thanks
0
 

Author Comment

by:chilekitty
ID: 26205311
Thanks x77; I will work with what you sent
0
 

Author Comment

by:chilekitty
ID: 26211174
Ok here is where I'm at:
1) Still need help here :  You're right ged325, no distiller is needed; that's good.  But x77 where I might have a problem (please correct me if I'm wrong anyone) that the printer is specific to an Application, like word, excel, ppt - so if this is true then that would mean that I would need to make a new or active printer for each application depending on the file.  We'd like the ability to have the user select a file or multiple files or a directory and for each file convert to PDF (i.e. print to Adobe PDF). Is there a 'generic' way for doing this without the use of another 3rd party?  

2) Unless others have an opinion, Office 2007 to PDF is settled:
Thanks for the info ged325; The last link provide the information that I needed;
Use ExportAsFIxedFormat for excel to PDF...which will lead me to implement this for all Office files to PDF (docx, xlsx, pptx) to retain some standard in code.

Thanks all!
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 26211779

1)
You could right your own app for it:
Essentially have an OpenFile dialog, then add the files to a listbox.
User clicks a process button and you can open and print each document directly to the printer.

OR
2) (Just thought of this)  Instead of assigning the printer for the application, change the default printer.  As long as the printer exists, this will work for any application.  When you're done, simply change the default printer back and you are good to go.
0
 

Author Comment

by:chilekitty
ID: 26212148
ged325 #1- not viable at this time but would be an option if nothing else is found to work
ged325 #2- was something I was looking into earlier based on the comment by x77 (change the active printer); I can do that through an 'Application', but how can this be done outside an 'Application'?  x77 your code works, we'd just have to do this for each document/application....we'd really like something more 'generic' like ged325's  #2 option.
Does someone have some code or examples for accessing and assigning a printer and then printing out a document in .Net without going through an 'Application'?  Hope this makes sense; just started getting my feet wet in printing and .Net.
Thank you for all your help!
0
 
LVL 41

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 2000 total points
ID: 26287531
Note:
by default anything written in .net is an application in and of itself . . . so not sure what you mean by "outside of an application"

Get default printer:
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/fe615570-ce3e-419b-86fc-7f98aed71c8f

For setting the default printer:
(note you can just call     SetDefaultPrinterWinNT ("Adobe pdf") )
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Controls/Q_20789664.html

(then you would call the setdefault() again with the old printer name to reset)

You then just need to process files . . . but this is where I don't know how you want to go about it.


The app will need to know what files to print.  (Unless you just want to have a mini application to toggle, the printer).  If that's the case you can just have the user minimize your window (adobe PDF will be set as default) they can print whatever, then click the toggle again to reset it back to default)






0
 

Author Comment

by:chilekitty
ID: 26350025
Sorry ged325 and all; it's been a little crazy me. Let me get reaquainted with the issues again and look at your suggested sites and will get back :)
Thanks!
0
 
LVL 15

Expert Comment

by:x77
ID: 26350551
If you install PDFCREATOR, it give us samples in the install directory for MsAccess (Vba), Word, VbNet, CSharp...
In the MsAccess sample, it set and restore the Default Printer to print a report.

C:\Archivos de programa\PDFCreator\COM\MS Office\modPDFCreatorAccess.bas

With PDFCreator1
  .cStart "/NoProcessingAtStartup"
  .cOption("UseAutosave") = 1
  .cOption("UseAutosaveDirectory") = 1
  .cOption("AutosaveDirectory") = "C:\"
  .cOption("AutosaveFilename") = RepName
  .cOption("AutosaveFormat") = 0                            ' 0 = PDF
  DefaultPrinter = .cDefaultPrinter
  .cDefaultPrinter = "PDFCreator"
  .cClearCache
  DoCmd.OpenReport RepName, acViewNormal
  .cPrinterStop = False
 End With

.....
 With PDFCreator1
  .cDefaultPrinter = DefaultPrinter
  Sleep 200
  .cClose
 End With

0
 

Author Closing Comment

by:chilekitty
ID: 31674246
Thanks ged325 you provided us with the most suggestions and options to our issues.  Thanks all!!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question