Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » PDF Document Margin Setup
PDF Document Margin Setup [message #1738] Mon, 20 October 2008 08:57 Go to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Tony,

I am producing some output documents that will print on pre-printed stationary. However, the actual result, as to whether or not the fields line up exactly on the document, varies slightly depending on the printer used.

I'd like to be able to set an x and y margin value that can be user adjusted (maybe read from a database table containing printer setups) that could be incorporated into the output documents.

Is there any way this type of functionality can be performed with the existing PDF functions?
Re: PDF Document Margin Setup [message #1739 is a reply to message #1738] Mon, 20 October 2008 10:17 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
The TCPDF library functions that I use to create PDF documents use default margin values which depend of the page format (A4, A5, Letter, etc). As far as I am aware it should be possible to amend these defaults by including the following code somewhere in your _cm_pre_output() method:
$this->pdf->lMargin = x;  // left margin
$this->pdf->tMargin = x;  // top margin
$this->pdf->rMargin = x;  // right margin
$this->pdf->bMargin = x;  // bottom margin

Try it and see. The only alternative would be to manually adjust the x and y coordinates as discussed in http://www.tonymarston.net/php-mysql/output-to-pdf.html#body .contents.detail3.


Re: PDF Document Margin Setup [message #1740 is a reply to message #1738] Mon, 20 October 2008 10:30 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
I'm actually using absolute positioning for the fields using the x and y values.

I'm hoping that by setting the left and top margins the x and y values will be offest (effectively becoming x+lmargin and y+tmargin) thereby moving the field positions but keeping them in the ame position relative to each other.

I'll try and let you know if it works.
Re: PDF Document Margin Setup [message #1741 is a reply to message #1740] Mon, 20 October 2008 11:39 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
If you read the documentation at http://www.tonymarston.net/php-mysql/output-to-pdf.html#body .contents.detail3 you would see that both the <x> and <y> values are absolute (which means relative to the page borders, not to any margins). The <y_relative> value is relative to the bottom of the previous cell.

Re: PDF Document Margin Setup [message #1742 is a reply to message #1738] Mon, 20 October 2008 11:44 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
That was what I was hoping would happen with x and y coordinates, but that doesn't seem to be what I'm experiencing. It appears that different printer drivers are giving different results - and quite significant at that.
Re: PDF Document Margin Setup [message #1743 is a reply to message #1742] Mon, 20 October 2008 12:05 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
That is unsual. Once a PDF document is created it is supposed to be printed exactly the same regardless of which printer is used.

Re: PDF Document Margin Setup [message #1756 is a reply to message #1738] Tue, 21 October 2008 11:05 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
Tony,

I haven't done any testing with the margins yet, but I noticed that when printing a document on a couple of different printers, the actual font appears to be a slightly different size. This could partially explain why the XY coordinates appear to be in a different position. However, there also 'appears' to be some scaling going on, as in some cases the text appears slightly to the left and in other cases slightly to the right (could be due to the effect of centering with a different size font).

I am just using the standard embedded Arial font.

Any suggestions what might be causing this type of effect?
Re: PDF Document Margin Setup [message #1758 is a reply to message #1756] Tue, 21 October 2008 11:25 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
I haven't got a clue. As far as I am aware a PDF document should appear EXACTLY the same no matter what printer it is sent to. If a printer dynamically changes the font size then that sounds like a printer problem to me.

Re: PDF Document Margin Setup [message #1759 is a reply to message #1738] Tue, 21 October 2008 13:19 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
Just an update in case anyone is in need of modifying margins, the correct way to do it is with:
$this->pdf->SetMargins(10,23,49);


as all the *Margin attributes are protected.

[Updated on: Tue, 21 October 2008 13:45]

Report message to a moderator

Re: PDF Document Margin Setup [message #1760 is a reply to message #1759] Tue, 21 October 2008 13:40 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
Not if I change them all to public! I *HATE* this private/protected nonsense in OOP.

Re: PDF Document Margin Setup [message #1765 is a reply to message #1738] Fri, 24 October 2008 05:54 Go to previous messageGo to next message
gpatti is currently offline  gpatti
Messages: 283
Registered: August 2008
Senior Member
For information, I think I have discovered the cause of this issue.

The PDF Reader print dialog has an option for page scaling, and by default this seems to be set to "Reduce to Printer Margins". If this is set to "None" I then get identical results on different printers.

Problem solved!
Re: PDF Document Margin Setup [message #1766 is a reply to message #1738] Fri, 24 October 2008 06:07 Go to previous messageGo to next message
bonzo_bcn is currently offline  bonzo_bcn
Messages: 152
Registered: June 2008
Senior Member
I'm getting diferent results in the same printer with different papers, a standard A4 isn't printed with the same margins as an A4 with prestamped labels.....weird..
Re: PDF Document Margin Setup [message #1767 is a reply to message #1765] Fri, 24 October 2008 06:08 Go to previous message
AJM is currently offline  AJM
Messages: 2347
Registered: April 2006
Location: Surrey, UK
Senior Member
Thank goodness for that! At last it wasn't due to a bug in my code (as if there could EVER be such a thing Embarassed )

Previous Topic: Print labels in PDF
Next Topic: Export selected fields from list view to CSV
Goto Forum:
  


Current Time: Wed Apr 24 11:59:39 EDT 2024

Total time taken to generate the page: 0.07996 seconds