Rank: Guest
Groups: Guests
Joined: 1/5/2016(UTC) Posts: 162
Was thanked: 5 time(s) in 5 post(s)
|
Hello, I am using the trial version of the Pdfium.net sdk in my Unity project (.net 3.5, x64, mono compiler). I am getting a MarshalDirectiveException from the Patagames.Pdf.Net.PdfCustomLoader.GetBlockData() function. The code: Code:
//Open and load a PDF document from a file.
PdfDocument doc = PdfDocument.Load( @"C:\FillableFields.pdf" ); // <----- Exception is thrown here
Stacktrace: MarshalDirectiveException: Non LPArray marshalling of arrays to managed code is not implemented. (wrapper native-to-managed) Patagames.Pdf.Net.PdfCustomLoader.GetBlockData (intptr,uint,intptr,uint) <IL 0x00013, 0x0012d> Patagames.Pdf.Pdfium.FPDF_LoadCustomDocument (Patagames.Pdf.FPDF_FILEACCESS,string) <IL 0x00013, 0x000dd> Patagames.Pdf.Net.PdfCustomLoader.Load () <IL 0x0000c, 0x00091> Patagames.Pdf.Net.PdfDocument.Load (Patagames.Pdf.Net.PdfCustomLoader) <IL 0x00001, 0x00052> Patagames.Pdf.Net.PdfDocument.Load (System.IO.Stream,Patagames.Pdf.Net.PdfForms,string,bool) <IL 0x0003f, 0x00249> Patagames.Pdf.Net.PdfDocument.Load (string,Patagames.Pdf.Net.PdfForms,string) <IL 0x0000e, 0x000db> PDFTest.LoadPDF () (at Assets/External/Pdfium/PDFTest.cs:27)
|
|
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,138
Thanks: 10 times Was thanked: 133 time(s) in 130 post(s)
|
Hi, Looks like some unsupported behaviour with non LP arrays in mono. I can suggest the following workaround for this Code:
static void Main(string[] args)
{
PdfCommon.Initialize();
IntPtr docHandle = Pdfium.FPDF_LoadDocument(@"C:\FillableFields.pdf", null);
if (docHandle == IntPtr.Zero)
throw ProcessLastError();
using (var doc = PdfDocument.FromHandle(docHandle))
{
//Gets second page from document;
PdfPage page = doc.Pages[1];
//Gets number of characters in a page or -1 for error.
//Generated characters, like additional space characters, new line characters, are also counted.
int totalCharCount = page.Text.CountChars;
//Extract text string from the page
string text = page.Text.GetText(0, totalCharCount);
}
}
public static Exception ProcessLastError()
{
uint code = Pdfium.FPDF_GetLastError();
switch (code)
{
case 1: return new UnknownErrorException();
case 2: return new PdfFileNotFoundException();
case 3: return new BadFormatException();
case 4: return new InvalidPasswordException();
case 5: return new UnsupportedSecuritySchemeException();
case 6: return new PageNotFoundException();
case 126: return new PageNotFoundException();
case 0x20000000 | 0x00001: return new ImageObjectIsEmptyException();
case 0x20000000 | 0x00002: return new NoLicenseException();
case 0x20000000 | 0x00003: return new NoLicenseException("The requested operation cannot be completed due to a license restrictions. You need to have at least a Developer Small Business License to be able to complete this operation.");
case 0x20000000 | 0x00004: return new NoLicenseException("The requested operation cannot be completed due to a license restrictions. You need to have at least a LITE License to be able to complete this operation.");
case 0x20000000 | 0x00005: return new NoLicenseException("The requested operation cannot be completed due to a license restrictions. You need to have a full license to be able to complete this operation.");
case 0x20000000 | 0x00011: return new PdfiumException(code, "Can't find parent dictionary for given bookmark.");
default: return new PdfiumException(code, "Unexpected error code.");
}
}
|
|
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close