I'm trying to achieve the following:
- Get all text objects in a page
- Replace each text object for a new text object with same text but using a default font.
Code looks as follows:
publicvoidUpdateFonts(){FPDF_FONTfont=PDFium.FPDFText_LoadStandardFont(Handle,"Helvetica");for(vari=0;i<GetPageCount();i++){FPDF_PAGEpageHandle=Pages[i].Handle;FPDF_TEXTPAGEtextPageHandle=PDFium.FPDFText_LoadPage(pageHandle);varpageObjCount=PDFium.FPDFPage_CountObjects(pageHandle);for(varj=pageObjCount-1;j>0;j--){FPDF_PAGEOBJECTpageObj=PDFium.FPDFPage_GetObject(pageHandle,i);PageObjTypespageObjType=PDFium.FPDFPageObj_GetType(pageObj);if(pageObjType==PageObjTypes.Text){FPDF_PAGEOBJECTtextObj=PDFium.FPDFPageObj_CreateTextObj(Handle,font,10);byteptr=0;ulonglength=PDFium.FPDFTextObj_GetText(textObj,textPageHandle,refptr,0);if(length>0){byte[]buffer=newbyte[length];vartext=Encoding.Unicode.GetString(buffer,0,(int)length-2);PDFium.FPDFText_SetText(textObj,text);}varmatrix=newFS_MATRIX();if(PDFium.FPDFPageObj_GetMatrix(pageObj,matrix)){PDFium.FPDFPage_RemoveObject(pageHandle,pageObj);PDFium.FPDFPageObj_SetMatrix(textObj,matrix);}}}}}Now the issue I encounter is when I try to set the matrix based on matrix from the old text object (FPDFPageObj_SetMatrix). An error occurs:
PDFiumSharp.Tests.PdfDocumentTests.CloneDocument
Source: PdfDocumentTests.cs line 41
Duration: 123 ms
Message:
System.Runtime.InteropServices.MarshalDirectiveException : Cannot marshal 'parameter #2': Invalid managed/unmanaged type combination (this value type must be paired with Struct).
Stack Trace:
PlatformInvoke.FPDFPageObj_SetMatrix_Winx64(FPDF_PAGEOBJECT path, FS_MATRIX matrix)
PDFium.FPDFPageObj_SetMatrix(FPDF_PAGEOBJECT path, FS_MATRIX matrix) line 8163
PdfDocument.UpdateFonts() line 245
PdfDocumentTests.CloneDocument() line 47
RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
How can I pass this matrix to the C# interop layer? This issue is the same with other structs by the way, based on my experience.
I'm trying to achieve the following:
Code looks as follows:
Now the issue I encounter is when I try to set the matrix based on matrix from the old text object (FPDFPageObj_SetMatrix). An error occurs:
How can I pass this matrix to the C# interop layer? This issue is the same with other structs by the way, based on my experience.