Rectangle 27 25

I ended up bailing on Adobe Acrobat here and going with FoxIt Reader (Free pdf reader) to do my pdf printing. This is the code I'm using to print via FoxIt in C#:

Process pdfProcess = new Process();
pdfProcess.StartInfo.FileName = @"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe";
pdfProcess.StartInfo.Arguments = string.Format(@"-p {0}", fileNameToSave);
pdfProcess.Start();

The above code prints to the default printer but there are command line parameters you can use to specify file and printer. You can use the following syntax:

Apparently earlier versions of acrobat do not have the problem outlined above either. If you use a much older version (4.x or something similar) it does not exhibit this problem.

Some printers do support native pdf printing as well so it's possible to send the raw pdf data to the printer and it might print it. See https://support.microsoft.com/en-us/kb/322091 for sending raw data to the printer.

In later versions of our software we ended up using a paid product:

This saves my life! I've tried so many things to print PDFs silenty ... the Adobe Reader via command line, a windows service invoking the Adobe Reader, some WinAPI trickery. With any approach either the Adobe Reader window came up or it simply didnt print. Thanks a lot for this hint!

I'm pretty sure with the latest version of FoxIt this is no longer supported. I think they've integrated it into the paid version at this point.

c# - Printing a PDF Silently with Adobe Acrobat - Stack Overflow

c# acrobat
Rectangle 27 23

I ended up bailing on Adobe Acrobat here and going with FoxIt Reader (Free pdf reader) to do my pdf printing. This is the code I'm using to print via FoxIt in C#:

Process pdfProcess = new Process();
pdfProcess.StartInfo.FileName = @"C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe";
pdfProcess.StartInfo.Arguments = string.Format(@"-p {0}", fileNameToSave);
pdfProcess.Start();

The above code prints to the default printer but there are command line parameters you can use to specify file and printer. You can use the following syntax:

Apparently earlier versions of acrobat do not have the problem outlined above either. If you use a much older version (4.x or something similar) it does not exhibit this problem.

Some printers do support native pdf printing as well so it's possible to send the raw pdf data to the printer and it might print it. See https://support.microsoft.com/en-us/kb/322091 for sending raw data to the printer.

In later versions of our software we ended up using a paid product:

This saves my life! I've tried so many things to print PDFs silenty ... the Adobe Reader via command line, a windows service invoking the Adobe Reader, some WinAPI trickery. With any approach either the Adobe Reader window came up or it simply didnt print. Thanks a lot for this hint!

I'm pretty sure with the latest version of FoxIt this is no longer supported. I think they've integrated it into the paid version at this point.

c# - Printing a PDF Silently with Adobe Acrobat - Stack Overflow

c# acrobat
Rectangle 27 2

You might consider using a PDF Printer Driver that allows you to configure silent "printing" to a preset directory using auto-generated names.

For an example of such a product, see:

This is the best solution I've found. eDocPrinter PDF Pro (the software you linked,) even allows you to set all its settings through the registry, so you can specify names and directories, etc. Adobe PDF Printer allows for a silent mode, but I did not see any way to programatically set its settings.

vb6 - How can I programatically print a DataReport to a pdf file? - St...

vb6 pdf-generation
Rectangle 27 39

A very straight forward approach is to use an installed Adobe Reader or any other PDF viewer capable of printing:

Process p = new Process( );
p.StartInfo = new ProcessStartInfo( )
{
    CreateNoWindow = true,
    Verb = "print",
    FileName = path //put the correct path here
};
p.Start( );

How do you specify the page size with this method? I need to be able to specify a specific paper size that the default printer supports.

You can't specify anything using that method. It will only print the pdf using the default printer and its default settings. So if your default paper size is a4, any larger pages will be cut off. It really sucks, but short of 3rd party tools I don't think that there is anything that can be done about this.

Great answer, but note that Process inherits from component which implements IDisposable, so it is of course recommended to dispose it or use a using statement, especially if one uses it many times

.net - Print Pdf in C# - Stack Overflow

c# .net pdf printing
Rectangle 27 11

Apache PDFBox. It is currently in incubation, but the PDF printing functionality has been around before that. Internally, it uses the Java Print Services to create a print job, and it also supports silent printing.

Do note that it requires Fontbox as well, and the current (upcoming 0.8.0 release) has included graceful fallback for documents with Type 0 fonts. Type 1 fonts are printed correctly; however in 0.7.3, attempts to print documents with Type 0 fonts will result in an exception being thrown.

I tried this, but the pdf's printed at least mainly blank (sometimes completely blank pages, sometimes just a section).

Well, the command line (PrintPDF) seems to work and print everything (even if it makes a mess of my transparent PNG image)

That's a bit strange, considering that command line printing seems to have worked (except for the PNG image). I'll check how PNGs are represented in the PDFBox model. By the way, are you trying this with 0.7.3 or a later release?

It was a few older generated pdf's in particular... perhaps it was due to using a prior version of flying saucer to generate the pdf. Newly generated pdf's are fine. BTW +1 - it's working now...

Version 0.8.0. As for +1, I would vote, but apparently I already have, and too long ago too :(. I hope it was already an up vote.

Silent Printing of PDF From Within Java - Stack Overflow

java pdf printing pdf-generation
Rectangle 27 3

Without having access to the same printer that you are using it is hard to know exactly what is happening. My best guess would be that the driver of this printer has issues dealing with process-level fonts (those that are registered using the GDI function AddFontResourceEx) when "Enable advanced printing features" is checked. This is how Amyuni PDF Creator uses fonts embedded in the PDF file, which is the case for the file that you have presented. A possible workaround for this could be to use the attribute "PrintAsImage" of the Document class.

//set license key This is needed only with licensed version
acPDFCreatorLib.SetLicenseKey("your company", "your activation code");

//Create a new document instance
Amyuni.PDFCreator.IacDocument doc = new Amyuni.PDFCreator.IacDocument(null);

doc.AttributeByName("PrintAsImage").Value =1;

//Open the file here (...)

//Print to default printer
pdfCreator1.Document.Print("", false);

Another alternative would be to save your file as xps using Amyuni PDF Creator then send the xps file to the printer:

// Create print server and print queue.
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue();
defaultPrintQueue.AddJob("my document", "c:\\temp\\mytempfile.xps", true);

Note: GDI is not the only way to render content into a printer, there is also XPS and DirectX and the behavior of a given printer driver may change (for better or for worse) on each of them. It just happens that Amyuni PDF Creator 5.0 uses GDI for text rendering, other tools may use something else.

Thanks yms for your explanation on how fonts are embedded in Amyuni and which might cause issues under Windows service. I will tested with PrintAsImage attribute as a workaround to solve the issue. Let me know whether there are any consequences of using PrintAsImage? Please note that we are also printing with label printers and postscript printers.

Printing the pdfs as an image works but the process is very slow due to size of the file send to spooler is 15-20 times bigger and not a solution we can live with. dropbox.com/s/njh2gq9r46gd0mq/ What we have forgotten to mention is that the same printing process/code works when running it as a console application. We also use the same pdf file and same printer.

c# - AmyuniPDF prints PDF document in wrong font (special characters) ...

c# .net pdf printing
Rectangle 27 3

A really simple but not easily deployable solution is to use a WebBrowser control to load the Html and then using the Print method printing to a locally installed PDF printer. There are several free PDF printers available and the WebBrowser control is a part of the .Net framework.

EDIT: If you Html is XHtml you can use PDFizer to do the job.

c# - Convert HTML to PDF in .NET - Stack Overflow

c# html pdf itextsharp
Rectangle 27 3

The problem with matplotlibs subplots_adjust is that the values you enter are relative to the x and y figsize of the figure. This example is for correct figuresizing for printing of a pdf:

pyplot.subplots_adjust(left = (5/25.4)/figure.xsize, bottom = (4/25.4)/figure.ysize, right = 1 - (1/25.4)/figure.xsize, top = 1 - (3/25.4)/figure.ysize)

for a figure of 'figure.xsize' inches in x-dimension and 'figure.ysize' inches in y-dimension. So the whole figure has a left margin of 5 mm, bottom margin of 4 mm, right of 1 mm and top of 3 mm within the labels are placed. The conversion of (x/25.4) is done because I needed to convert mm to inches.

Note that the pure chart size of x will be "figure.xsize - left margin - right margin" and the pure chart size of y will be "figure.ysize - bottom margin - top margin" in inches

Other sniplets (not sure about these ones, I just wanted to provide the other parameters)

pyplot.figure(figsize = figureSize, dpi = None)

and

pyplot.savefig("outputname.eps", dpi = 100)
xsize
ysize
AttributeError: 'Figure' object has no attribute 'xsize'

python - Reduce left and right margins in matplotlib plot - Stack Over...

python matplotlib
Rectangle 27 6

Allow different sizes, but control each size's margins and design!

The W3 CSS3 standard established for page sizes works great with the "SAVE AS PDF" option directly from Chrome's plugin on the printing interface.

I have had years of trouble with different interfaces and go-around solutions for different proyects (for example: generating PDF's directly from server which was too heavy in processing and messy in code, or telling users to use windows printing interface, etc). This one is a great solution for me and seems to be definitive!

Here's a perfect example of the same page, with options for A4-size and Letter-size printing margins:

/* style sheet for "A4" printing */
 @media print and (width: 21cm) and (height: 29.7cm) {
    @page {
       margin: 3cm;
    }
 }
 /* style sheet for "letter" printing */
 @media print and (width: 8.5in) and (height: 11in) {
    @page {
        margin: 1in;
    }
 }

You can replicate as many times as you wish using different paper sizes. Extra values (colors, hidden elements, etc.) would go outside @page.

This doesn't quite address what I was wanting, though. If I've got one document with two 200px-by-200px divs, and another document with twenty of them, and I want to print them both and have everything come out the same size. Chrome's default PDF generation may not have that result. That's why my solution has a div of "whole page" width.

css - How to make HTML pages print at a consistent size from Chrome? -...

html css google-chrome printing print-css
Rectangle 27 3

Why are you going through the step of printing the PDF file to a PostScript file? Ghostscript is already capable of accepting a PDF file as input.

Its not possible to say what the problem 'might' be without seeing the original PDF file and the PostScript file produced by your driver. My guess would be that whatever application is processing the PDF hasn't embedded the font, or that the PostScript driver hasn't been able to convert the font into something suitable for PostScript, resulting in the font being missing in the output, and the pdfwrite device having to substitute 'something else' for the missing font.

Ghostscript (more accurately the pdfwrite device) is perfectly capable of producing a decent PDF file when the input is PDF, but your input isn't PDF, its PostScript!

To be perfectly honest, if your original PDF file isn't 'searchable' its very unlikely that the PDF file produced by pdfwrite will be either, no matter whether you use the original PDF or mangle it into PostScript instead.

The usual reasons why a PDF file are not 'searchable' are because there is no ToUnicode information and the font is encoded with a custom encoding and deos not use standard glyph names. If this is the case there is nothing you can do with the PDF file except OCR it.

The reason is because I have this printer that accepts the files from the users and it doesnt know if they're printing a word or pdf file and always converts it into postscript(because of PS driver). I don't have to use PS but it seems like this is the best when I want to create a pdf later. The original pdf is searchable, but I just saw now that they have fonts that say "embedded subset" when i use acrobatreader, could that pose a problem?

Possibly yes. I would guess that the original file has ToUnicode CMaps, which convert the text into Unicode. There is no equivalent in PostScript, because PostScript is intended for printing so knowing the Unicode equivalent is not helpful. As a result this information is discarded when you print to PostScript. If the fonts use a non-standard Encoding (very likely with subset fonts) then fundamentally you've lost the searchability right there. Try converting the PDF file directly as a test, I expect it will work. This is a flaw in your workflow I'm afraid.

Is there any other way to grab a file from a printer and convert it into a pdf then? (regardless of what the input is (word or pdf)). Are there printer drivers that doesn't do anything to the file? then I could probably see if the file is a pdf and don't do a conversion and just send it straight through.

Bascially, no. When an application displays its content on screen, it does it by making drawing calls to the Operating System (Windows, Mac, Linux, etc). What you see on-screen isn't what's in the file, its what the application draws. When you print, the OS translates those drawing commands into the language of the printer (PostScript, PDF, PCL etc). That's what the printer driver is for. You need to look at the file format before opening it with an application and printing it, once you print it, you've lost all the original information.

Print a file (pdf) to a printer with PS driver, grab PS-file and conve...

pdf ghostscript postscript
Rectangle 27 3

WeasyPrint is an open-source engine that renders to PDF and supports absolute positioning as well as CSS 3 Paged Media to set the page margins:

@page { margin: 1cm /* or 0, if you want */ }

I still couldn't make it work in the chrome though :(

css - HTML print with absolute postitions - Stack Overflow

html css printing
Rectangle 27 3

I had the same problem on printing a PDF file. There's a nuget package called Spire.Pdf that's very simple to use. The free version has a limit of 10 pages although, however, in my case it was the best solution once I don't want to depend on Adobe Reader and I don't want to install any other components.

PdfDocument pdfdocument = new PdfDocument();
pdfdocument.LoadFromFile(pdfPathAndFileName);
pdfdocument.PrinterName = "My Printer";
pdfdocument.PrintDocument.PrinterSettings.Copies = 2;
pdfdocument.PrintDocument.Print();
pdfdocument.Dispose();

.net - Print Pdf in C# - Stack Overflow

c# .net pdf printing
Rectangle 27 1

UNless the printer supports PDF you cannot send it directly to the printer. You need to rasterize it. I wrote a blog article on printing PDFs from Java at http://www.jpedal.org/PDFblog/2010/01/printing-pdf-files-from-java/

I understand that PDF-fluent printers are becoming increasingly common, but your point is still valid.

printing - Print pdf in applet using itext - Stack Overflow

pdf printing applet itext
Rectangle 27 3

You can write a key to the registry. Here is an example of the registry key for PDFing from WordPad.

For Window 64-bit OS you have to use splwow64.exe as the program. It is normally located in C:\Windows.

If it still does not work then the program name might be wrong. To see the program name, manually create a PDF from the program. Acrobat will store the program name in the registry under "LastPdfPortFolder -".

As you can see splwow64.exe was shown there, which made me google it and ultimately figured out that the Adobe Documentation was a little lacking.

printing - bypass Adobe PDF Printer "SaveFileAs" prompt - Stack Overfl...

pdf printing adobe
Rectangle 27 1

Remember PDF.js is just another web page. ATM, at least not in the standard HTML5 APIs, there is no way for a web page push random information directly to printers (but you can push it to the cloud printing service) -- you can print only what you "see". "See" means what's in the DOM, and currently CSS can be used to hide information for the screen or printer. The DOM can also be changed the beforeprint/afterprint events.

In you case, since your PDF view in embedded, you need to fake DOM to have all PDF's pages/canvases on the main web page, make them visible for print and hide for screen (see e.g. [4]). Few different problems needs to be solved too that might be off-topic here: removing margins and non-rasterizing canvas. Firefox is dealing with those via moznomarginboxes [1] and mozPrintCallback [2] -- both are created in support of PDF.js and not supported by other browsers. (See also polyfill for the latter [3])

javascript - PDF.js How do you print a multi-page pdf? - Stack Overflo...

javascript pdf printing pdf.js
Rectangle 27 1

Actually, print_media_type option is used for styling your pdf file, not for printing it. To send pdf file directly to printer you can try following:

  • Generate pdf and save it to a file: # create a pdf pdf = render_to_string pdf: "some_file_name", template: "templates/pdf", encoding: "UTF-8" # then save to a file save_path = Rails.root.join('pdfs','filename.pdf') File.open(save_path, 'wb') do |file| file << pdf end
system("lpr", "pdfs/filename.pdf")

ruby on rails - How to print generated PDF automatically with Wicked P...

ruby-on-rails ruby wicked-pdf
Rectangle 27 11

You can try this(Python-for-PDF-Generation) or you can try PyQt, which has support for printing to pdf. Python for PDF Generation The Portable Document Format (PDF) lets you create documents that look exactly the same on every platform. Sometimes a PDF document needs to be generated dynamically, however, and that can be quite a challenge. Fortunately, there are libraries that can help. This article examines one of those for Python.

How to create PDF files in Python - Stack Overflow

python pdf
Rectangle 27 4

Creating layout in html and printing afterwards into pdf is the fastest way.

Html into pdf conversion is provided by phantomjs, wkhtmltopdf or jsreport

jsreport provides direct integration with asp.net mvc views, where you can just mark controller action with attribute and it will print pdf instead of html for you.

Disclaimer: I am the author of jsreport

If you are using MVC, Rotativa is a really nice wrapper for wkhtmltopdf... super easy to use, we've converted to it to solve this problem now... There was an issue with images, but there is a workaround on SO

Yes, Rorativa is a nice wrapper. jsreport is rather a reporting server that handles images or keeps reports history for you.

Asp.Net MVC how to get view to generate PDF - Stack Overflow

asp.net-mvc pdf
Rectangle 27 4

Creating layout in html and printing afterwards into pdf is the fastest way.

Html into pdf conversion is provided by phantomjs, wkhtmltopdf or jsreport

jsreport provides direct integration with asp.net mvc views, where you can just mark controller action with attribute and it will print pdf instead of html for you.

Disclaimer: I am the author of jsreport

If you are using MVC, Rotativa is a really nice wrapper for wkhtmltopdf... super easy to use, we've converted to it to solve this problem now... There was an issue with images, but there is a workaround on SO

Yes, Rorativa is a nice wrapper. jsreport is rather a reporting server that handles images or keeps reports history for you.

Asp.Net MVC how to get view to generate PDF - Stack Overflow

asp.net-mvc pdf
Rectangle 27 2

If printing the PDF using conventional means (e.g. Adobe Reader), the PDF MUST be downloaded to the browser's cache to be opened and printed. There is no way around that.

Now you can probably prevent the average Joe from saving the PDF locally via the following technique, but any savvy user will be able to inspect your HTML's source and download the PDF directly.

  • Output your PDF in iText such that when the PDF is opened, a print action automatically occurs
  • Put an invisible IFRAME on your HTML page which loads this PDF, but is not visible in the browser to your user

When the user loads your HTML page, the PDF will be loaded in the IFRAME and sent to the users printer (presuming that Adobe Reader is installed in the browser). Yes, the PDF will end up in the browser cache, but the user would have to be savvy enough to both recognize this and then hunt it down in their browser's cache.

If this is not acceptable, you're going to have to look at converting the PDF to another file type (e.g. pages are rendered to images displayed in the browser or perhaps a Flash / Java object that sends each page in the document to the printer directly)

Hi - thanks for this answer - one problem I'm having is that the PDF print dialog is coming up REALLY slow, even when I have a simple "Hello, World" PDF. Any thoughts on how to speed it up?

java - Create a "print-only" PDF with itext - Stack Overflow

java pdf itext