Dtronix/PDFiumCore

How to pass buffers for reading of strings

Smith00101010 opened this issue · 1 comments

Hi,

thanks for your work on this project.

I am currently trying to use it to extract some information from an existing PDF file but I am wondering how I would prepare a buffer to pass to functions like fpdf_annot.FPDFAnnotGetFormFieldName() or fpdf_edit.FPDFTextObjGetText() which expect a buffer and the length of the buffer as parameters.

Would it be possible to provide an example for that? I was not able to find anything and other libraries seem to handle calls to such C functions in a differnt way, e.g. by allowing to pass a StringBuilder.

I figured it out. I already tried this before but some unrelated precondition was not met while I tried that. Now I am using

var outputArray = new ushort[1024];
var lengthInBytes = fpdf_annot.FPDFAnnotGetFormFieldName(formFill, currentAnnotation, ref outputArray[0], (uint)outputArray.Length);
var asBytes = new byte[lengthInBytes - 2];
Buffer.BlockCopy(outputArray, 0, asBytes, 0, (int)lengthInBytes) - 2;
var formFieldName = Encoding.Unicode.GetString(asBytes);

If there is a better way to do this, please let me know.