Generate branded, customizable PDF reports of Copyleaks scan results (plagiarism, AI detection, and grammar feedback), delivered via webhook.
This document provides a comprehensive overview of the essential steps for creating and customizing PDF reports, setting up report generation, handling webhooks, and managing completed reports.
The PDF API allows you to generate detailed and customizable PDF reports of scan results, including plagiarism checks, AI detection, and Grammar Checker feedback. These reports can be branded with your own logo and customized to match your organization’s needs.The PDF generation process is integrated with the Copyleaks scanning process, where you enable PDF creation during scan submission and then receive the generated PDF through webhooks.Copyleaks API also offers different PDF report versions, with version 3 being the latest and most feature-rich option that includes advanced formatting and comprehensive analysis visualization.
PDF files for keeping records of individual scan results, which complement the interactive reports, are created through the download functionality in the report UI. If you have other PDF requirements to complement the interactive report options, please contact Copyleaks Support.
To enable PDF report generation, we first need to generate an access token. We will use the login endpoint.The API key can be found on the Copyleaks API Dashboard.Upon successful authentication, you will receive a token that must be attached to subsequent API calls via the Authorization: Bearer <TOKEN> header.This token remains valid for 48 hours.
To boost performance, cache your login token and reuse it for all requests. The token remains valid for up to 48 hours, so you don’t need to log in repeatedly. The login method has stricter rate limits than other endpoints.
POST https://id.copyleaks.com/v3/account/login/apiContent-Type: application/json{ "email": "<EMAIL_ADDRESS>", "key": "<API_KEY>"}
Use the submit file endpoint to send content for analysis while enabling PDF report generation. The key difference for PDF reports is including the properties.pdf.create parameter set to true.In the URL, supply your chosen scan ID, which serves as the identifier for the scan. Each scan needs to have a unique scan ID.The properties.pdf.reportVersion should be set to “latest” to use the latest PDF report format with enhanced visuals and comprehensive data visualization.The properties.pdf.title allows you to customize the title that appears on the PDF report.The properties.displayLanguage allows you to generate the PDF report in a specific language.For branding purposes, you can include your organization’s logo using properties.pdf.largeLogo (PNG format, base64 encoded, max 100kb, recommended size 185x50px).
There are more customization options available for PDF reports, but this guide doesn’t cover all of them.For this tutorial, we also pass in properties.sandbox as TRUE to enable sandbox mode. The sandbox mode is free to use, but it returns mock results. Using sandbox mode while working on integrating with the Copyleaks API is helpful.
# Submit a file for scanning with PDF generation enabledscan_id = "<SCAN_ID>";file_name = "<FILE_NAME>"base64_file_content = base64.b64encode(b'Hello world.').decode('utf8') # or read your file and convert it into BASE64 presentation.print("Submitting a new file...")file_submission = FileDocument(base64_file_content, file_name)# Set scan properties with PDF optionsscan_properties = ScanProperties('https://your.server/webhook?event={\{STATUS\}}')scan_properties.set_sandbox(True) # Turn on sandbox mode. Turn off on production.# Enable PDF report generationscan_properties.set_pdf({ "create": True, "reportVersion": "v3", "title": "Custom PDF Report Title" # Add base64_logo if needed})file_submission.set_properties(scan_properties)# Submit the file for scanningCopyleaks.submit_file(auth_token, scan_id, file_submission)print("Sent to scanning with PDF report enabled")print("You will be notified, using your webhook, once the scan is completed.")
// Submit a file for scanning with PDF report enabledconst scanId = "<SCAN_ID>"; // Replace with your unique scan IDconst filename = "<FILE_NAME>";const fileContent = Buffer.from('Hello world').toString('base64'); // Convert file content to base64const submitFile = async (authToken) => { const scanProperties = new copyleaks.ScanProperties('https://your.server/webhook?event={\{STATUS\}}'); scanProperties.setSandbox(true); // Enable sandbox mode for testing // Enable PDF report generation scanProperties.setPDF({ create: true, reportVersion: "v3", title: "Custom PDF Report Title" // Add largeLogo if needed }); const fileSubmission = new copyleaks.FileSubmission(fileContent, filename); fileSubmission.setProperties(scanProperties); try { await copyleaks.submitFile(authToken, scanId, fileSubmission); console.log('File submitted for scanning with PDF report enabled. Scan ID:', scanId); } catch (error) { console.error('Failed to submit file:', error); }};
// Submit a file for scanning with PDF report enabledString scanId = "<SCAN_ID>"; // Replace with your unique scan IDString filename = "<FILE_NAME>";String fileContent = Base64.getEncoder().encodeToString("Hello world".getBytes()); // Convert file content to base64ScanProperties scanProperties = new ScanProperties("https://your.server/webhook?event={\{STATUS\}}");scanProperties.setSandbox(true); // Enable sandbox mode for testing// Enable PDF report generationMap<String, Object> pdfProperties = new HashMap<>();pdfProperties.put("create", true);pdfProperties.put("reportVersion", "v3");pdfProperties.put("title", "Custom PDF Report Title");// Add largeLogo if neededscanProperties.setPDF(pdfProperties);FileSubmission fileSubmission = new FileSubmission(fileContent, filename);fileSubmission.setProperties(scanProperties);try { Copyleaks.submitFile(authToken, scanId, fileSubmission); System.out.println("File submitted for scanning with PDF report enabled. Scan ID: " + scanId);} catch (CommandException e) { System.out.println("Failed to submit file: " + e.getMessage());}
The PDF report can be extensively customized to match your organization’s branding and requirements.
Property
Type
Description
Default
create
boolean
Add a request to generate a customizable export of the scan report, in a pdf format. Set to true in order to generate a pdf report for this scan.
false
title
string
Customize the title for the PDF report. Maximum 256 characters.
null
colors
object
Object containing color customization options for the PDF report.
-
largeLogo
string (base64)
Customize the logo image in the PDF report. Only supports png format. Max file size: 100kb. Recommended size: width 185px, height 50px.
null
rtl
boolean
When set to true, the text in the report will be aligned from right to left.
false
reportVersion
string
PDF version to generate. By default latest version will be generated. Version 3 is the latest iteration of the PDF report. Available values: v1, v2, v3, latest
The scan and PDF report generation may take seconds to minutes, depending on the content, features used, and products enabled.Once the scan is complete successfully, Copyleaks API will send a completed webhook to the URL you supplied in the submit under properties.webhooks.status. At the same time, the {STATUS} is replaced with “completed”.The completed webhooks hold the summary information about the scan, such as the number of matched words, total words, and results found.If the scan finishes with an error, an error webhook will be sent to the properties.webhooks.status while the {STATUS} is replaced with error.
For testing purposes, we recommend using a third-party service such as request bin or ngrok.
Use the export method to retrieve the generated PDF report along with other scan artifacts. The export method sends webhooks with each artifact’s content to your specified target server.We supply the Scan ID we used earlier in the submit endpoint in the URL. The user chooses a unique Export ID for each export.For PDF reports specifically, we add a pdf section to the export request, providing an endpoint where the PDF should be sent when ready.
# Export scan results including PDF reportexport_id = "<EXPORT_ID>"export = Export()export.set_completion_webhook('https://your.server/webhook/export/completion')# Export PDF reportpdf_export = ExportPDF()pdf_export.set_endpoint('https://your.server/webhook/export/pdf')pdf_export.set_verb('POST')pdf_export.set_headers([['key', 'value'], ['key2', 'value2']]) # optionalexport.set_pdf(pdf_export)# Trigger the exportCopyleaks.export(auth_token, scan_id, export_id, export)print("Export initiated. You will be notified via webhook once the export is completed.")
// Export scan results including PDF reportconst exportId = '<EXPORT_ID>';const exportResults = async (authToken, scanId) => { const exportRequest = new copyleaks.Export(); exportRequest.setCompletionWebhook('https://your.server/webhook/export/completion'); // Export PDF report const pdfExport = new copyleaks.ExportPDF(); pdfExport.setEndpoint('https://your.server/webhook/export/pdf'); pdfExport.setVerb('POST'); exportRequest.setPDF(pdfExport); try { await copyleaks.export(authToken, scanId, exportId, exportRequest); console.log('Export initiated with PDF report. Export ID:', exportId); } catch (error) { console.error('Failed to export results:', error); }};
// Export scan results including PDF reportString exportId = "<EXPORT_ID>";Export exportRequest = new Export();exportRequest.setCompletionWebhook("https://your.server/webhook/export/completion");// Export PDF reportExportPDF pdfExport = new ExportPDF();pdfExport.setEndpoint("https://your.server/webhook/export/pdf");pdfExport.setVerb("POST");exportRequest.setPDF(pdfExport);try { Copyleaks.export(authToken, scanId, exportId, exportRequest); System.out.println("Export initiated with PDF report. Export ID: " + exportId);} catch (CommandException e) { System.out.println("Failed to export results: " + e.getMessage());}