Comments (8)
that's because of the Retina scaling feature of Fabric.js. canvas is scaled by devicePixelRatio (it's 4 in my S9 for example) instead of 1 in the desktop. see here.
so, concerning your issue, you have just to disable "enableRetinaScaling" attribute in the creation of the fabrice object.
in pdfannotate.js, change the function initFabric:
this.initFabric = function () {
var inst = this;
$('#' + inst.container_id + ' canvas').each(function (index, el) {
var background = el.toDataURL("image/png");
var fabricObj = new fabric.Canvas(el.id, {
freeDrawingBrush: {
width: 1,
color: inst.color
},
enableRetinaScaling: false // <====== add this line
});
inst.fabricObjects.push(fabricObj);
if (typeof options.onPageUpdated == 'function') {
fabricObj.on('object:added', function() {
var oldValue = Object.assign({}, inst.fabricObjectsData[index]);
inst.fabricObjectsData[index] = fabricObj.toJSON()
options.onPageUpdated(index + 1, oldValue, inst.fabricObjectsData[index])
})
}
fabricObj.setBackgroundImage(background, fabricObj.renderAll.bind(fabricObj));
$(fabricObj.upperCanvasEl).click(function (event) {
inst.active_canvas = index;
inst.fabricClickHandler(event, fabricObj);
});
fabricObj.on('after:render', function () {
inst.fabricObjectsData[index] = fabricObj.toJSON()
fabricObj.off('after:render')
})
});
}
hope that helps.
from pdfjsannotations.
You export and save the JSON
pdf.serializePdf(); // returns JSON string with canvas data
pdf.loadFromJSON(serializedJSON) // continue edit with saved JSON
from pdfjsannotations.
Sorry sir, I'm a student.
How to convert JSON to pdf file?
from pdfjsannotations.
When you open PDF file from this plugin, it converts PDF pages into images and render those images into FabricJS canvases. that's how you were able to draw things on top of the PDF. When you serialize those canvases it will convert those images to base64 format and outputs a JSON with all annotations. So when you want to open that file again you can pass that JSON into pdf.loadFromJSON
function. The biggest drawback of this plugin is this process removes the ability to select text from PDF. I have started to fix this issue but it's still early dev stage.
from pdfjsannotations.
Thank you so much for detail information and guideline.
from pdfjsannotations.
I think that he want to upload the final pdf as a file on the server.
if it's what you want, you can do it with ajax after rendering with doc.output() instead of doc.save().
to do so, in script.js add the function:
function saveToServer(link) {
pdf.saveToServer(link);
}
then, add in pdfannotate.js the function:
PDFAnnotate.prototype.saveToServer = function (link) {
var inst = this;
var doc = new jsPDF();
$.each(inst.fabricObjects, function (index, fabricObj) {
if (index != 0) {
doc.addPage();
doc.setPage(index + 1);
}
doc.addImage(fabricObj.toDataURL(), 'png', 0, 0);
});
var file = new File([doc.output('blob')], 'file.pdf', { type: "application/pdf"});
var formData = new FormData();
formData.append('file', file);
jQuery.ajax(link,
{
method: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(data){console.log(data)},
error: function(data){console.log(data)}
});
}
finally, change the button in index.html to point to the new function:
<button class="btn btn-light btn-sm" onclick="savePDF()"><i class="fa fa-save"></i> Save</button>
to
<button class="btn btn-light btn-sm" onclick="saveToServer('link_to_backend_function')"><i class="fa fa-save"></i> Save</button>
the link_to_backend_function
point to the method receiving and storing the pdf in the server with your back-end language.
hope that helps.
from pdfjsannotations.
@hichamhargal Thank you so much. It's working. But when I access from tablet (iPad), it crop my document and big file size. Do you have solution?
from pdfjsannotations.
@crackedurheart007 hope above answer fixed your issue. I'm gonna close this for now. Feel free to re-open if you need
from pdfjsannotations.
Related Issues (20)
- Enable annotation layer (text and link)
- 2 Pages View like a book
- load or save pdf slow HOT 1
- Saved PDF text is blurry HOT 1
- loadFromJSON loses backgroundImage HOT 1
- Memory canvas use exceeds the maximum limit (254mb) HOT 1
- loading image from sample_output breaks background HOT 3
- Arrow | Pencil Tool Glitch HOT 1
- Can't Save PDF HOT 1
- get the coordinates of x,y ?
- TEXT LAYER HOT 3
- add zoom in / zoom out buttons
- Add predefinited image to canvas
- return saved image as base64
- Password protected pdf with password how to open Please Tell Me.
- Getting Blur PDF after saving Annotation HOT 1
- on a tablet I scroll to the canvas and can't scroll below? HOT 2
- PDF file does not open HOT 7
- Place image on the currently viewed page
- Edting PDF?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfjsannotations.