I need to print an organigram of a large corporation with php/MySQL. The organigram will be boxes with peoples names in them, and there are just over 200. The page will be very wide and long. I want to be able to set the page size to something like 90 inches high by 300 inches wide (The PDF will be printed on an eco-plotter which is usually used to print architectural plans, but can be used to make huge black and white wall posters. I have done this many times using PageMaker/InDesign but never with php). Is it possible to do this with TCPDF and if yes how? If no, any suggestions of how I can do this in php?
Yes, TCPDF is perfectly capable of generating very large PDF documents. If you're rendering a lot of elements, it would likely be a good idea to make sure you have a high memory limit.
I created an example here: Example large format PDF
The key part is providing your own custom page size. Here's what I used in the script that generated this example:
// create new PDF document, I set landscape,
// inches for units, 300 wide and 90 deep
$pdf = new TCPDF('L', 'in', array(300,90), true, 'UTF-8', false);
The rendering part is, of course, then entirely up to you. I just had some fun with some bezier curves and cells with borders set.
//Line from Dot to Tiny
$pdf->Curve(50, 30, 50 + $offsetx, 30, 50 + $offsetx + 1 , 20 + $offsety_down,
60, 20, null, $style);
$pdf->SetXY(60, 20);
$pdf->Cell(20, 10, 'Tiny', 1, 1, 'TLRB', 0, '', 1, 'C', 'C');
If you want to use points for working with your document (which I'd suggest it over inches - it's real easy to accidentally make 1 inch thick lines and such) pass something like the following to the constructor:
Note: points are a physical unit of measure equal to 1/72 of an inch. This is not specifying rendering resolution but the actual physical size of the document. For line definitions you can use partial numbers for your physical units. For example: 0.75 to specify 3/4 of a point.
// create new PDF document, I set landscape,
// pt for units, 300 wide and 90 deep, 72 points per inch.
$pdf = new TCPDF('L', 'pt', array(300*72,90*72), true, 'UTF-8', false);
TCPDF will work with several different types of units. Another option is millimeters, for instance. Methods like SetXY and Curve and so on will then use whatever page unit you had set here.
Related
Hello to the community,
I would have one more question on Highcharts. I am working closely with designers and they prefer to have charts given to them with a predefined height, width, and text size, in millimetres (not pixels). That is because ultimately these charts are going to be printed out in reports.
Right now designers enter the value they want for a specific chart in millimetres onto a spreadsheet, and I convert all that to px before making the chart.
To convert pixel to mm I use:
px = mm * DPI / 25.4 since 1in = 25.4 mm.
For point (pt) to pixel I use:
px = pt * DPI/72 since 1pt = 1/72th of 1in.
Where DPI is a variable given to me: usually 300.
However the font size tends to be much bigger than it should be (it looks like it is 20 pt on the chart when I want 12 pt), and the chart dimensions also seem to be wrong.
My first question: do my calculations look right? (I am afraid I am not much of an image expert).
My second question: would there be a way to specify chart dimensions in a different format than pixel when configuring a chart on Highcharts, by any chance?
Thank you so very much!
You can use some of the already existing converters to get those values, like: https://www.unitconverters.net/typography/millimeter-to-pixel-x.htm
You can use CSS to set parameters for the container that the chart is rendered inside, demo: https://jsfiddle.net/BlackLabel/vu41gdt6/
#container {
height: 15rem;
width: 15rem;
}
Consider use regular CSS units for the charts on you web app and change them only for printing needs.
API: https://api.highcharts.com/highcharts/chart.events.beforePrint
Useful article: Using cm/mm on the CSS of a web app that replicates paper interaction is a good practice?
According to JPEG2000 specs, Number of tiles in X and Y directions is calculated by following formula:
numXtiles = (Xsiz − XTOsiz)/ XTsiz
&
numYtiles = (Ysiz − YTOsiz)/ YTsiz
But it is not mentioned about the range of numXtiles or numYtiles.
Can we have numXtiles=0 while numYtiles=250 (or any other value) ?
In short, no. You will always need at least one row and one column of tiles to place your image in the canvas.
In particular, the SIZ marker of the JPEG 2000 stream syntax does not directly define the number of tiles, but rather the size of each tile. Since the tile width and height are defined to be larger than 0 (see page 453 of "JPEG 2000 Image compression fundamentals, standards and practice", by David Taubman and Michael Marcellin), you will always have at least one tile.
That said, depending on the particular implementation that you are using, there may be a parameter numXtiles that you can set to 0 without crashing your program. In that case, the parameter is most likely being ignored or interpreted differently.
In my MVC application when it comes to printing of reports i have few options
RazorPDF - advanatage of handling design from cshtml itself & can pass values from controller as model
iTextSharp - advanatage of handling design from cshtml itself & can pass values from controller as model
pdfSharp - No advantage of handling design from cshtml page. Have to do all coding from .cs file & modifications is very difficult. BUt have a great control over the layout of generated report
So Can any one suggest a method with both options
Can do the PDF design from cshtml itself.
Can specify width and height of the PDF page
Since the report is not always to print on laser printers. Need to giv support for dotmatrix print as well and in that case i have to mention width & height of page .Also there is a possibility toprint on letter heads so i have to mention widtha nd height of empty area again
Or any one can suggest a way to mention to width and height of PDF page with RazorPDF and iTextSharp approach
Your question is about many different tools, but this is the answer in case you are using iTextSharp.
When you create a PDF from scratch using iTextSharp, you always need a Document and a PdfWriter class. The Document class is to be used for the high-level functionality; the PdfWriter class for the low-level operations.
The page size is defined at the Document level. You can create a new Document object like this:
Document document = new Document();
As we didn't pass any parameters to the constructor, iTextSharp will create a PDF using the default page size (A4) and margins of half an inch.
This is the equivalent of:
Document document = new Document(PageSize.A4, 36, 36, 36, 36);
As you can see: I use 36 as value for half an inch, because 1 inch = 72 user units in PDF.
If you want to define another page size, you can do so by using one of the other values available in the PageSize class, for instance:
Document document = new Document(PageSize.LETTER);
PageSize.A4 and PageSize.LETTER are instances of the Rectangle class, so if you need a page size that isn't defined in PageSize, then you can create your own rectangle. For instance:
Rectangle envelope = new Rectangle(432, 252);
Document document = new Document(envelope, 0, 0, 0, 0);
Where do these values come from? Let's do the Math:
6 inch x 72 points = 432 points (the width)
3.5 inch x 252 points = 252 points (the height)
This is how you define pages with a custom size.
I have a LOGFONT structure. Now all i'd like to do is get the associated font size in points from the LOGFONT height.
When the mapping mode is mm_Text (which it usually is), and when the lfHeight field is positive, it already gives the height in points. When it's negative, the units are pixels. MSDN for LogFont gives you the formula to convert between them:
lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
There are 72 points per inch. GetDeviceCaps tells you the number of pixels per inch on a given device. Invert the formula to get pixels from points:
PointSize := MulDiv(-lfHeight, 72, GetDeviceCaps(hDC, LogPixelsY);
The important thing to realize here is that you need a device context. Font sizes don't exist independently of the media they appear on. The pixel height of a font on the screen will be different from the pixel height of a font on a printer. Use the Handle property of whatever canvas you're planning on drawing to.
I find this a bit confusing, as well.
Here are a few things that I háve learned. ;)
Examine the two low-order bits of lfPitchAndFamily to determine the font type.
For fixed-pitch fonts, use GetTextMetrics and the TEXTMETRIC structure.
For variable-pitch fonts (true-type, etc), use GetOutlineTextMetrics and the OUTLINETEXTMETRIC structure. Be sure you have the structure aligned properly. Also, the structure is variable-sized. Call the function once to get the size, allocate space, then call the function again to fill the structure.
From there, you can find proper ascent, descent, and other size-related information.
Keep in mind that they are recommended values and not all display routines will use them properly. For example, I am in the process of figuring out a correct method of determining the required height of a dialog box static control for a given string of text.
It does not appear that Microsoft has followed their own documentation. ;)
Not that the documentation is all that clear or complete, to begin with.
In this sample code, the author does the following
\draw ($(closedStart.south) + (-.5em,0)$)
edge[stateEdge] node[edgeLabel, xshift=-3em]{\emph{Passive open}}
($(listen.north) + (-.5em,0)$);
What irritates me most about these markup based drawing tools is that I've to measure a value and specify. In this case, the author specifies .5em
I've yet not understood how to figure that out? How much is .5em? I don't even know the size of the base object, so how can I be sure that if I give a value it will be valid?
Is there any approach to do this? How should I decide the value and also the unit? Is em always the best unit to use?
Google is your friend: http://en.wikipedia.org/wiki/Em_%28typography%29
An em is a unit of measurement in the field of typography, equal to the point size of the current font. This unit is not defined in terms of any specific typeface, and thus is the same for all fonts at a given point size. So, 1 em in a 16 point typeface is 16 points.
You can change the unit of measurement to anything supported by latex, i'm sure: in, mm, cm, pts, picas, etc etc.
Not too sure how TikZ handles it but in LaTeX you can specify measurements as fractions (larger or smaller than 1) of known lengths, so you could set a length to be, say, 0.5\textwidth. My bet is that TikZ has this sort of facility so if you are going to be a long term user you'll want to figure it out.
To expand on what Mica says:
ems are the usual way that intercharacter space is measured, and is historically was the width of a character "M" in a given font ("M" normally being the widest letter in Latin-based fonts): crucially, it is a relative measure, and subscript fonts, say, have a smaller em than normal text. Modern fonts generally have narrower "M" characters than historically, and there are many non-Latin fonts, so the em measure is now derived from the dimensions of the square (or oblong) that the font designer places the character in, and is communicated as a parameter, together with such facts as the height of the baseline that text sits on, that tells us the scale of the font.
The point size of a font is the number of points (usually 1/72 inch) to an em, so a 12 point font is one whose character "M" is 1/6th of an inch wide (i.e., 12/72 in). The subscripts of a 12 point font are usually shown in a 7 point font, for which the em is just under 1/10th inch.
If you want to do positioning on a page, use points. If you want to control spacing in text, use ems because they scale.
Postscript
Fixed the discussion of the character `M', thanks to Mica.