Jump to content

Recommended Posts

So I'm coding a system for work that lets us enter some business names/addresses into the database and allows envelopes to be printed for each business that was entered. I've mostly completed this. The database part works fine, entries can be added/edited/deleted and whatever, but the printing part is baffling me. I figured the best way to print the envelopes was to make a PDF with one page per envelope, then have the user download that and print it onto envelopes, so I wrote the code. My PDF is created and sent to the user beautifully. It looks 100% perfect on screen...then I try to print it. It seems like every printer prints it differently, and it doesn't look right on any of them. In the printer dialog I set the page size to a #10 envelope, but when the envelope finishes printing it's off center causing the top and bottom of the envelope to be lopped off. Curiously, the horizontal axis seems to be printing correctly (at least judging by the fact that the destination address is centered as it should be).

 

The envelope in question is a standard #10 envelope, no window. I used 684 x 315 as my page dimensions (found those numbers online somewhere). Apparently, this isn't good enough. As I researched the problem, I found out that converting pixels to inches on print media is a colossal pita at best. Apparently I need to take the printer's DPI setting into effect to get my correct page dimensions? I don't even know how to do that, or if it's even possible from PHP.

 

What should I do to make these print correctly? Am I even on the right track?

Link to comment
https://forums.phpfreaks.com/topic/195599-troubles-generating-a-pdf-to-be-printed/
Share on other sites

Hmm, I don't have much experience with creating PDFs via PHP, but I have a TON of experience in creating dynamic PDFs via a web interface. This was a web-based application for the customers of a national printing company. However, we utilized the web forms along with PostScript code (the native language for PDF creation). We then ran the PostScript code through a Distiller to create the PDFs.

 

I'm not certain, but I can probably guess why you are encountering some of the problems.

 

1. Fonts: In printing Fonts is one of the biggest headaches. If the font is not embedded into the PDF then the device rendering the PDF will replace the font with something else. So, if you create the PDF with a font available on your computer it will display fine on your computer but display differently on a computer without that font. There are some complexities around printing. I *think* that true type fonts can be sent from the printing computer to the printer, but that for non true-type fonts, the printer will need to have the font installed.

 

2. Page size: The horizontal size is most likely correct because a #10 envelope is pretty much the same with as an 8-1/2 x 11 page. I'm not sure why you are having problems with the vertical distance. When you open the PDF in Acrobat have you checked the dimensions in the properties and are they correct? If so, then the problem is probably a PC to Printer issue and not the PDF itself. Have you tried printing an envelope from Word to see if it prints correctly?

2. Page size: The horizontal size is most likely correct because a #10 envelope is pretty much the same with as an 8-1/2 x 11 page. I'm not sure why you are having problems with the vertical distance. When you open the PDF in Acrobat have you checked the dimensions in the properties and are they correct? If so, then the problem is probably a PC to Printer issue and not the PDF itself. Have you tried printing an envelope from Word to see if it prints correctly?

 

I think you might have hit on the problem. When I look at the properties, my PDF reader gives the dimensions as 9.50" (correct) by 4.38" (not correct). Right now, though, it's time to go home so I'm hoping the solution here is as simple as changing my page size.

Actually scratch that, I cheated a little bit and got it to work.

 

Assuming that a #10 envelope is 9.5" x 4.125", and 684 is my correct X size, I can determine that 4.125 is 43.42% of 9.5, and 43.42% of 684 is 296.9928, so that becomes my Y size.

 

I plugged that number in and it seems to work perfectly  :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.