Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use FPDF_SaveAsCopy #13

Open
insinfo opened this issue Aug 26, 2023 · 1 comment
Open

how to use FPDF_SaveAsCopy #13

insinfo opened this issue Aug 26, 2023 · 1 comment

Comments

@insinfo
Copy link

insinfo commented Aug 26, 2023

how to use FPDF_SaveAsCopy

@torfluor
Copy link

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();
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants