PDFiumCore icon indicating copy to clipboard operation
PDFiumCore copied to clipboard

how to use FPDF_SaveAsCopy

Open insinfo opened this issue 2 years ago • 1 comments

how to use FPDF_SaveAsCopy

insinfo avatar Aug 26 '23 02:08 insinfo

This is how I use SaveAsCopy in my code:

    public void SaveAsCopy(string filePath, SaveFlags flags = 0)
    {
        FileStream? fileStream = null;

        try
        {
            fileStream = File.Open(filePath, FileMode.Create);
        
            var fileWrite = new FPDF_FILEWRITE_
            {
                Version = 1,
                WriteBlock = (IntPtr pThis, IntPtr pData, uint size) => 
                {
                    byte[] managedArray = new byte[size];
                    Marshal.Copy(pData, managedArray, 0, (int)size);
                    fileStream.Write(managedArray, 0, (int)size);
                    return 1;
                }
            };
            var result = fpdf_save.FPDF_SaveAsCopy(Document, fileWrite, (uint)flags);
        }
        catch
        {
            throw;
        }
        finally
        {
            fileStream?.Close();
        }
    }

torfluor avatar Oct 11 '24 14:10 torfluor