I want to use wkhtmltopdf to convert an html file to pdf. I was trying with various options with the wkhtmltopdf but its not giving the proper output what i wanted. I want to have the pdf with the same format as looking by saving it using control+p
The url is http://raindrops.in/subhashini/view/524e5aa14251df44518b4567
Please help me out how to use it.
If the problem is that you don't have the layout you're looking for, it is probably because you don't use wkhtmltopdf with the correct settings as far as screen size, margins etc. is concerned.
Check the available options here http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html
Check your own screen settings (width/height), and use them in wkhtmltopdf.
Related
I'm using NodeJS to do an app that finds and replaces a text in a pdf. I have found some approaches:
Using some npm package, like pdfReader, that converts pdf to json. So I get the text and replaces it with what I want. The problem it's convert the output back to pdf.
The possible solution for the first item it's to convert the PDF to HTML, edit the HTML and convert it back to pdf. But most of the tutorials using NodeJS it's about convert HTML to PDF, not PDF to HTML.
Any solutions for this problem?
Update
I ended up using PDFKit to create the pdf files that i need. In my case, this solution don't to cover all the possibles. But if you have to find a word and replace it in an unpredictable pdf file, maybe this problem has no solution in nodeJS. The PDFKit lib has an open issue for this feature.
Look at this approach how to export json data to pdf file with specify format with Nodejs?. Basically uses your idea. Convert PDF to JSON and then render the JSON in html, then convert the HTML to pdf.
Need to upload the .dwg format images and able to preview /view in a page which created using js/HTML/angularjs or Angular 2+?.
tried to implement CAD viewer js library but there is not much documentation available for that. So anyone implemented this or any idea how to view .dwg files dynamically in js/HTML/Angular?
Have tried CAD viewer library and try to embed the image with in page using HTML but no result.
Even have tried Autodesk viewer but there is no proper documentation regarding how to upload and render it.
1.http://cadviewerjs.com/cv-js_api/index_cvjs_24_viewing.html
2.https://github.com/Autodesk-Forge/viewer-javascript-offline.sample
3.http://cadviewerjs.com/cv-js_api/index_cvjs_24_viewing.html
these above links which I have tried.
Should able to upload .dwg format image and able to view it(irrespective of size, it has a size around 300MB sometimes).
The demo shows that the image is rendered to a svg image. Try inspect in chrome dev or similar. All you now has to do is either to grab the svg and store it in the DB or use some kind of svg to png script to store a png in the DB. Based on the fact that they do not show their pricing information or any kind of store you can be sure it will have 4 digits before the $ sign. And by that price i am sure they will code you that simple thing. And if client has enough money to use autocad he has also the money for the pro licence :) BTW: the images of a drawing or blocks are part of the native DWG file. There is some kind of header structure which target the embedded image which autocad stores on save. Another way is to write a autocad addon which export this image on safe. C# export block images. Note a whole drawing is also just a "block". It has the special name "*Model_Space". And also this block has a image (as long as the user does not disabled the image generation).
And last but not least also Autocad has a javascript interface which is nothing else as a headless chrome inside autocad. Put some websock interface in such a javascript component and let autocad do the exporting thing. So you can run a autocad aside to your server headless (also possible is called autocad core console).
(1) Is there a way to search for texts in a pdf file and go to that location in the pdf file using Python?
(2) Is there a way to highlight a text in a pdf file and that text get extracted, using Python?
I tried using Javascript pdf.js, which actually worked but I want to try Python. Any help would be appreciated. Thanks!
For searching for text within a PDF file you can use PyMuPDF or pdfminer. PyMuPDF would also let you create a PDF viewer and highlight the text if that's what you have in mind.
I know two libraries to create PDF files using Javascript in the browser ([1], [2]) but none of them allows to embed a custom font into the document.
[2] allows to set a custom font, but only for the standard PDF fonts (Courier, Times-Roman) and none of them is actively developed anymore.
Does anyone know a library to create PDF files in the browser that is still actively developed and supports the embedding of custom fonts?
Cheers,
Manuel
Ok, looks like current implementations do not support it.
So I'm porting libharu to javascript using emscripten:
Project:
https://github.com/manuels/hpdf.js
Demos:
http://manuels.github.com/hpdf.js/
If anyone else is looking, there's also this: https://github.com/devongovett/pdfkit
It looks more actively developed than hpdf, BUT I couldn't get it working just using browserify with the node module brfs as the docs mention (firstly brfs only works with static paths, but it also didn't seem to output the raw data from the font properly), I had to do this to get it to work:
if your font has no cmap: open, then export the font as ttf (with glyph map in the export options) with fontforge
get the base64 of the ttf file in string format (I used python to read the contents of the ttf file, encode with base64, remove line breaks, then save out to another file)
paste the string as a variable in your script
create a buffer object, and pass that as the font with pdfkit, ie
fontCenturyGothicBase64 = "your base64 encoded string here";
fontCenturyGothic = new Buffer(fontCenturyGothicBase64, 'base64');
doc.font(fontCenturyGothic);
use browserify on the javascript file (Buffer is a node object rather than pure js)
Maybe it's possible without using the Buffer object (and thus browserify), I haven't tried.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to convert HTML (containing JavaScript ) to a PDF. How can I do that?
I just want to show what is being shown in web page. I am displaying a gantt chart that is generated by a JavaScript library.
Now I want to save that HTML web page as a PDF, how to do that?
We are also looking for some way to convert html files with complex javascript to pdf.
The javasript in our files contains document.write and DOM manipulation.
We have tried using a combination of HtmlUnit to parse the files and Flying Saucer to render to pdf but the results are not satisfactory enough. It works, but in our case the pdf is not close enough to what the user wants.
If you want to try this out, here is a code snippet to convert a local html file to pdf.
URL url = new File("test.html").toURI().toURL();
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage(url);
OutputStream os = null;
try{
os = new FileOutputStream("test.pdf");
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(page,url.toString());
renderer.layout();
renderer.createPDF(os);
} finally{
if(os != null) os.close();
}
I'm surprised no one mentioned the possibility to use an API to do the work.
Granted, if you want to stay secure, converting HTML to PDF directly from within the browser using javascript is not a good idea.
But here's what you can do:
When your user hit the "Print" (for example) button, you:
Send a request to your server at a specific endpoint with details about what to convert (URL of the page for instance).
This endpoint will then send the data to convert to an API, and will receive the PDF in response
which it will return to your user.
For a user point of view, they will receive a PDF by clicking on a button.
There are many available API that does the job, some better than others (that's not why I'm here) and a Google search will give you a lot of answers.
Depending on what is written your backend, you might be interested in PDFShift (Truth: I work there).
They offer ready to work packages for PHP, Python and Node.js. All you have to do is install the package, create an account, indicate your API key and you are all set!
The advantage of the API is that they work well in all languages. All you have to do is a request (generally POST) containing the data you want to be converted and get a PDF back. And depending on your usage, it's generally free, except if you are a heavy user.
Using the browser's Print... menu item, you can utilize a PDF Printer Driver, like PDFCreator. This way any JavaScript included in the page is processed by the browser when the page is rendered.
PDFCreator is a free tool to create PDF files from nearly any Windows application.
Create PDFs from any program that is able to print
With Docmosis or JODReports you could feed your HTML and Javascript to the document render process which could produce PDF or doc or other formats. The conversion underneath is performed by OpenOffice so results will be dependent on the OpenOffice import filters. You can try manually by saving your web page to a file, then loading with OpenOffice - if that looks good enough, then these tools will be able to give you the same result as a PDF.
Check this out http://www.techumber.com/2015/04/html-to-pdf-conversion-using-javascript.html
Basically you need to use html2canvas and jspdf to make it work. First you will convert your dom to image and then you will use jspdf to create pdf with the images.
EDIT:
A short note on how it work.
We will use two libraries to make this job done. http://html2canvas.hertzen.com/ and
https://github.com/MrRio/jsPDF
First we will create a dom image by using html2canvas them we will use jspdf addImage method to add that image to pdf.
It seems simple but there are few bugs in jsPdf and html2cavas so you may need to change dom style temporarily.
Hope this helps.
Copy and paste this in your site to provide a link which will convert the page to a PDF page.
Convert To PDF
You can do it using a jquery,
Use this code to link the button...
$(document).ready(function() {
$("#button_id").click(function() {
window.print();
return false;
});
});
This link may be also helpful: jQuery Print HTML Pdf Page Options Link