Inserting pages size???

Talk here about issues with one of the components hosted at wxCode, or suggest features for it.
Post Reply
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Inserting pages size???

Post by dkaip »

Hello.
With wxPDFDocument lib i add in a file many pdfs. Size too big, about 700MB in almost 800 pages. Ok so far.
Now getting a part of 36 pages of this file with the lib, the size is about 400MB. Too big for 36 pages.
If i make new file with only the 3 files, that is until page 36 i will have 1.2 MB
Why is that?
Thank you.
Jim
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Inserting pages size???

Post by utelle »

dkaip wrote:With wxPDFDocument lib i add in a file many pdfs. Size too big, about 700MB in almost 800 pages. Ok so far.
In principle, the final PDF file should only be slightly larger than the sum of the sizes of the inserted PDFs. However, it also depends a bit on the settings for wxPdfDocument (for example, if compression is turned off).
dkaip wrote:Now getting a part of 36 pages of this file with the lib, the size is about 400MB. Too big for 36 pages.
If i make new file with only the 3 files, that is until page 36 i will have 1.2 MB
Why is that?
Not sure I understand what you try to tell. Is the size of the 36-page PDF 400 MB? Of which 3 files are you talking?

Without knowing the PDF files (sizes, type of content ...) you insert into a new PDF document, and without knowing the code used to produce the new PDF document, I'm not able to analyze whether the observed behaviour is normal or result of a bug in wxPdfDocument.

Regards,

Ulrich
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: Inserting pages size???

Post by dkaip »

Ok i will send the code and files, but not all files, there are 78.
I will try it in small scale and send code and some files to see what hapends.
Thank you
Jim
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Inserting pages size???

Post by utelle »

dkaip wrote:Ok i will send the code and files, but not all files, there are 78.
I will try it in small scale and send code and some files to see what hapends.
A subset exposing the problem you observed would be enough, of course.

Maybe you can pack the files into a zip archive, upload them and send a link for download (via PM if you prefer).

Regards,

Ulrich
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: Inserting pages size???

Post by dkaip »

Hello.
I send 3 files, 1.pdf, 2.pdf, 3.pdf.
Adding these 3 files produce test1.pdf.
Then from all pages i take 2 in file test2.pdf from test1.pdf.
The sizes of 2 files are same.
I will send and the code...
File test.zip is about 45MB.
Thank you
Jim

Code: Select all

wxPdfDocument sPDF;
addFile(sPDF, "1.pdf");
addFile(sPDF, "2.pdf");
addFile(sPDF, "3.pdf");
sPDF.SaveAsFile("test1.pdf");

bool addFile(wxPDFDocument& exportPdfFile,wxString pdfFile)
{
    int pgs= exportPdfFile.SetSourceFile(pdfFile);
    for(int i=1; i<=pgs; i++)
    {
        exportPdfFile.AddPage();
        int tpl = exportPdfFile.ImportPage(i);
        exportPdfFile.UseTemplate(tpl);
    }
    return true;
}

bool addFile(wxPDFDocument& exportPdfFile,wxString pdfFile, int j)
{
    int pgs= exportPdfFile.SetSourceFile(pdfFile);
    for(int i=1; i<=j; i++)
    {
        exportPdfFile.AddPage();
        int tpl = exportPdfFile.ImportPage(i);
        exportPdfFile.UseTemplate(tpl);
    }
    return true;
}

wxPdfDocument sPDF;
addFile(sPDF, "1.pdf");
addFile(sPDF, "2.pdf");
addFile(sPDF, "3.pdf");
sPDF.SaveAsFile("test1.pdf");

Then i use ..

Code: Select all

wxPdfDocument sPDF;
addFile(sPDF, "test1.pdf",2/*pages*/);
sPDF.SaveAsFile("test2.pdf");

test.zip from dropbox ..
https://www.dropbox.com/s/svr9t3oj39nif ... s.zip?dl=0

Thank you
Jim.
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Inserting pages size???

Post by utelle »

dkaip wrote:I send 3 files, 1.pdf, 2.pdf, 3.pdf.
Adding these 3 files produce test1.pdf.
Then from all pages i take 2 in file test2.pdf from test1.pdf.
The sizes of 2 files are same.
I will send and the code...
File test.zip is about 45MB.
Thanks for the sample data files.

Unfortunately, I have to inform you that the problem you experienced is a deficiency of the current version of wxPdfDocument. The cause for the problem is that wxPdfDocument uses a single global resource dictionary for all pages. In your case this results in including all resources from all pages of test1.pdf, although you don't import all pages.

The current PDF standard (version 2.0) recommends to use a resource dictionary per page, although inheriting resources from a global (or parent) resource dictionary is still supported. wxPdfDocument was implemented mainly over 12 years ago, as a port of FPDF, based on the PDF standard version 1.6 (and later version 1.7, published in 2006). Yes, it would have been possible to implement page specific resource dictionaries back then, too, but FPDF used/uses a global resource dictionary, and I - back then just learning how to handle PDF - kept this approach.

Changing the behaviour of wxPdfDocument in respect to page resources would be a major effort. Although I have plans to overhaul wxPdfDocument in the future, there is no schedule when this will happen. I'm sorry, but you will have to live with the deficiencies of wxPdfDocument for now ... or choose another PDF library.

Regards,

Ulrich
dkaip
Super wx Problem Solver
Super wx Problem Solver
Posts: 333
Joined: Wed Jan 20, 2010 1:15 pm

Re: Inserting pages size???

Post by dkaip »

Thank you for answer. I have in mind that something like will happening.
Ok no problem at all.
Thank you.
Jim.
Post Reply