• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Adobe Embed API CORS error

New Here ,
Dec 01, 2023 Dec 01, 2023

Copy link to clipboard

Copied

I am using the correct API key for my registered domain zippiai.app
The pdfs are also hosted on the same domain. I am thrown a cors error.




This is my react component code:

import React, { useEffect } from "react";
import { Grid, Paper } from "@Mitsumine/material";

function DocDisplaySection({
  pdfDocument,
  noteDocument,
  sourceDocument,
  pageNumber,
  sliderValue,
}) {
  useEffect(() => {
    if (!window.AdobeDC) {
      console.error(
        "Adobe PDF Embed API not loaded. Check script in index.html"
      );
      return;
    }

    let selectedDocument;
    let url;
    let fileName;

    if (pdfDocument) {
      selectedDocument = pdfDocument;
      url = `${process.env.REACT_APP_API}/${selectedDocument.filePath.slice(
        8
      )}`;
      fileName = pdfDocument.fileName;
    } else if (noteDocument) {
      selectedDocument = noteDocument;
      url = `${process.env.REACT_APP_API}/${selectedDocument.filePath.slice(
        8
      )}`;
      fileName = noteDocument.fileName;
    } else if (sourceDocument) {
      selectedDocument = sourceDocument;
      url = `${process.env.REACT_APP_API}/${selectedDocument.slice(8)}`;
      fileName = "source";
    }

    if (selectedDocument) {
      new window.AdobeDC.View({
        clientId: `${process.env.ADOBE_PDF_EMBED_API_KEY}`,
        divId: "adobe-dc-view",
      })
        .previewFile({
          content: {
            location: {
              url: url,
            },
          },
          metaData: { fileName: fileName },
        })
        .then((adobeViewer) => {
          adobeViewer.getAPIs().then((apis) => {
            apis
              .gotoLocation(pageNumber)
              .catch((error) => console.error(error));
          });
        });
    }
  }, [pdfDocument, noteDocument, sourceDocument, pageNumber]);

  return (
    <Grid item xs={12} sm={12} md={sliderValue}>
      <Paper
        elevation={3}
        style={{
          width: "100%",
          height: `calc(100vh - 130px)`,
        }}
      >
        <div id="adobe-dc-view" style={{ width: "100%", height: "100%" }}></div>
      </Paper>
    </Grid>
  );
}

export default DocDisplaySection;

Views

131

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 01, 2023 Dec 01, 2023

Copy link to clipboard

Copied

LATEST

I am attaching a screenshot of the error.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources