C# free Doc 2 PDF solution - c#

would anyone suggest a free solution to programmatically convert Office documents (mostly .doc) to PDF in the form of a .NET library or a command-line application i can call from my program? Thanks
PS: I know I can use SaveAs PDF in newer versions of Office, but some of the clients where the program will run still have older versions of Office.

Won't GhostScript (GhostScript Website) do that for you? Otherwise, I think, under reserves, that PDFSharp might do it. If these won't do, I hope that this one will: PDFCreate. In fact, after a closer look, if Ghostcript won't do, I would perhaps consider trying PDFCreate as it provides some sample code on the wbesite I linked for it.
You might also want to consult Wikipedia on the topic: List of PDF software

You can maybe use something like PrimoPDF which basically installs a printer that when you print to it, creates a PDF document. I've never actually called it command line but since it's just another printer, any standard print code would work.
Cody

Related

How to convert office file to image

I am searching from last two days but did not find any thing.
My requirement is to create a document viewer in my web application (C#.Net) and I don't want to use any third party tool for this. Can I convert the files in image or PDF or in any common formate which can be easly render on web page. I also can not use Introp object.
Any help will be highly appreciated
You mention in one of your comments that you'd like to write all the code yourself but don't know where to start. Here's how I would go about it...
First, you'll need to familiarize yourself with the Microsoft Office Format specification. You can find that here (there's a link to the technical specification). Office documents are actually a .zip file with an XML file inside along with any binary data representing attachments. Just renamed a .docx file as .zip and you'll be able to open it up and see the XML and any other supporting documents inside (same is true for xlsx, etc...).
Then you'll need to become intimately familiar with either PDF or HTML, as your job now will be to convert the various Office document structure into PDF or HTML structure, being sure to respect page layout, margins, order, etc...
As others have said, this is a large task which is why third party tools exist today. Also, each third party toolset has it's limitation as this is really hard to "get right" in all situations and there will be edge cases that work for one document and not another (because maybe they didn't use Microsoft Word to save the .docx, maybe they used OpenOffice and OpenOffice interpreted the standard slightly differently...)
If you cannot use COM/Interop technologies in your solution, you can take a look at the specialized 3rd party options. I see that you prefer not to use them, however, there are no existing built-in solutions in the .NET Framework. Check out my answer in a similar thread that describes how to accomplish exactly the same task using 3rd party libraries (for example, DevExpress, since I have experience with it). In addition, take a look at the Documents demo, where you can see how to create images/thumbnails from different types of MS Office documents.
I believe what you need is an intermediate representation of the documents which can be converted into an image for the viewer to display.
Lets me try to explain with the below diagram:
You can use tools like smallpdf or OfficeToPDF to do that. Just integrate them into your application.
Small PDF(https://smallpdf.com/library-detail)
officetopdf (https://officetopdf.codeplex.com/)

Embedding Pdf with OpenXml in PowerPoint fails for newer versions

I need to progammatically embed Pdf documents in PowerPoint via OpenXml. According to this: Embedding files into Open XML documents using C# it is possible via OLE32.StgCreateStorageEx methods to create the necessary picture as well as the oleobject.
Unfortunately this doesn't work with current versions of PDF. On a 64 bit OS, this seems to work only with Abobe version 9.Higher version fails with error code 0x8000FFFF which translates to Catastrophic failure. This is actual true after testing it. Even the version 9 does not work reliable.
As a fallback, I used pdfium by google to create a png from the first page. This unluckily is only half the way, as the incorporated oleobject is very different from the original one. That does not hurt until the user tries to open the embedded document via doubleclick within Powerpoint. Then an error message comes up, saying the application of the document cannot be found.
Here my questions:
Has anyone information about how to improve the procedure to make it working even with never versions?
Does anybody know what the changes to the pdf document are that are necessary to incorporate a similar object like pdf does it?
Any hint is highly appreciated
Finally I made it running. Have a look here for explanation.
Actually there is only one difference compared to the code in Embedding files into Open XML documents using C# . When calling, StgCreateStorageEx OLE32.STGFMT.STGFMT_DOCFILE has to be used instead of STGFMT_STORAGE.
That makes it running even with newer Adobe versions.

Printing a Word Doc or a PDF

My program takes a word doc and manipulates it with the Codeplex DocX open source app. That works great.
Now I need to print it. I've looked for a few hours and I haven't found a good way to print the PDF version of the file. I even tried to use AcroRd32.exe and it's just plain clunky and not really usable for a serious application.
I do have it printing with the Word.Interop but that is tying me down to a specific version of Word, more specifically, the version I have on my machine. That makes the lower versions that our customers use not work and the devs cannot compile if they aren't on 2010.
I need a way to print either a pdf or a word doc (2003 or greater) seamlessly without being prompted with each document like Acrobat Reader is doing.
Anyone have any suggestions?
Thanks!
I've used the following library for printing PDFs in past projects:
http://www.debenu.com/products/development/debenu-pdf-library/
They have a free and professional (commercial) version. It's a great library and well worth the minor expense.

Open PDF and print to PDF programmatically C#

I am developing an application that is able to open and display PDFs after I open them and print them to another PDF using CutePDF, but the originals are not viewable.
I am looking for a way to programmatically open a PDF file, and print to another PDF file (not necessarily using CutePDF, just printing to another PDF is the desired functionality).
This will be integrated into a C# .NET project. Are there any suggestions how to go about doing this?
Thanks.
You could use Office Interop and generate the PDF, when you say "print to another pdf", I imagine you mean just generate? Or are you saying spool them to a pdf print driver that essentially will just create a PDF to be saved.
Use iText, which is available in Java and C# versions. I have used the Java version successfully. I recommend the iText in Action book to help you get up to speed with iText faster. The book discusses only the Java API, but I imagine you will be able to learn the principles of iText from the book and then figure out the minor differences for the C# version.
To implement this you can use PDFFlow library for generating PDF files from C#. It has easy fluent syntax and many features.
Here are many examples of real complex PDF documents: examples
Good luck :)

HTML Printing

I am too cheap to buy crystal reports so i built the report in asp.net, the only problem I'm facing is printing the report and making it look professional. On different printer's the report looks diff, i want to be able to control the final output and make the report print standard across all printers. You guys have any suggestions on how to achieve this properly?
Why not just use Reporting Services? It's free and easy to integrate with both WebForms and WinForms apps. Supports export to PDF, Excel, etc.
Mabye a stylesheet? Google it, good luck
You could try implementing a print stylesheet (you'll find many examples Googling the term), but that can be laborious if you're not familiar with css.
If you're checking out pdf solutions, I've used iTextSharp to create pdfs. It's relatively easy, open source and mature and used by many corporations.
You could try printing to a PDF. Not sure what your budget is, but ExpertPDF is a good option I'm using now.
You could create the report as a PDF using a C# library such as PDFsharp (Open-Source).
This approach allows you to:
Serve PDF files to your user, giving them the option to:
print it now
archive it for later use
Automatically email reports to your users using a scheduled task
Store generated PDFs in a database or on the file system
cutePDF is a free PDF writer and should work for what you need

Categories