khazri achraf
khazri achraf

Reputation: 17

how to save pdf with PDFIUM c++

Is there any example that shows how to use FPDF_SaveAsCopy() function for saving PDF document ? I can't find any examples anywhere !

Upvotes: 1

Views: 1756

Answers (1)

I'm not familiarized with c++. But I can give you a C# example. So you can get an idea and convert it to c++.

string test_doc = "myTest.pdf";
FPDF_DOCUMENT doc = FPDF_LoadDocument(test_doc, NULL);
var stream = new FileStream(filename, FileMode.Create);
FPDF_SaveAsCopy(doc, stream, 0, 0);

        public static bool FPDF_SaveAsCopy(FPDF_DOCUMENT document, Stream stream, SaveFlags flags, int version = 0)
        {
            byte[] buffer = null;
            FPDF_FILEWRITE fileWrite = new FPDF_FILEWRITE((ignore, data, size) =>
            {
                if (buffer == null || buffer.Length < size)
                    buffer = new byte[size];
                Marshal.Copy(data, buffer, 0, size);
                stream.Write(buffer, 0, size);
                return true;
            });

            if (version >= 10)
                return FPDF_SaveWithVersion(document, fileWrite, flags, version);
            else
                return FPDF_SaveAsCopy(document, fileWrite, flags);
        }

I hope this will help you any way.

Upvotes: 1

Related Questions