I am using Essential Objects to convert an HTML file to PDF, it is working perfectly and I can save the PDF to Hard-drive by using the following method.
In addition to convert it to a file, it can also convert it to any .NET Stream object. For example, you can convert it to a
MemoryStream
object, then retrieve the raw bytes of the PDF file from the MemoryStream and attach it to an email or any other purpose, all without creating any physical file at all by using the following method.Now my problem is that how can I print the PDF file stored in
MemoryStream
or PdfDocument
or PdfPage
to a printer?Muhammad
MuhammadMuhammad2,34522 gold badges1818 silver badges3535 bronze badges
3 Answers
Have a look at PrintDocument, its the way to go when printing in c#. To quote from the msdn site
Typically, you create an instance of the PrintDocument class, set properties such as the DocumentNameand PrinterSettings, and call the Print method to start the printing process. Handle the PrintPage event where you specify the output to print, by using the GraphicsGraphics property of the PrintPageEventArgs.
LouisLouis
I_Am_HatedI_Am_Hated
You can print a PDF document to a printer using the PdfPrinter class from HiQPdf library:
HiQPdfHiQPdf
Not the answer you're looking for? Browse other questions tagged c#pdfprinting or ask your own question.
I am writing an application in MVC4.
I have a physical pdf file on the server. I want to convert this to a memory stream and send it back to the user like this:
But how do I convert a pdf file to a memory stream?
Thanks!
meJustAndrew3,32444 gold badges2626 silver badges5353 bronze badges
user2206329user22063291,4401010 gold badges4040 silver badges7171 bronze badges
3 Answers
You don't need
MemoryStream
. Easiest way is to use overload that accepts file name:another solution is to use overload that accepts
byte[]
: or if you want use
dkozldkozlFileStream
:27.2k66 gold badges5757 silver badges6767 bronze badges
user2206329user22063291,4401010 gold badges4040 silver badges7171 bronze badges
Use an overload that uses a filename, see here. It's the easiest solution when you have a physical file.
fejesjocofejesjoco10.2k33 gold badges2828 silver badges6060 bronze badges
Not the answer you're looking for? Browse other questions tagged c#.netasp.net-mvc-4 or ask your own question.
I am using a third party tool to get the scanned content from the scanner. On button click it executes the code and gives the content as a FileStream. Now I need to save this FileStream content as a pdf file in to a specified folder.After saving I need to open the file in browser.So how can I save the FileStream as a pdf file.Please help me.
ANPANP
5,8902121 gold badges5151 silver badges7575 bronze badges
5 Answers
You might want to take a look at the C# PDF Library on SourceForge: http://sourceforge.net/projects/pdflibrary/
Roy DictusRoy Dictus28.5k55 gold badges5050 silver badges6666 bronze badges
If I'm understanding you correctly, the third party library is handing you a stream containing the data for the scanned document and you need to write it to a file? If that's the case you need to look up file I/O in C#. Here's a link and an example:
PhillPhill1,16711 gold badge88 silver badges1818 bronze badges
You can write the stream directly to the output buffer of the response.
So if you're at the point in your code where you have the filestream from the scanner. Simply read bytes from the scanner filestream and write them to the
Response.OutputStream
Set the contentType to
application/pdf
Make sure you return nothing else. The users browser will do whatever it is configured to do now, either save to disk or show in the browser. You can also save to disk on the server at this point as well in case you wanted a backup.
C Convert Stream To Pdf Example In Hindi
I'm assuming your file stream is already a pdf, otherwise you'll need to use something like itextsharp to create the pdf.
EditHere's some rough and ready code to do it. You'll want to tidy this up, like adding exception trapping to make sure the file stream gets cleaned up properly.
How to play waw zombies with friends. Mar 10, 2015 - Me and my friend have been trying to play online for a while but we cant seem to figure out how. If anyone can help out, that would be greatly. Use the play with LAN option, go to mission select and go to nazi zombies. Select which map you want. Go to invite friends, and select the friends you want to play with.
Simon
Simon HalseySimon Halsey5,06711 gold badge1616 silver badges3131 bronze badges
not sure, but maybe check this
Community♦
user833503
Another prominent PDF library (which I have used in the past as well) is iTextSharp. You can take a look at this tutorial on how to convert your Stream to PDF then have the user download it.
A mod to make your game even greater with HD Textures (Total graphical modification) Credits goes for me (Doudda) and for Jack Mills, Repodreptiles, Mamenchi, MrGorsh, Nad 4 and Mister Nublar. Jurassic park operation genesis graphics mode.
Alex R.Alex R.3,78644 gold badges2424 silver badges3737 bronze badges
Not the answer you're looking for? Browse other questions tagged c#asp.netpdfsavefilestream or ask your own question.
I have some files. It's format is PDF.Now there is a project, this project needs to convert the PDF file to Image. If the PDF is Multi-page,I just need one image that contains all of the PDF pages.I've got some answers from Google, but some of the tools are charged.
So, how to solve it with C#?Thank you very much!
I know, use the Acrobat.dll in C# can solve this problem, but it must install the Adobe Acrobat and it is not free.
loveForEverloveForEver
6 Answers
The following thread is suitable for your request.converting pdf file to an jpeg image
One solution is to use a third party library. ImageMagick is a very popular, freely available too. You can get a .NET wrapper for it here. The original ImageMagick download page is here.
- http://www.codeproject.com/KB/library/pdftoimages.aspx Convert PDF pages to image files using the Solid Framework (dead link, the deleted document is available on Internet Archive)
- http://www.print-driver.com/howto/convert_pdf_to_jpeg.html Universal Document Converter
- http://www.makeuseof.com/tag/6-ways-to-convert-a-pdf-file-to-a-jpg-image/ 6 Ways To Convert A PDF To A JPG Image
And you also can take a look at this thread:how to open a page from a pdf file in pictureBox in C#
If you use this process to convert a PDF to tiff, you can use this class to retrieve the bitmap from tiff.
Use it like so:
Gaurav DeochakkeGaurav Deochakke1,85911 gold badge1515 silver badges2424 bronze badges
You can use Ghostscript to convert PDF to images.
To use Ghostscript from .NET you can take a look at Ghostscript.NET library (managed wrapper around the Ghostscript library).
To produce image from the PDF by using Ghostscript.NET, take a look at RasterizerSample.
To combine multiple images into the single image, check out this sample: http://www.niteshluharuka.com/2012/08/combine-several-images-to-form-a-single-image-using-c/#
HABJANC Convert Stream To Pdf Example Format
HABJAN7,99922 gold badges3030 silver badges5353 bronze badges
As for 2018 still no simple answer on the question how to convert PDF to image in C#; many libs use GhostScript licensed under AGPL and in most cases expensive commercial license is required for production use.
Good alternative might be using poppler 'pdftoppm' utility which has GPL license; it can be used from C# as command line tool executed with System.Diagnostics.Process. Poppler tools are well known in Linux world, but windows build is also available.
If you don't want to integrate pdftoppm by yourself you can use my PdfRenderer poppler wrapper (supports both classic .NET Framework and .NET Core) - it is not free but pricing is very affordable.
Vitaliy FedorchenkoVitaliy Fedorchenko4,82122 gold badges2323 silver badges2727 bronze badges
This nuget package:https://www.nuget.org/packages/Pdf2Png/
is available for free and is only protected by the MIT license, which is very open.
I've tested around a bit and this is the code to get it to convert a pdf to an image. (It does save the image in the debug folder).
DaveInCaz3,98433 gold badges2222 silver badges4545 bronze badges
Melvin WinthagenMelvin Winthagen
The PDF engine used in Google Chrome, called PDFium, is open source under the 'BSD 3-clause' license. I believe this allows redistribution when used in a commercial product.
There is a .NET wrapper for it called PdfiumViewer (nuget) which works well to the extent I have tried it. It is under the Apache license which also allows redistribution.
(Note that this is NOT the same 'wrapper' as https://pdfium.patagames.com/ which requires a commercial license).
(There is one other PDFium .NET wrapper, PDFiumSharp, but I have not evaluated it.)
IMO so far, this may be the best choice of open-source (free as in beer) PDF libraries to do the job which do NOT put restrictions on the closed-source / commercial nature of the software utilizing them. I don't think anything else in the answers here satisfy that criteria, to the best of my knowledge.
DaveInCazDaveInCaz3,98433 gold badges2222 silver badges4545 bronze badges
(Disclaimer I worked on this component at Software Siglo XXI)
You could use Super Pdf2Image Converter to generate a TIFF multi-page file with all the rendered pages from the PDF in high resolution. It's available for both 32 and 64 bit and is very cheap and effective. I'd recommend you to try it.
Just one line of code..
You can take a look here: http://softwaresigloxxi.com/SuperPdf2ImageConverter.html
M. CotaM. Cota
protected by Community♦Mar 13 '18 at 7:40
Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
Would you like to answer one of these unanswered questions instead?