DllNotFound_Windows, libSkiaSharp, The specified module could not be found.: at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x79 at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0xe4
at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x2f
at SkiaSharp.SkiaApi.sk_matrix_post_concat(SKMatrix*, SKMatrix*) + 0x38
at sprn.spra(sprkx, SKMatrix, sprkz) + 0xe0
at Spire.Pdf.Graphics.PdfCanvas.sprc(Single, Single, sprdmc) + 0xbb
at Spire.Pdf.Graphics.PdfCanvas.TranslateTransform(Single, Single) + 0x60
at Spire.Pdf.PdfPageBase.spra(Boolean, Boolean, PdfCanvas&) + 0x522
at Spire.Pdf.Widget.PdfPageCollection.Insert(Int32, PdfNewPage, PdfPageSettings, Boolean) + 0x4bb
at Spire.Pdf.PdfDocumentBase.spra(Int32, PdfDocumentBase, PdfPageBase, List`1) + 0x208
at Spire.Pdf.PdfDocumentBase.ImportPageRange(PdfDocumentBase, Int32, Int32, Int32) + 0x599
at Spire.Pdf.PdfDocumentBase.ImportPage(PdfDocumentBase, Int32, Int32) + 0x7d
at Spire.Pdf.AOT.NLPdfDocument.PdfDocument_InsertPageLP(IntPtr, IntPtr, Int32, IntPtr) + 0xd2
I am getting this error on newPdf.InsertPage(document, i) line
import os
import uuid
import loguru, logging
# from common_functionalities.custom_loguru_lambda import logger
# from helper import upload_docs_to_s3
# from common_functionalities.config import DOCS_BUCKET_NAME
from spire.pdf import PdfDocument
PDF_PAGE_SPLIT_THRESHOLD = 20 # split for every 20 pages
def split_pdf_file(filename, file_name, request_id, md5, client_id):
try:
# Create an instance of the PdfDocument class
document = PdfDocument()
document.LoadFromFile(filename)
newPdf = PdfDocument()
pdf_chunks_s3_uris = []
current_page_number = 1
is_file_splitted = False
if document.Pages.Count >= PDF_PAGE_SPLIT_THRESHOLD:
for i in range(document.Pages.Count):
newPdf.InsertPage(document, i)
if (i + 1) % PDF_PAGE_SPLIT_THRESHOLD == 0 or (i + 1) == document.Pages.Count:
base_file_name = file_name.rsplit('.', 1)[0]
split_file_name = f"{base_file_name}_{(i // PDF_PAGE_SPLIT_THRESHOLD) + 1}.pdf"
split_file_path = f"/tmp/{split_file_name}"
s3_key = f"{client_id}/{request_id}/splits/{split_file_name}"
newPdf.SaveToFile(split_file_path)
# s3_uri = upload_docs_to_s3(split_file_path, DOCS_BUCKET_NAME, s3_key)
# try:
# os.remove(split_file_path)
# except Exception as e:
# logger.warning(f"Failed to delete split file chunk: {str(e)}")
pdf_chunks_s3_uris.append({
"s3_uri":"s3_uri",
"page_index": current_page_number,
"chunk_id": str(uuid.uuid4())
})
current_page_number += newPdf.Pages.Count
newPdf.Close()
newPdf = PdfDocument()
is_file_splitted = len(pdf_chunks_s3_uris) > 1
return is_file_splitted, pdf_chunks_s3_uris
except Exception as e:
print(e)
# logger.error(f"Error splitting PDF file: {str(e)}")
return False, [], str(e)
if __name__ == "__main__":
request_id = "1234"
md5 = "12345"
client_id = "example_client_id"
# Split PDF file
filename = "D:\\Users\\PANDA109\\Downloads\\test_split.pdf"
file_name = "test_split.pdf"
is_splitted, pdf_uris = split_pdf_file(filename, file_name, request_id, md5, client_id)
print(f"PDF Split: {is_splitted}, URIs: {pdf_uris}")