Issues printing embedded PDF - pdf

I have embedded a pdf object in a webpage. When I print this page, the embedded object does not show in the printout. The only way to print the pdf is to use the print function of the plugin, however I need to add some headers to the pdf document that is on the top of the web page. Is there a way to achieve this?

Related

MVC print PDF without displaying in view with print dialog

I have an MVC app where the intention is for the the user to click Print, and in the subsequent print dialog, verify the target printer, number of copies, etc, and click Print. I'm rendering the PDF document and returning the document thusly:
return File(printJob.Bytes, "application/pdf");
This displays the document quite nicely in the browser. In both Chrome and Edge, when the user clicks Print, they get a preview of the page in the print dialog. So the user experience is they click Print, see a preview, click print, see a preview again and then click print. Does anyone know if it's possible to render the PDF document without displaying it in the browser and instead just present the user with the print dialog box?
Thx in advance!
When you return the PDF from your website, the browser is then acting as a PDF viewer instead of a web browser, so you need to get the PDF to request the print dialog on open, not the website.
You can achieve this by adding the document javascript this.print(true) into the PDF that you are generating.
You can test this in Adobe Acrobat by going to Javascript -> Edit All Javascripts and just pasting this.print(true) at the top outside of any named function.
Tested and working on Chrome, as soon as you open the PDF it displays the print dialog.
Acrobat Javascript Reference is here, the reference to the print function is on page 179.

Print CSS with pdf included in page

I have a page where I have a lot of info about an item, with a little "Download specs pdf" button below. Clicking it opens the pdf seperately, which is all I need for the webversion.
However I'm currently working on my print css, and my goal is to create a print css here that shows the info along with the pdf below it, included in the same printfile.
Is it possible to embed the pdf in my page (only for print css)? I've tried using the <object> or embed tags but this doesn't seem to show up at all in my print css.
Update: I managed to show the pdf using iframe, but I'm unable to set the iframe height to the pdf's height. The pdf is dynamic so it's not a set height. Dynamically updating the height through jQuery has proven to be impossible because the onload event isn't fired for file downloads in an iframe. If anyone can help me come to a solution, I would be very grateful.
Thanks in advance.
The simple solution is to force a 4:3 perspective on the iframe and size it according to your print page (A4 paper size is standard here).
You can use PDF.js library's who is an amaZing JavaScript PDF viewer working cross browser. Display the PDF in a div, make it hidden with a display:none for web version with your screen CSS.
One advice I can give you is, if you know the maximum number of PDF pages, just make the iframe height large enough... that means, if the number of pages is less, the printer is going to output empty pages.
The other advice was the one stated above, get a tool to annotate or change properties of all PDFs to contain that information.
I found this tool: http://pdfcrowd.com/html-to-pdf-api/ to convert PDF into HTML, which you can use instead of displaying PDF
I'm thinking your best bet is to have a parsed version of the PDF for printing. Open it in Illustrator and save each page to SVG and use the SVG files to print with.

Embedded PDF prints off-center

<embed width="100%" height="100%" src="filename.pdf" type="application/pdf">
I can embed a PDF file into a web page using the simple code above. But when I go to print the web page (using CTRL+P), only half the PDF appears on the print preview as it has been off-centred. The same happens on this web page: http://pdfobject.com/examples/simplest-full-window.html.
Here is an example of a 'Print Version' web page where the embedded PDF centres when it is printed (CTRL+P): http://www.bbc.co.uk/food/recipes/our_paella_92328.pdf. This example is also responsive, which is useful as the print appearance remains consistent no matter the size of the browser window.
Firstly how do I centre the embedded PDF upon printing? Secondly, how do I make the embedded PDF responsive?
When you want to print an embedded PDF, you must use the print command from the PDF plugin, not the print command from the web browser.
In the first example the Javascript code loads the PDF plugin and replaces the HTML document with the PDF document. If you hit CTRL+P then the print dialog from Internet Explorer is shown. If you click into the PDF plugin then press CTRL+P, then the print dialog from Adobe PDF plugin is shown.
In second example you open directly the PDF file. In this case the PDF plugin is loaded and activated automatically. No need to click in it. Pressing CTRL+P brings its own print dialog.

Customize PDF view inside a browser

I've worked on a requirement that allows me to show a PDF file inside a browser by doingo a Response.ContentType = "application/pdf".
The problem is that the default view of the PDF is always showing the bookmarks menu at the left, is there a way by using HTTP headers or something to tell the PDF viewer not to show the bookmarks section?
Thanks in advance.
There's two ways that you can do it. The way that I would recommend is to actually open the PDF in Adobe Acrobat and go to File, Properties. On the Initial View tab you'll see a lot of options for how to display the PDF. The second way I haven't tested but Adobe says you can pass various querystring options to the PDF. The one you'd probably want is http://example.org/doc.pdf#pagemode=none
The way how a PDF document is displayed can be configured inside the PDF document.
There are a lot of PDF editors that can modify the "viewer preferences" as it is mostly called. One free example is BeCyPDFMetaEdit.

Is it not possible to print a pdf from a hyperlink?

I have looked for weeks and I keep hitting dead ends. I know you can create a text or image link and tell it to "print page" in a browser. But so far, I can't get it to print a document, specifically a pdf. I would like the print dialog to show after the link is clicked and yes, the pdf linked to has been printed.
Why does this seem to be such an impossible feat? I have seen it work in a Flash movie, but since I cannot access the native file I cannot see how it was done.
Any advice?
Thanks.
Many of today's printers support direct PDF printing. Lexmark, HP, Xerox to name a few all have this on most of the 'business' printers. On these devices simply sending the PDF file directly to the device over LPR, port 9100, or some other mechanism will result in a printed document. Some devices even support URLs. I do know that Lexmark had some devices that a URL could be sent to the printer as as long as it had access to the URL it would pull the document and print. In this case it supported basic HTML, JPEG, TIF, and PDF.
Hope this helps.
A PDF must be rendered as an image before it can be printed. Usually when you're printing a PDF file on your desktop you could simply right-click on the file and select Print and if you have Adobe Reader or an alternative application set as your default PDF viewer, then the PDF that you have selected will be opened automatically -- at this stage the PDF is rendered as an image -- and then the printing process will begin.
But if there is no access to a PDF viewer that can render the PDF and then print it, then you won't be able to print the PDF. Usually if you have Adobe Reader, Foxit Reader, etc, installed then when you click on a URL to a PDF then the PDF will open within the PDF viewer within the browser and you will be able to print it.
Alternatively, you could find a PDF SDK that silently renders a PDF as an image and then sends that to the printer, without the need to have a PDF viewer installed on your machine.