php pdf generators losing content when saved (content visible on screen)

Hello

I have inherited a website which makes lots of pdf files. Luckily for me sometimes it uses fpdf, sometimes tcpdf, sometimes mpdf. Its a joy to wade through.

But i find this curious. The website generates the pdf files (haphazardly but they are made) but then when the files are saved or emailed sometimes bits of the document got missing like a logo or a contents page.

I would have thought that once the file had been generated that was it and everything was complete. I dont understand why emailing or saving the file loses information.

Because the code is is such a mess I am hoping you might give me some ideas before i post sections that might be relevant as its very hard to tell

But in theory before looking at this code. How is it possible that saving a pregenerated pdf can lose data?

Thanks
andiejeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
How is it possible that any programming error could occur?  I have never seen this happen in a PDF, but I have seen plenty of HTML emails with links that didn't work because the programmer used relative paths, and when the email was opened on a client's machine those paths didn't point to images any more.   So it could be something like a local dependency.  Steps to try to nail this down...

1. Is it always the same PDF(s) that is missing an image?
2. Can you reproduce the missing images regularly?
3. Once we know that, we can start looking at the PDF files to see if there is something unique about them.
0
Ray PaseurCommented:
Also, you might want to think about this.
http://refactoring.com/
0
andiejeAuthor Commented:
Its not just missing images - its text too
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

andiejeAuthor Commented:
Its the contents of entire pages
0
Ray PaseurCommented:
Interesting.  Is it consistent in any way - ie, can you reproduce the failure by rerunning the same script?  Or is it sporadic?

Is it the same site that you mentioned in this Q?
http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28535541.html
0
andiejeAuthor Commented:
Yes

The logo is always missing

There  is a graphic present always

There is a swirl drawn on the page and that is always there
0
andiejeAuthor Commented:
Always the same error
0
andiejeAuthor Commented:
just to be clear you seee everyhing
- logo
-content
page swirl

When document is saved logo disapears (probably a path issue)
the text in the contents is links/bookmarks to pages in the document
0
Ray PaseurCommented:
Well, since I haven't seen this code, but have seen lots of examples of really badly written code I'd like to suggest that you consider refactoring.  The site obviously does not work and probably never did, and trying to "fix" bad code usually takes longer than starting over and doing the job right - with the right data in the right places and with the right test cases along the way.

Do you know the history of the site?  Why does it use three different classes to generate PDFs?
0
andiejeAuthor Commented:
no idea! if you were me and starting again what pdf generator would you use. It doest have to be free, quality is the issue
thanks
0
Ray PaseurCommented:
I have had excellent results with FPDF, creating post cards, business cards, etc.  I've done a few scripts with TCPDF and found its documentation lacking a bit.  It seems to work, but there is a good bit of trial and error with any of these PDF extensions.  All of them seem to work OK at PHP 5.3, but that's out of date now, so I would want to set up a test case to exercise every feature I needed before I commit to development with either one of them.  I haven't used MPDF; it sounds like a seductively good idea, but the truth is that HTML is for semantic markup, and PDF is for document layout.  I just don't trust the process of trying to marry the two into one.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andiejeAuthor Commented:
progress - when the logo is removed the contents is visible on save but then add logo and content vanishes and logo is visible when you save (all the document including logo is visible in browser)

Its weird . Its finei n the web browswer but not on saving. could it be anything to do with page margins or something like that?
0
Ray PaseurCommented:
I don't know what might be wrong.  I think at this point we can't make any progress without seeing the code and the test data.
0
andiejeAuthor Commented:
My understanding - html2pdf makes a document to be converted to pdf. From my code this is some template code for one of the pages in the document


<page backimg="<?php echo $image_dir . 'backgrounds/' . $style['back']; ?>" backimgx="center" backimgy="bottom" backimgw="100%" backtop="30mm" backleft="10mm" backright="10mm" backbottom="12mm" footer="" style="font-size: 12pt; line-height:130%;" >
 
<page_header>
        <div class="pagehead">
            <table style="width:100%;">
                <tr>
                    <td style="width:70%; text-align:left;vertical-align:top; padding-top:22px;"> Safety Pack - Contents </td>
                    <td style="width:200px;text-align:right;vertical-align:top;"></td>
                </tr>
            </table>
        </div>
    </page_header>
    
    <page_footer>
        <div class="footer">
            <div <?php if (strlen($tagname) > 30) echo 'style="font-size:10pt;"';?>><?php echo $tagname ?></div>
            <div style="font-size:10pt; padding-top:10px;">Page [[page_cu]] / [[page_nb]]</div>
        </div>
    </page_footer>  
 </page>

Open in new window


I know now the developer doesnt have to put the page content in here. Bits and pieces are read in all over the place in buffers



Then this is the page that makes the pdf document. It is my understanding that the pdf header (not page header) is constant on every page

The page makes the html to be converted to pdf from all over the place including the template files

ob_start();
include(dirname(__FILE__) . '/res/front.php');
$content[$ri++] = ob_get_clean();

Open in new window




Here is the pdf header
Here is adding the logo. I out it local to be sure
  $header_img_path = "logo.png";
    //$header_img_path = PUBLIC_DIR_UPLOAD . 'logo/' . $company_logo;
    $html2pdf->pdf->Set_Header_IMG_Path($header_img_path);
    $html2pdf->pdf->setPrintHeader(true);

Then it writes the document from the content array

When something is wrong neither the pdf header nor the links show on that one page

Then on the next page its there again

Ironically the whole document displays fine in firefox as a standalone document and sumatrapdf reader
0
andiejeAuthor Commented:
The pdf in this file i was given to work with was corrupt and couldnt be verified. Please can i lose this question
0
andiejeAuthor Commented:
thnks ray
0
andiejeAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.