Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Sep 25, 2024 11:16 am

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}")

abhishek1141
 
Posts: 1
Joined: Wed Sep 25, 2024 10:56 am

Thu Sep 26, 2024 6:48 am

Hello,

Thanks for your inquiry.
Kindly note that "SkiaSharp" is a dependency library for our Spire.PDF for Python, and our Spire Python products requires the C++ environment. Your error is likely due to a missing 'libSkiaSharp.dll' file. You can check if the file is missing from the dependent installation path("yourPath\python3.9\Lib\site-packages\spire\pdf\lib\libSkiaSharp.dll"). If not, we recommend uninstalling the Spire.Pdf and then reinstalling it again. If the problem still exists. Please provide us with your operating environment and your Python version for investigation. Thank you in advance.

Sincerely,
Amin
E-iceblue support team
User avatar

Amin.Gan
 
Posts: 283
Joined: Mon Jul 15, 2024 5:40 am

Return to Spire.PDF