Printing PDFs with Puppeteer/Playwright and Flexbox Layouts - pdf

If you open Chrome or Edge and visit a page with a flexbox layout, like this one, and choose Print/Save as PDF, the PDF includes the flex elements in the proper location. However, if you use Playwright and the Page object's pdf() method, flex elements are missing.
I'm fairly certain this isn't a bug with Playwright, or Puppeteer, but instead is an issue with how the headless chromium creates the pdf. Or, hopefully, it's some kind of option I'm missing somewhere. Does anyone have experience creating PDFs of pages with flexbox layouts using Playwright?

I had a similar issue where the height of the elements inside my flexbox was completely wrong in Puppeteer.
I was able to solve it by using display: inline-flex instead of display: flex

Related

What is the easiest way to implement dark mode on a html document?

For example, if I have a link like https://cultivate-newsletter-html.s3.amazonaws.com/html-mtrgr0fqddar2d1movb1qeutr0sne3mg29uuvk81 , how can I turn this to have a dark mode experience?
Currently I am rendering this in an web view on react native, and I also do have access to the actual html document.
One way I could think of would be to directly modify the css on the html document...but I am not confident that I can grab all the elements that should change to white texts on all types of html document.

SVG with images with dataURL href not rendered correctly in some engine

This SVG originated from HTML5 canvas. Which looks fine and I added images that are represented in dataurl form to avoid CORS issues.
However, when opened in chrome the image showed up fine
When opened in Adobe Illustrator, the image did not show up.
When opened with macOS preview app, the image did not show up.
I looked up SVG2 specifications for using dataURL in svg's <image> tag href attribute and they said its okay to use. So I don't understand what is causing this rendering discrepancy between different viewers.
File for reference
In short, what is the standard way to embed images into SVG.
Okay I found out it is because only Chrome supports the newer SVG2 standard href attribute on <image> element of SVG. So I just needed to replace the href with xlink:href
Even though xlink:href attribute is deprecated in SVG2. It seems the other softwares aforementioned in the question are not SVG2-compliant.

Add timestamp watermark to PhantomJS images

How can I add watermarks on Phantomjs images?
Somewhat like this:
Can page.evaluate help me here?
Any injection or while rendering should not affect the actual look of the webpage. This stamp should only overlay.
The rendering is very high level in PhantomJS. The only way is to inject the watermark as an element (think position: absolute) into the DOM through page.evaluate and remove it after the screenshot.
Finally got it.
Created a new html element which is required, from DOM method and then injected this while rendering the HTML by page.evaluate.

Facebook Application Link and JS SDK

Hello guys I have two small questions about my facebook application link and JS SDK. So let me explain:
1- Well as I understood from Facebook JS SDK, the should be left just empty. But still I am a little dizzy and I want to make sure whether we should put our page content into it or it should be left empty?
Please make me sure about it.
2- I have put some changes in my css and markup of my page but after one day I can not see some of the changes in my facebook application link.
How can I see the result of changes if there is such a way??
Thank you very much indeed.
Let me answer this for you:
1) Yes, It should be left empty and here's the info on why it's required quoted from JS SDK docs:
The JavaScript SDK requires the fb-root element in order to load properly and a call to
FB.init to initialize the SDK with your app ID correctly.
The fb-root element must not be hidden using display: none or
visibility: hidden, or some parts of the SDK will not work properly in
Internet Explorer.
The SDK inserts elements into fb-root which expect to be positioned
relative to the body or relative to an element close to the top of the
page. It is best if the fb-root element is not inside of an element
with position: absolute or position: relative. If you must place the
fb-root element inside of a positioned element, then you should also
give it a position close to the top of the body or some parts of the
SDK may not work properly.
2) It's most probably a cache problem, there's a similar question with an issue of css which has been answered previously: Caching for css content for iphone FB APP
Also to get your browser/visitors browser to re-fetch your CSS file, The trick is to pass a query param/variable at the end of the CSS file url like so: ?v=1
<link rel="stylesheet" href="css/style.css?v=1">
This will automatically make your browser or maybe even facebook to fetch your CSS file again with the new changes. Make sure to change the number everytime you update your files so you could see the changes instantly.

Can I show a PDF inside a DIV with a zoom function?

I have a large PDF and I need to show it 50% reduced in size inside a div tag that is 600px 600px in size. I also need to offer the client a zoom function.
Should I use the "object" tag? But can I reduce the pdf size inside an "object"?
Is there a jquery example or anything out there?
Need help.
<div>
<object data="febrero2012.pdf" type="application/pdf" width="600px" height="600px">
alt : febrero2012.pdf
</object>
</div >
I coudn't find the way to set a default zoom level yet. If you find a way, please let me know.
No. PDFs cannot be displayed in a DIV, as they're not html or an image. You can convert the PDF to html/images on the server and display that, just like google's "quick view" function does. But in general, PDF rendering in-browser is dependent on the presence of a plugin (e.g. Adobe Reader, Chrome's built-in rendering engine notwithstanding). Plugins can't be displayed in divs, just embed/object/iframe sections.