HTTP Operation Type Object DTO Why-DTOs?
Query documentPdfPreview DocumentPdfPreviewGLDtoInput

Description

The DocumentPdfPreview service allows you to preview documents in PDF format.

This service generates a binary representation of the PDF.

This binary data, often referred to as a blob can easily be displayed in a PDF viewer embedded within a browser tab.

img

Functionality

Required Parameters

To utilize this service, you need to provide the following input parameters:

Response

The service returns a DocumentPdfPreviewOutputGLDto object containing the following fields:

Key Value
Authorization Bearer Current access Token How to find?
X-TenantId Current tenant id How to find?
X-OrganizationId Current organization Id How to find?
x-api-key Primary or secondary subscription key of your app How to find?
graphQL Query
query($input: DocumentPdfPreviewGLDtoInput!) {
  documentPdfPreview(input: $input) {
    type
    id
    pdfPreview
  }
}
graphQL Variables
{
  "input": {
    "type": "SALES_INVOICE",
    "id": "{invoiceId}"
  }
}
Example Response
{
  "type": "SALES_INVOICE",
  "id": "123e4567-e89b-12d3-a456-426614174000",
  "pdfPreview": "JVBERi0xLjcKJYGBgYEKCjQgMCBvYmoKPDwKL1R5cGUgL1hPYmplY3QKL1N1YnR5cGUg..."
}

documentPdfPreview Input parameters

Fields Type Description Length
type
  • SALES_QUOTE
  • SALES_ORDER
  • SALES_DELIVERY_NOTE
  • SALES_INVOICE
Type of the document (e.g., SALES_INVOICE)  
id UUID Unique identifier of the document  

documentPdfPreview Response

Fields Type Description Length
type
  • SALES_QUOTE
  • SALES_ORDER
  • SALES_DELIVERY_NOTE
  • SALES_INVOICE
Type of the document previewed  
id UUID Unique identifier of the document  
pdfPreview String Binary representation of the PDF (Base64 encoded string)  
Info
  • pdfPreview: This is a Base64 encoded string representing the PDF file. It can be converted to a binary file and viewed in a PDF reader.

Javascript sample to display the pdf in a browser tab

To display the PDF in a browser, you can use the provided JavaScript function pdfPreviewInBrowser with the PdfPreview string.

function pdfPreviewInBrowser(base64String){
  const base64Pdf = `data:application/pdf;base64,${base64String}`;
  let pdfBlob = fetch(base64Pdf).then(res => res.blob());
  pdfBlob.then(blob => {
    const pdfUrl = URL.createObjectURL(blob);
    window.open(pdfUrl);
  });
}

img