Decorated in a PDF version for e-books
Often hanging on habré and not only many times I caught myself thinking that the information and articles much more efficiently perceived from your phone or tablet when reading in a comfortable position, or even home — transport, business trips, etc. game with a file for the original Habrahabr convert to PDF-option for comfortable offline reading on e-book — rather a curious variant of the experiment, where there are several interesting services and well-known technologies: PHP, CURL, ajax, js, css.
So, everything in order.
Long matured the idea to purchase the e-book on e-ink ink. All the known arguments in favor of this: less eye strain and longer work time on a single charge. Not welcoming "the harvesters" a La "all in one", settled on the Amazon Kindle version 6, which is due to a popular Bulletin Board got me almost the price as on ebay, but immediately and with the opportunity to haggle and touch. Reviews of this model on the web abound, but the main essence is in the sufficient conservatism of the manufacturer. Yes, this e-book in all of its manifestations. There is an mp3 player, applications, games and other features. Strictly popular global formats "digitization of paper" and a simple browser, nothing more. Note that the initial rate on the built-in browser were clearly exaggerated. And the same Habr opened in a very small version of the font, rendered "Gabrovski" the color of the header #b5b5b5 in a very soft color. In General, reading directly from a browser, a bit strained.

Moreover, in contrast to downloaded books, turning over to the next page with one click, the browser's scroll had the standard "telephone" method, by swiping your finger from bottom to top. And if kalenom mathar the glass of the phone such gestures have somehow not noticed, gentle, sensitive and slightly rough e-ink display is somehow not raised a hand to RUB a few hours a day. Besides, even blind, because the image gets drawn only when you release the finger and the eye was forced to look for a place where to continue to read.
Then the idea to program a "proxy" for easy surfing and the most interesting export to PDF. Pretty quickly, I wrote a PHP layer, the entrance of which is in GET parameter was passed to the url of the target site using CURL and which has requested the desired resource.
Such a simple solution has been successfully tested on a PC and book. Of course, all css-styles and js-scripts safely "lost", because this is the simplest code didn't account for relative links in the html code of the site that you are parsing.
To correct this unfortunate oversight, I had to implement
To stay no longer wanted and I began to think on improving their ideas.
Formulated the following wishes for improving the usability of a web surf:
All the adjustments I decided to make a replacement similar to the above manipulations with the substitution of references.
The design idea does not stand still — experiments with easy scrolling I decided to start with the simplest button, which is rigidly attached to the lower right corner of the screen. As planned, click on it was to call a simple function that using scrollBy would be moving, scrolling to the desired value down. Intermediate tested codes will not lead. Alas, all of these examples, brilliant running on a standard PC, was not workable in kindleberger... All known cross-browser function, even just giving the value of the current scroll, were given 0 or undefined when the tests on the device. Moreover, even the button that has clearly set the positioning to fixed and tied to the bottom of the screen, in the book of scrolls together with the website. After spending half an hour (and my Rato proportional to the number of nerves per hour * 0.5), I decided to go the other way. Which turned out to be quite workable and comfortable.
Namely, I wanted to make a handy export to PDF, to not be distracted by features browser-books — and easy to read, the benefit of doing this from a file is much more comfortable. Besides offline reading relevant where there is no wi-fi.
MonitorIV current resources quick export web pages to PDF ( selectpdf.com and web2pdfconvert.com), I reassigned the function to your fixed buttons on the fast export.
Yes, this solution worked. Selectpdf.com the referer field value determines where they came from the user, converts this page and pays with the correct mime header. For the user this means exactly that he is not aware of the existence selectpdf.com but only jmackay the magic button on my site — and almost immediately downloaded the pdf. Oh, and "my website" is not the correct expression... Because in this case all content courtesy of Abram. However, I don't plan to put the service to the public and I think that for my personal goals this parsing CURL-om does not bring any problems myself Habru in this case.
So, we seem to be close to my goal to read a page in magic downloaded pdf version. But Kindle again prepared us a surprise! Downloading in the browser is only allowed in several formats, MOBI, TXT, and a couple. Don't quite understand the limitation, because the book itself copes with most formats, including RTF and Word's. DOC(X).
Well, here is a crazy programming. And excitement.
I remember about a curious synchronization of documents, which laid Amazon to your device. Namely, each authorized user is a personal account and a personal "cendrowski" email, which can be white list of boxes to send letters with the documents and they magically appear in the book. A parody of dropbox and other cloud file storage. But do not use this opportunity would be foolish. Moreover, the tests showed that in such a scenario, "courier delivery of documents to the book," successfully loaded a PDF though, at least any other from the list of supported Kingdom.
Now about the second half of the "bridge" that we will continue to build. And that is exactly how the bridge was created in my mind during the analysis of all variants of the task. Namely, the service PdfByEmail provide one of those services that I monitor for previously. The essence — you can send the target url to the portal web2pdfconvert.com in the letter, putting in the subject line the key word and Convert the response (as promised by the developers of the service — within 1...3 min) will receive a letter with prefacename PDF nick. Brilliant! For our case the most. After all, we can make a response letter was sent directly to the book, i.e. its authorised email. All you need to do is add the email conversion service no-reply@web2pdfconvert.com the white list Amazon personal account.
I had to rewrite the function of the same fixed-the buttons on the bottom of the site. Now she runs an ajax request to another page of my website, indicating what url you want to parse. Because I wasn't sure whether jquery on all sites where I wander, and to connect their would be cumbersome, I had to remember the old days when I was doing ajax on native js, without frameworks.

Of course, in the beginning I tested sending it to your mailbox, and then decided to run the entire chain. I was afraid that my letter, sent from a domain that does not match the email domain to reply kindle.com, will be banned by spam filters PDF service. But all went well and worked first time. Exactly 2-3 minutes, as claimed by the developers web2pdfconvert — and the file falls in the book with a NEW label.
Will sum up. Now, thanks to home-made proxies, I have the opportunity to surf your favorite sites in the book in a convenient scale, contrast. And stumbled on an interesting article, one click to send it for conversion, knowing that in three minutes it will fall to me in the book in PDF version. Roughly speaking, you can see a daily news feed and to bring the articles that interested you. And then read them offline and with a friendly usability. By the way, as it turned out, web2pdfconvert saves links. So even reading the PDF I can also, as before, to discover something on the hyperlink from the document. For example, the comments section or the "related articles" at the bottom.
By the way, I had to implement another small hack regarding spoilers in articles Habra. Because in the PDF they are no longer open...
Finita La Commedia! Now read your favorite articles, and even through the makeshift crutch (well, that is a crutch) — brings even more pleasure. Of course, there is still room to improve the idea. For example, the names of the files which are sent by the Converter equal to mysyte-EN and do not depend on further links. I think that can be solved through the creation of subdomains. To at least supernovost-mysyte-EN or something had a different name. It should read about limits on the length of domain names. Well, in titles sometimes podglyuchivaet the Converter (see below). But it's the little things.

Article based on information from habrahabr.ru
So, everything in order.
Long matured the idea to purchase the e-book on e-ink ink. All the known arguments in favor of this: less eye strain and longer work time on a single charge. Not welcoming "the harvesters" a La "all in one", settled on the Amazon Kindle version 6, which is due to a popular Bulletin Board got me almost the price as on ebay, but immediately and with the opportunity to haggle and touch. Reviews of this model on the web abound, but the main essence is in the sufficient conservatism of the manufacturer. Yes, this e-book in all of its manifestations. There is an mp3 player, applications, games and other features. Strictly popular global formats "digitization of paper" and a simple browser, nothing more. Note that the initial rate on the built-in browser were clearly exaggerated. And the same Habr opened in a very small version of the font, rendered "Gabrovski" the color of the header #b5b5b5 in a very soft color. In General, reading directly from a browser, a bit strained.
Moreover, in contrast to downloaded books, turning over to the next page with one click, the browser's scroll had the standard "telephone" method, by swiping your finger from bottom to top. And if kalenom mathar the glass of the phone such gestures have somehow not noticed, gentle, sensitive and slightly rough e-ink display is somehow not raised a hand to RUB a few hours a day. Besides, even blind, because the image gets drawn only when you release the finger and the eye was forced to look for a place where to continue to read.
Then the idea to program a "proxy" for easy surfing and the most interesting export to PDF. Pretty quickly, I wrote a PHP layer, the entrance of which is in GET parameter was passed to the url of the target site using CURL and which has requested the desired resource.
the First sketches code
$q = $_GET['q'];
if ( get_magic_quotes_gpc()) $q=addslashes(stripslashes(trim($q)));
if ($ch = curl_init()) {
// Initialize CURL parameters
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0');
curl_setopt($ch, CURLOPT_URL, $q );
$p = curl_exec($ch);
// Output to browser
header("Content-Type: text/html; charset=utf-8");
echo $p;
} else echo 'failed to initialize CURL!';
Such a simple solution has been successfully tested on a PC and book. Of course, all css-styles and js-scripts safely "lost", because this is the simplest code didn't account for relative links in the html code of the site that you are parsing.
To correct this unfortunate oversight, I had to implement
replace relative links to absolute:
Pay attention to pairs of replacement single and double quotes in the code Hebestreit met both spellings.
$p = str_replace ('href=\'/', 'href=\'http://m.habrahabr.ru/' , $p);
$p = str_replace ('href="/', 'href="http://m.habrahabr.ru/' , $p);
$p = str_replace ('src=\'/', 'src=\'http://m.habrahabr.ru/' , $p);
$p = str_replace ('src="/', 'src="http://m.habrahabr.ru/' , $p);
Pay attention to pairs of replacement single and double quotes in the code Hebestreit met both spellings.
To stay no longer wanted and I began to think on improving their ideas.
Formulated the following wishes for improving the usability of a web surf:
-
the
- Scale (for comfortable reading needed to increase the size of fonts in 2 times); the
- Color (due to color e-ink all the "fashion" colors had to do pokorrektnee);
All the adjustments I decided to make a replacement similar to the above manipulations with the substitution of references.
Introduction to CSS add-ons
// we Increase the scale of the whole page and set color to black for maximum contrast reading
$p = str_replace ('</head>', '<style>body { zoom:2; } * {color: #000 !important; }</style></head>', $p);
The design idea does not stand still — experiments with easy scrolling I decided to start with the simplest button, which is rigidly attached to the lower right corner of the screen. As planned, click on it was to call a simple function that using scrollBy would be moving, scrolling to the desired value down. Intermediate tested codes will not lead. Alas, all of these examples, brilliant running on a standard PC, was not workable in kindleberger... All known cross-browser function, even just giving the value of the current scroll, were given 0 or undefined when the tests on the device. Moreover, even the button that has clearly set the positioning to fixed and tied to the bottom of the screen, in the book of scrolls together with the website. After spending half an hour (and my Rato proportional to the number of nerves per hour * 0.5), I decided to go the other way. Which turned out to be quite workable and comfortable.
Namely, I wanted to make a handy export to PDF, to not be distracted by features browser-books — and easy to read, the benefit of doing this from a file is much more comfortable. Besides offline reading relevant where there is no wi-fi.
MonitorIV current resources quick export web pages to PDF ( selectpdf.com and web2pdfconvert.com), I reassigned the function to your fixed buttons on the fast export.
Implementation of a button for quick download page in PDF
// Manipulation styles
$p = str_replace ('</head>', '<style>body { zoom: 2; } * {color: #000 !important; } .fixed-buttons {position: fixed; right: 0; bottom: 0; margin-top: 0; background-color:gray; width:40px; height:40px;} </style></head>', $p);
// Button code (before the closing BODY tag)
$p = str_replace ('</body>', '<a class="fixed-buttons" href="http://selectpdf.com/save-as-pdf">PDF</a></body>', $p);
Yes, this solution worked. Selectpdf.com the referer field value determines where they came from the user, converts this page and pays with the correct mime header. For the user this means exactly that he is not aware of the existence selectpdf.com but only jmackay the magic button on my site — and almost immediately downloaded the pdf. Oh, and "my website" is not the correct expression... Because in this case all content courtesy of Abram. However, I don't plan to put the service to the public and I think that for my personal goals this parsing CURL-om does not bring any problems myself Habru in this case.
So, we seem to be close to my goal to read a page in magic downloaded pdf version. But Kindle again prepared us a surprise! Downloading in the browser is only allowed in several formats, MOBI, TXT, and a couple. Don't quite understand the limitation, because the book itself copes with most formats, including RTF and Word's. DOC(X).
Well, here is a crazy programming. And excitement.
I remember about a curious synchronization of documents, which laid Amazon to your device. Namely, each authorized user is a personal account and a personal "cendrowski" email, which can be white list of boxes to send letters with the documents and they magically appear in the book. A parody of dropbox and other cloud file storage. But do not use this opportunity would be foolish. Moreover, the tests showed that in such a scenario, "courier delivery of documents to the book," successfully loaded a PDF though, at least any other from the list of supported Kingdom.
Now about the second half of the "bridge" that we will continue to build. And that is exactly how the bridge was created in my mind during the analysis of all variants of the task. Namely, the service PdfByEmail provide one of those services that I monitor for previously. The essence — you can send the target url to the portal web2pdfconvert.com in the letter, putting in the subject line the key word and Convert the response (as promised by the developers of the service — within 1...3 min) will receive a letter with prefacename PDF nick. Brilliant! For our case the most. After all, we can make a response letter was sent directly to the book, i.e. its authorised email. All you need to do is add the email conversion service no-reply@web2pdfconvert.com the white list Amazon personal account.
I had to rewrite the function of the same fixed-the buttons on the bottom of the site. Now she runs an ajax request to another page of my website, indicating what url you want to parse. Because I wasn't sure whether jquery on all sites where I wander, and to connect their would be cumbersome, I had to remember the old days when I was doing ajax on native js, without frameworks.

a Bunch of js and php that is responsible for sending letters to the conversion service
Frontend
the
Backend:
the
Setting exp=1 to send the link I added for a slightly different display of the web page to PDF Converter for my viewer.
The Converter is too "Melcher", and for him I did triple the scale of the body in css. In addition, the export document was not to be seen my fixed button. This and ran the flag exp=1.
the
// AJAX
function getXmlHttp() {
var xmlhttp;
try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {
try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}
catch (E) {xmlhttp = false;}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
// ajax-sending commands
www_to_pdf function(q) {
var req = getXmlHttp();
req.onreadystatechange = function() {
if (req.readyState == 4) {
if(req.status == 200) {
if (req.responseText == "ok") {
alert('Request for conversion of the document has been sent successfully!');
} else alert(req.responseText);
} else alert(req.status);
}
}
req.open('GET', 'www_to_pdf.php?q=' + encodeURIComponent(q), true);
req.send(null); // send the request
}
Backend:
the
$q = $_GET['q'];
if ( get_magic_quotes_gpc()) $q=addslashes(stripslashes(trim($q)));
// Send e-mail
$title = "convert";
$headers = "From: myamazonlogin<myamazonlogin@kindle.com>\r\nReply-To: myamazonlogin<myamazonlogin@kindle.com>\r\nContent-type: text/plain; charset=utf-8\r\n";
$ret = mail('submit@web2pdfconvert.com', $title, "http://mysite.ru/proxy.php?exp=1&q=$q", $headers);
if ($ret == 1) echo 'ok';
else echo $ret;
Setting exp=1 to send the link I added for a slightly different display of the web page to PDF Converter for my viewer.
The Converter is too "Melcher", and for him I did triple the scale of the body in css. In addition, the export document was not to be seen my fixed button. This and ran the flag exp=1.
Of course, in the beginning I tested sending it to your mailbox, and then decided to run the entire chain. I was afraid that my letter, sent from a domain that does not match the email domain to reply kindle.com, will be banned by spam filters PDF service. But all went well and worked first time. Exactly 2-3 minutes, as claimed by the developers web2pdfconvert — and the file falls in the book with a NEW label.
Will sum up. Now, thanks to home-made proxies, I have the opportunity to surf your favorite sites in the book in a convenient scale, contrast. And stumbled on an interesting article, one click to send it for conversion, knowing that in three minutes it will fall to me in the book in PDF version. Roughly speaking, you can see a daily news feed and to bring the articles that interested you. And then read them offline and with a friendly usability. By the way, as it turned out, web2pdfconvert saves links. So even reading the PDF I can also, as before, to discover something on the hyperlink from the document. For example, the comments section or the "related articles" at the bottom.
By the way, I had to implement another small hack regarding spoilers in articles Habra. Because in the PDF they are no longer open...
the Problem was solved a couple of corrective inserts
Note the above parameter $exp, which varies the scale for converting and easy viewing.
$p = str_replace ('</head>', '<style>body { zoom: '. ( $exp ? 3 : 2 ) . '; } * {color: #000 !important; } .fixed-buttons {position: fixed; right: 0; bottom: 0; margin-top: 0; background-color:gray; width:40px; height:40px;} .spoiler_text {display:block;} </style><script type="text/javascript" src="http://mysite.ru/scripts/js/www_to_pdf.js"></script></head>', $p);
$p = str_replace ('class="spoiler_text"', 'class="spoiler_text" style="display:block; line-height: 120%;"', $p);
Note the above parameter $exp, which varies the scale for converting and easy viewing.
Finita La Commedia! Now read your favorite articles, and even through the makeshift crutch (well, that is a crutch) — brings even more pleasure. Of course, there is still room to improve the idea. For example, the names of the files which are sent by the Converter equal to mysyte-EN and do not depend on further links. I think that can be solved through the creation of subdomains. To at least supernovost-mysyte-EN or something had a different name. It should read about limits on the length of domain names. Well, in titles sometimes podglyuchivaet the Converter (see below). But it's the little things.
Комментарии
Отправить комментарий