Merging Documents (64-bit)

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Post Reply
glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Merging Documents (64-bit)

Post by glima » Mon Jan 21, 2019 6:09 pm

I have a very interesting issue. Where the code works on some machines and not others (Win 64 with all Updates)

I have a C# wrapper class for merging documents. The function below takes adds the pages from one document to another.

Log from Working machine
2019/01/21 10:44:25.05 -> AddPages (a1) 0 - 562692148 - C:\Users\George Lima\AppData\Local\Temp\[BATES]-Merge.PDF
2019/01/21 10:44:25.05 -> AddPages (b1) -2081161214
2019/01/21 10:44:25.05 -> AddPages (a2) 0 - 562692552 - C:\Users\George Lima\AppData\Local\Temp\[BATES] Merge_Doc.PDF
2019/01/21 10:44:25.05 -> AddPages (b2) 0
2019/01/21 10:44:25.05 -> AddPages (c) 0
2019/01/21 10:44:25.05 -> AddPages (e) 0
2019/01/21 10:44:25.06 -> AddPages (f) 0


Log from non working machine
2019/01/21 10:42:04.74 -> AddPages (a1) 0 - 520486964 - C:\Users\John\AppData\Local\Temp\[BATES]-Merge.PDF
2019/01/21 10:42:04.74 -> AddPages (b1) -2081161214
2019/01/21 10:42:04.74 -> AddPages (a2) 0 - 520487368 - C:\Users\John\AppData\Local\Temp\[BATES] Merge_Doc.PDF
2019/01/21 10:42:04.74 -> AddPages (b2) 0
2019/01/21 10:42:04.75 -> AddPages (c) 0
2019/01/21 10:42:04.75 -> AddPages (e) -2113404927
2019/01/21 10:42:04.75 -> AddPages (f) -2113404927


Function being performed

Code: Select all

        public int AddPages(string outputfile, string inputfile)
        {
            int retval = -99;
            try
            {
                int file1, file2;
                res = PDFXCp_Funcs.PXCp_Init(out file1, PDFXCp_Funcs.g_RegKey, PDFXCp_Funcs.g_DevCode);
                log.ErrorLog("AddPages (a1) " + res.ToString() + " - " + file1 + " - " + outputfile);
                retval++;
                res = PDFXCp_Funcs.PXCp_ReadDocumentW(file1, outputfile, 0);
                log.ErrorLog("AddPages (b1) " + res.ToString() );
                retval++;

                res = PDFXCp_Funcs.PXCp_Init(out file2, PDFXCp_Funcs.g_RegKey, PDFXCp_Funcs.g_DevCode);
                log.ErrorLog("AddPages (a2) " + res.ToString() + " - " + file2 + " - " + inputfile);
                retval++;
                res = PDFXCp_Funcs.PXCp_ReadDocumentW(file2, inputfile, 0);
                log.ErrorLog("AddPages (b2) " + res.ToString());

                int count = 0;
                res = PDFXCp_Funcs.PXCp_GetPagesCount(file2, out count);
                log.ErrorLog("AddPages (c)  " + res.ToString());
                retval++;
                if (count > 0)
                {
                    PDFXCp_Funcs.PXCp_CopyPageRange[] pRanges = new PDFXCp_Funcs.PXCp_CopyPageRange[1];
                    pRanges[0].StartPage = 0;
                    pRanges[0].EndPage = count - 1;
                    pRanges[0].InsertBefore = -1;
                    res = PDFXCp_Funcs.PXCp_InsertPagesTo(file2, file1, pRanges, 1, 0);
                    log.ErrorLog("AddPages (e)  " + res.ToString());
                    retval++;
                    res = PDFXCp_Funcs.PXCp_WriteDocumentW(file1, outputfile,
                            PDFXCp_Funcs.PXCp_CreationDisposition.PXCp_CreationDisposition_Overwrite,
                            (int)PDFXCp_Funcs.PXCp_WriteDocFlag.PXCp_Write_Release);
                    log.ErrorLog("AddPages (f)  " + res.ToString());
                }
                PDFXCp_Funcs.PXCp_Delete(file2);
                retval++;
                retval = count;
            }
            catch
            {

            }
            return (retval);
        }

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 13414
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Merging Documents (64-bit)

Post by Tracker Supp-Stefan » Wed Jan 23, 2019 1:22 pm

Hello glima,

Thanks for your post and sample code.
I am checking with a colleague from the dev team now, and as soon as we have any advise - we will post it here for you!

Regards,
Stefan

glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Re: Merging Documents (64-bit)

Post by glima » Wed Jan 30, 2019 5:32 pm

I think it was a timing issue. I reworked the function to use the "while" so that I could use another library to merge files if this function failed. (This other library has drawbacks because you have to add 2 files to a third, which can be time consuming when a large number of files is being processed.)

This new process is working on ALL test machines.

Code: Select all

        public int AddPages(string outputfile, string inputfile)
        {
            int retval = -99;
            int count = 0;
            try
            {
                Logger("AddPages  " + outputfile + " - "  + inputfile);

                int file1, file2, res;
                res = PDFXCp_Funcs.PXCp_Init(out file1, PDFXCp_Funcs.g_RegKey, PDFXCp_Funcs.g_DevCode);
                Logger("AddPages (a1) " + res.ToString() + " - " + file1 + " - " + outputfile);
                retval++;
                res = PDFXCp_Funcs.PXCp_ReadDocumentW(file1, outputfile, 0);
                Logger("AddPages (b1) " + res.ToString() );
                retval++;
                res = 0;
                while (res == 0)
                {
                    res = PDFXCp_Funcs.PXCp_Init(out file2, PDFXCp_Funcs.g_RegKey, PDFXCp_Funcs.g_DevCode);
                    Logger("AddPages (a2) " + res.ToString() + " - " + file2 + " - " + inputfile);
                    retval++;

                    res = PDFXCp_Funcs.PXCp_ReadDocumentW(file2, inputfile, 0);
                    Logger("AddPages (b2) " + res.ToString());
                    retval++;

                    res = PDFXCp_Funcs.PXCp_GetPagesCount(file2, out count);
                    Logger("AddPages (c)  " + res.ToString() + " - " + count);
                    retval++;
                    if (count > 0)
                    {
                        PDFXCp_Funcs.PXCp_CopyPageRange[] pRanges = new PDFXCp_Funcs.PXCp_CopyPageRange[1];
                        pRanges[0].StartPage = 0;
                        pRanges[0].EndPage = count - 1;
                        pRanges[0].InsertBefore = -1;
                        pRanges[0].Reserved = 0;
                        res = PDFXCp_Funcs.PXCp_InsertPagesTo(file2, file1, pRanges, 1, 0);
                        Logger("AddPages (e)  " + res.ToString());
                        retval++;
                        res = PDFXCp_Funcs.PXCp_WriteDocumentW(file1, outputfile,
                                PDFXCp_Funcs.PXCp_CreationDisposition.PXCp_CreationDisposition_Overwrite,
                                (int)PDFXCp_Funcs.PXCp_WriteDocFlag.PXCp_Write_Release);
                        Logger("AddPages (f)  " + res.ToString());
                    }
                    PDFXCp_Funcs.PXCp_Delete(file2);
                    retval = count - 1;
                    res = 1;
                };
                retval++;
                //PDFXCp_Funcs.PXCp_Delete(file1);
            }
            catch
            {
            }
            Logger("AddPages (z)  " + retval);
            return (retval);
        }

Post Reply