Following is the code snippet I used to print a line of length 1 inch with the default DPI level(72dpi ).
page.moveTo(5, 20);
page.lineTo(72, 20);
But when I take the printout, line is smaller than 1 inch. (around 2.24 cm instead of 2.54cm)
Related
I'm working on a game and have created a simple numeric "font" for displaying the number of days.
Love2D's newImageFont() function lets one use a specifically-formatted image to create a font for any number of glyphs.
I've created my font, loaded it in my love.load() function thus:
dayFont = gr.newImageFont("/fonts/dayFont.png", "1234567")
Here's the font image file:
And then in love.draw(), I am trying to use it to display one number:
love.graphics.reset()
love.graphics.setFont(dayFont)
love.graphics.printf("1", 260, 20, 30, "left")
But nothing appears.
While troubleshooting, I discovered that when I don't set the font, the number does appear in the location expected, so the problem seems to be the imageFont itself.
The problem was in the 4th parameter of love.graphics.printf(), which sets the max width of the text. Because it was set to a max width of 30 pixels, and the glyphs themselves are 36 pixels wide, it simply doesn't render any glyphs at all.
Updating the line in love.draw() to:
love.graphics.printf("1", 260, 20, 40, "left")
fixes the issue.
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.
I plot a pdf figure using gnuplot 5.0 with pdfcairo terminal, and then insert this figure into a pdf file using latex. However, I found the font size in gunplot is different with the font size in latex, although I set them to be the same.
To make the font size consistent in gnuplot and latex, I have to set the fontscale in gnuplot as 0.75, as shown in the following codes.
gnuplot codes: plot an 'A' in blue (Helvetica, size 12, fontscale 0.75).
set terminal pdfcairo font 'Helvetica,12' size 1cm,1cm fontscale 0.75
set output 'test0.pdf'
set xrange [-1:1]
set yrange [-1:1]
unset xtics
unset ytics
unset border
set label 'A' at 0,0 textcolor 'blue'
p 1/0 notitle
Latex codes: insert the previous figure in original size, and write a black 'A' (Helvetica, size 12) next to the previous 'A'.
\documentclass[12pt]{standalone}
\usepackage{tikz}
\usepackage{helvet}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\node at (0,0) {\includegraphics{test0.pdf}};
\node at (0.3, -0.025) {\textsf{A}};
\end{tikzpicture}
\end{document}
You can see the final pdf file here. Now we can see these two 'A' are exactly the same size under the gnuplot setting 'fontscale 0.75'. I don't understand why 'fontscale 0.75' should be used in gnuplot, not 'fontscale 1'?
Is this a problem of cairo? And is there any elegant way to deal with this font size issue?
Short answer: gnuplot uses 72dpi, while cairo uses 96dpi. (96/72=4/3)
Note: For the same reason, if using pngcairo, 'fontscale 0.75' should also be used to get the right font size.
Alternative solution: cairolatex. #user8153
I think this might be due to cairo rendering. In order to set the font size, Gnuplot calls function pango_font_description_set_size with the supplied size, i.e., 12 in your case. However, this is then translated into the cairo units:
the size of the font in points, scaled by PANGO_SCALE. (That is, a
size value of 10 * PANGO_SCALE is a 10 point font. The conversion
factor between points and device units depends on system configuration
and the output device. For screen display, a logical DPI of 96 is
common, in which case a 10 point font corresponds to a 10 * (96 / 72)
= 13.3 pixel font.
Moreveor, from the documentation of the function pango_cairo_font_map_set_resolution:
/**
* pango_cairo_font_map_set_resolution:
* #fontmap: a #PangoCairoFontMap
* #dpi: the resolution in "dots per inch". (Physical inches aren't actually
* involved; the terminology is conventional.)
*
* Sets the resolution for the fontmap. This is a scale factor between
* points specified in a #PangoFontDescription and Cairo units. The
* default value is 96, meaning that a 10 point font will be 13
* units high. (10 * 96. / 72. = 13.3).
*
* Since: 1.10
**/
So in summary, it seems that the supplied size is then for the purposes of the rendering multiplied by 96/72 = 4/3 which effectively yields a font of size 16 instead of 12. The scaling factor of 0.75 which you applied would then revert this.
I want to use imcrop to crop images in matlab. But, sometimes it results the images which has one size more than what I want. Basically, my question is same as this.
http://www.mathworks.se/matlabcentral/answers/46737-how-do-i-make-the-imcrop-function-accurate-to-the-pixel
But, even this is not solved. Please help!
imcrop does return the "right size", i.e. the size specified in its documentation. A rectangle r1 = [20 20 40 30] is always not sometimes 21 by 11 pixels wide.
If your expectation of what the right size should be is different, you could index the rectangle differently. If you want a rectangle with pixel (20,20) as its upper left edge and 20 pixels tall and 10 pixels wide, you can specify r1 = [20, 20, 39, 29].
imcrop works like this because it operates on image data consisting of pixels. Pixels are being indexed, not points in space. Mathematically, a point has no width and no height, but a pixel has the width and height of one pixel.
To provide an extreme example, r2 = [5, 6, 8, 9] includes the pixels from row 5 to 6 and column 8 to 9, and is thus 2 by 2 pixels wide.
I could not really resolve the problem. But, I applied a simple work around. I used imcrop to crop with the desired sizes. And then resize the cropped image to desired size again.
Ive got Dymo labelwriter 400. It works like a charm with a glabels on ubuntu. I am currently writing software to create automatic labels. for that I need to know the size of the png I want to print.
The paper I use is: Large Address, which is 89x36mm.
When I create and print such an image it is not taking the whole label. It is in fact 2/3 of the label size.
In ppd I found such thing:
*PageSize w102h252/30321 Large Address: "<</PageSize[102 252]/ImagingBBox null>>setpagedevice"
I imagine 102 252 is a size. I created such png in gimp, still is too small.
How can I determine what size should the image have to fit the label?
The size will be in points (72nds of an inch). For example, 8.5 x 11 (letter) size paper is shown as
<</PageSize[ 612 792 ] /ImagingBBox null>>setpagedevice
102 = 1.4 inches or 36mm
252 = 2.5 inches or 89mm