Skip to content

[WIP] importPdf new param support for mime types #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/pages/references/addonsdk/addonsdk-constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,18 @@ A set of constants used throughout the add-on SDK. These constants are equal to
</ul>
</td>
</tr>
<tr class="spectrum-Table-row">
<td class="spectrum-Table-cell"><p><pre>SupportedMimeTypes</pre></p></td>
<td class="spectrum-Table-cell"><p><pre>string</pre></p></td>
<td style="vertical-align: bottom;">
<p>Mime type of the source asset</p>
<ul>
<li><strong>docx</strong></li>Microsoft Word document mime type
<li><strong>gdoc</strong></li>Google document mime type
</ul>
</td>
</tr>
</tbody>
</table>


43 changes: 40 additions & 3 deletions src/pages/references/addonsdk/app-document.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,23 +465,30 @@ Refer to the [import images how-to](../../guides/learn/how_to/use_images.md#impo

Imports a PDF as a new Adobe Express document.

<!-- Removed experimental as part of https://git.corp.adobe.com/Horizon/hz/pull/113300 -->

#### Signature

`importPdf(blob: Blob, attributes: MediaAttributes): void;`
`importPdf(blob: Blob, attributes: MediaAttributes & SourceMimeTypeInfo): void;`

#### Parameters

| Name | Type | Description |
| ------------- | ------------------------------------- | --------------------------------------------------------------------------: |
| `blob` | `Blob` | The PDF to add to the page. |
| `attributes?` | [`MediaAttributes`](#mediaattributes) | Attributes that can be passed when adding PDFs to the page (i.e., `title`). |
| [`SourceMimeTypeInfo?`](#sourcemimetypeinfo) | `SourceMimeTypeInfo` | Mime type details for importing media |

#### Return Value

None

#### `SourceMimeTypeInfo`

Mime type details for importing media

| Name | Type | Description |
| ------------------| -------------------- | ----------------------------------------: |
| `sourceMimeType?` | [`SupportedMimeTypes`](./addonsdk-constants.md#constants) | Mime type of the source asset |

#### Example Usage

```js
Expand All @@ -491,6 +498,7 @@ import AddOnSDKAPI from "https://express.adobe.com/static/add-on-sdk/sdk.js";
const { document } = AddOnSDKAPI.app;

const mediaAttributes = { title: "Sample.pdf" };
const url = "https://example.com/sample.pdf";

// Import a PDF. Note this will be imported as a new Adobe Express document.
function importPdf(blob, mediaAttributes) {
Expand All @@ -510,6 +518,35 @@ async function importPdfFrom(url) {
console.log("Failed to import the pdf.");
}
}

// Import a PDF that was converted from a Word document, specifying the source mime type
async function importPdfFromWordDoc(url) {
try {
const blob = await fetch(url).then((response) => response.blob());
let options = {
title: "Imported PDF", sourceMimeType: "docx"
};
document.importPdf(blob, {
title: "Converted Document.pdf",
sourceMimeType: AddOnSDKAPI.constants.SupportedMimeType.docx
});
} catch (error) {
console.log("Failed to import the pdf from Word document.");
}
}

// Import a PDF that was converted from a Google document
async function importPdfFromGoogleDoc(url) {
try {
const blob = await fetch(url).then((response) => response.blob());
document.importPdf(blob, {
title: "Google Doc.pdf",
sourceMimeType: AddOnSDKAPI.constants.SupportedMimeType.gdoc
});
} catch (error) {
console.log("Failed to import the pdf from Google document.");
}
}
```

### importPresentation()
Expand Down