Printing a PDF from a Windows service - c#

With C#, how can I print a PDF document (without any dialog boxes in the background) to an indicated printer?

I have used the following PDF library in the past to perform batch printing of PDF documents from a C# Windows Service.
http://www.quickpdflibrary.com/
It's a pretty decent library and if I remember correctly it only took a few lines of code to print the document. It worked very well and saved me a consider amount of time.
Also, the recommended link that discusses using DDE to launch a desktop application on a server to perform the printing is a bad idea. Adobe Reader probably doesn't support this and since it is a desktop application running in a windowless session you may run into problems with message boxes and dialog boxes. That solution just doesn't scale in my humble opinion.

here we go

Disclaimer: I work for Atalasoft
If you don't want to depend on Acrobat being on the server, you need to rasterize the PDF pages yourself and send them to the printer using the normal .NET printing API. We have a product that can rasterize PDF that uses the Foxit engine underneath. It deploys as a normal .NET assembly and doesn't require any other software to be installed.

Related

PDF with embedded font subset displays as gibberish on iPhone

I have made C# software to write PDFs ( on github here ), however PDFs with an embedded font subset which display fine in Adobe reader and other readers come out garbled on an iPhone. An example test PDF is here. Do you have any ideas on why, or suggestions on how I can find out what's wrong?
It could be as simple as a bug in your iPhone PDF viewing app.
If it tends to view correctly on different 3rd party viewers (including and excluding genuine Adobe technology) I'd lean towards that and inquire with the company making the app for them to formally investigate.

How to print formatted labels from c#

I'm writing a program that will (among other things) print out labels with variable information. I want to be able to format these labels (preferably in a GUI) at design-time, then have them print out at runtime. What tools/languages/projects can I use to accomplish this?
The label needs to include text and also Code39 or Code128 barcodes.
Printing will be done on a normal default printer, or possibly a label printer, unknown at this time.
Preference is for open-source, free projects, but any suggestions are appreciated. I'd also like to be able to distribute the program through xcopy, meaning no separate installations needed on the client.
EDIT: I'm now trying to do this using Microsoft Reporting services in local mode, but I'm still having problems getting the barcode to be readable.
There is a simple walkthrough of using our programmable ActiveReports product to do this here. Once you design the labels you can get them in PDF or print them directly (among other things). Another example of using ActiveReports to create a label maker program is here. That one uses the ActiveX/COM edition of ActiveReports but the concepts are still the same in the C#/.NET version.
We also provide a product named Data Dynamics Reports that uses a page-based metaphore for designing reports rather than the banded metephore like ActiveReports. It includes a label wizard which you can find out more about at this link.
Scott Willeke
GrapeCity inc.
Using Microsoft Reporting Services I can use a local report. Its not xcopy, but it is free and relatively easy. I just have to install report viewer on the client (and the barcode font), then I can even run the .exe from a network share.

Open docx in Windows Phone 7 programmatically

I would like to develop an app for printing service in Windows Phone 7. In the app, the users can select file to print out. Is there any way to open docx, xlsx, etc. in WP7 programmatically? I know in iPhone the WebView supports to view many file types. Is there anything similar in WP7?
If you are looking to open the document in Office, try using the WebBrowserTask to navigate to the document. There's a good chance it will open with Office.
If you want to render the document yourself, you are very much out of luck. You could try navigating to the document in a WebBrowser control, but I don't think it's supported.
Besides, there are no printing APIs so there would be no way to print it. If this is an enterprise application (ie. internal to your company), you might consider writing a web service on a local server that can accept DOCX files and print them. You could then call that service from your app to print the docs.
You will not be able to open these types of files from the isolated storage. There is no way for third-party applications to launch the external application required for viewing these file types. All of the files which you have listed in your question are XML-based open source file formats. Depending on how much time you want to spend on this, you could write your own parser or possibly utilize an open-source or commercial one.

hosting a PDF in a c# application

I am creating an ebook for a friend. He has the content in word (docx) so I have a few questions. I created a thread earlier on how to approach this and the best response was to create PDF's out of it. The main point of this was so we can have insertable textboxes, links, and table of contents.
Now I was wondering if I can host the pdfs in my application. I want to make an "adobe reader" basically. Is there a library out there that does this? Can I use installed COM/dlls to do this?
The reason for this is that I was to create like a "quiz" section on my application, or a "report card" or even a "bookmark" feature.
Thanks guys.
Making a custom PDF browser control could be an extremely challenging task. You could instead use the real Adobe Reader in your application as it is provided as a COM control which could be hosted in any Windows application. Here are the steps:
Start a new WinForms application
Make the Acrobat control available in the toolbox (Tools -> Add/Remove Toolbox Items: turn on "Adobe Acrobat 7.0 Browser Document" in COM Components tab). Don't forget to grab a cup of coffee before clicking on the COM tab.
Drag the control to the form
Manipulate it:
axAcroPDF1.LoadFile("mypdf.pdf");
axAcroPDF1.Show();
I know this has been asked before, but I can't remember where. The accepted answer was something along these lines:
It would be a very bad idea to create your own PDF reader, because:
you are not in control of when Adobe
changes specs
Adobe provides a
reader free of charge, and most
users already have it installed.
Given the previous two statements, why would you want to spend that much time on reinventing the wheel? It makes sense to reinvent the wheel when you can improve upon it, but not when you are just copying functionality that is freely available.
It would be far better to find a way to use the Acrobat reader that they have already designed, and distribute free of charge.
This is very easy to do. All you need to do us use the WebBrowser control (assuming this is WinForms) and set the DocumentSource to the PDF file. The WebBrowser control will just automatically use whatever pdf reader is already installed on the client PC, just as would Internet Explorer.
I've had very good experiences working the the Aspose libraries. They're affordable and will save you a lot of time.
You can embed Adobe Reader in your apps via the ActiveX component that is installed on your machine along with the reader. You can add it to your VS Toolbox from the COM Components tab. Anyone who has Abobe Reader installed will then be able to use your app to view PDF documents.
Note that if there is not Adobe Reader installed your program will not work, or you need somehow to provide the lib with the application.
If you want something that does not require Adobe Reader then you may like to check out the iText#.
A potential problem with using a Adobe ActiveX/com component is that the user must have Adobe Reader installed for this to work (I don't think you're able and/or allowed to redistribute the activeX control only and wouldn't want to force my users to install Adobe Reader). So for more serious work I would try to use a Pdf library that you can distribute with your code such as writing a (presumably very small) P/Invoke wrapper for the open source library http://ccxvii.net/mupdf/ or if you can/want afford it use some commercial library.
An problem with using a webbrowser control is that you have to be careful to test what happens if a target user as embedding of pdf disabled in IE. It can happen that instead of embedding you get a external adobe reader (or whatever is registered as pdf handler) pop up! There might be a workaround, but I've been bitten by this before (resulting in one of those "works on my machine" problems)

Silverlight/C# web application - send PDF to client's printer without opening

I am working on a Silverlight web application that creates PDF documents. We want our clients to print these PDF documents but we do not want them to see it or save it locally.
Is there a way to send PDF data directly to client's printer without opening it in client's browser?
Please advice.
No -- Silverlight 3 does not support printing natively.
You can usually get some things done in the browser using Javascript, but that won't let you directly send a PDF the way you're discribing.
It's possible to write a seperate app that lives on the client machine and then integrate with that... For an internal line-of-business app that could be a good solution, but the obvious drawback is that you're stepping outside of Silverlight's multi-platform bubble.
Here's an article that might be worth looking at: http://jonas.follesoe.no/PrintingInSilverlight2UsingCSSAndASPNETAJAX4.aspx (the comments are also interesting, and some of them talk about working with PDFs)
Update: Silverlight 4 now supports this.
No. Silverlight does not have access to any printer resources directly, only via javascript print functions.

Categories