mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 08:08:07 +02:00
[api-minor] Remove the manual passing of an AnnotationStorage
-instance when calling various API-method
Note how we purposely don't expose the `AnnotationStorage`-class directly in the official API (see `src/pdf.js`), since trying to use *multiple* ones simultaneously doesn't really make sense (e.g. in the viewer). Instead we lazily initialize, and cache, just *one* instance via `PDFDocumentProxy.annotationStorage` which should thus be available internally in the API itself without having to be manually passed to various methods. To support these changes, the `AnnotationStorage`-instance initialization is moved into the `WorkerTransport`-class to allow both `PDFDocumentProxy` and `PDFPageProxy` to access it. This patch implements the following simplifications: - Remove the `annotationStorage`-parameter from `PDFDocumentProxy.saveDocument`, since it's already available internally. Furthermore, while it's currently possible to call that method without an `AnnotationStorage`-instance, that really does *not* make any sense at all. In this case you're effectively reducing `PDFDocumentProxy.saveDocument` to a "regular" `PDFDocumentProxy.getData` call, but with *a lot* more overhead, which was obviously not the intention of the `PDFDocumentProxy.saveDocument`-method. - Try to discourage third-party users from calling `PDFDocumentProxy.saveDocument` unconditionally, as a replacement for `PDFDocumentProxy.getData` (note the previous point). - Replace the `annotationStorage`-parameter, in `PDFPageProxy.render`, with a boolean `includeAnnotationStorage`-parameter which simply indicates if the (internally available) `AnnotationStorage`-instance should be used during rendering (e.g. for printing). - By removing the need to *manually* provide `annotationStorage`-parameters to various API-methods, using the API should become simpler (e.g. for third-parties) since you no longer need to worry about manually fetching and passing around this data.
This commit is contained in:
parent
6429ccc002
commit
72ef183085
5 changed files with 38 additions and 39 deletions
|
@ -635,14 +635,13 @@ var Driver = (function DriverClosure() {
|
|||
optionalContentConfigPromise: task.optionalContentConfigPromise,
|
||||
};
|
||||
if (renderPrint) {
|
||||
const annotationStorage = task.annotationStorage;
|
||||
if (annotationStorage) {
|
||||
const docAnnotationStorage = task.pdfDoc.annotationStorage;
|
||||
const entries = Object.entries(annotationStorage);
|
||||
if (task.annotationStorage) {
|
||||
const entries = Object.entries(task.annotationStorage),
|
||||
docAnnotationStorage = task.pdfDoc.annotationStorage;
|
||||
for (const [key, value] of entries) {
|
||||
docAnnotationStorage.setValue(key, value);
|
||||
}
|
||||
renderContext.annotationStorage = docAnnotationStorage;
|
||||
renderContext.includeAnnotationStorage = true;
|
||||
}
|
||||
renderContext.intent = "print";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue