mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +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
|
@ -998,9 +998,7 @@ const PDFViewerApplication = {
|
|||
try {
|
||||
this._ensureDownloadComplete();
|
||||
|
||||
const data = await this.pdfDocument.saveDocument(
|
||||
this.pdfDocument.annotationStorage
|
||||
);
|
||||
const data = await this.pdfDocument.saveDocument();
|
||||
const blob = new Blob([data], { type: "application/pdf" });
|
||||
|
||||
await this.downloadManager.download(blob, url, filename, sourceEventType);
|
||||
|
|
|
@ -66,7 +66,7 @@ function composePage(
|
|||
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
|
||||
viewport: pdfPage.getViewport({ scale: 1, rotation: size.rotation }),
|
||||
intent: "print",
|
||||
annotationStorage: pdfDocument.annotationStorage,
|
||||
includeAnnotationStorage: true,
|
||||
optionalContentConfigPromise,
|
||||
};
|
||||
currentRenderTask = thisRenderTask = pdfPage.render(renderContext);
|
||||
|
|
|
@ -48,7 +48,7 @@ function renderPage(
|
|||
transform: [PRINT_UNITS, 0, 0, PRINT_UNITS, 0, 0],
|
||||
viewport: pdfPage.getViewport({ scale: 1, rotation: size.rotation }),
|
||||
intent: "print",
|
||||
annotationStorage: pdfDocument.annotationStorage,
|
||||
includeAnnotationStorage: true,
|
||||
optionalContentConfigPromise,
|
||||
};
|
||||
return pdfPage.render(renderContext).promise;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue