I've got html2pdf working nicely to attach a pdf to an email
However, I need to adjust the page width to 606px
I can do this in the html but the html is 606px and the pdf itself is standard letter width in portait.
Is there any way to constrict the doc to the width I need?
Thanx
Mark
Here is the solution for this problem:
$html2pdf = new HTML2PDF('P', array($width_in_mm,$height_in_mm), 'en', true, 'UTF-8', array(0, 0, 0, 0));
Width and Height should be in MM. If your using inches convert it to MM.
Formula:
$width_in_mm = $width_in_inches * 25.4;
$height_in_mm = $height_in_inches * 25.4;
Don't round it off. Used the exact conversion even if it has a decimal point.
Hope this answer will solve your problem.
You can change the output of the PDF to more suit your purpose when constructing HTML2PDF.
http://www.prepressure.com/library/paper-sizes
Here are some compatible page sizes.
Constructor of HTML2PDF CLass
public function __construct($orientation = 'P', $format = 'A4', $langue='fr', $unicode=true, $encoding='UTF-8', $marges = array(5, 5, 5, 8))
{
Adjust the $format variables by defining your page size
$format =array('user_defined_height','user_defined_width'); //for user-defined sizes accepts only in millimeter
In your case
606px = 160.3375mm
$format =array('160.3375','160.3375');
Related
This is part of iText5 function where page height and width is first fetched and then compared against the input parameters.
Rectangle rectangle = page.getPageSize();
float pageHeight = com.itextpdf.text.Utilities.pointsToInches(rectangle.getHeight());
float pageWidth = com.itextpdf.text.Utilities.pointsToInches(rectangle.getWidth());
I read through iText7 API and could not find pointsToInches or similar function. Looks like simple thing, I am not sure did I miss it or its dropped in iText7. Anyone know the function or how to convert from points to inches.
Any help is appreciated.
I know this is old but it didn't have an answer other than #mkl's comment on the question. The default UserUnit is 72 per inch, but that can be changed in the Page Dictionary's /UserUnit entry.
It appears that they did ditch the inchesToPoints method, but a direct implementation is trivial: float points = inches * 72f;. An implementation using the page's UserUnit value is addressed by Bruno in iText 5 here. Adapting it to iText 7 is trivial since PdfDictionary has similar syntax in both.
public static float pointsToInches(float inches, PdfPage page)
{
PdfNumber userUnit = page.GetPdfObject().GetAsNumber(PdfName.UserUnit);
float userUnitValue = userUnit == null ? 72f : userUnit.FloatValue();
return inches / userUnitValue;
}
Edit: It did say inches / userUnitValue, but it should be inches * userUnitValue.
I'm trying to display a graph generated by PDL (using PLplot) inside a Gtk3 app. When I try the following code, I see two problems:
$pdlImg isn't a GdkPixbuf so new_from_pixbuf() doesn't work.
$pdlImg appears to be empty as because the error message prints out the 10x10x3 array as a string and they're all zeroes.
Code:
#!/usr/bin/perl -w
use strict;
use PDL;
use PDL::Graphics::PLplot;
use Gtk3 -init;
my $pdlImg = zeroes(byte, 10, 10, 3);
my $pl = PDL::Graphics::PLplot->new(DEV => 'mem', MEM => $pdlImg);
my $x = sequence(10);
my $y = $x**2;
$pl->xyplot($x, $y);
$pl->close;
my $win = Gtk3::Window->new;
my $img = Gtk3::Image->new_from_pixbuf($pdlImg);
$win->add($img);
$win->show_all;
Gtk3::main();
To answer your first question, you are having PLplot put the plot into a piddle that is 10 pixels wide and 10 pixels high. I'm not sure if you're just going to get one corner of the normal plot in that case, or if you're getting the whole plot sampled into those 10x10 pixels. But in either case it's no surprise that $pdlImg is entirely zeroes. Try passing in a piddle with larger size (perhaps 1000, 1000, 3), or perhaps even using MEM => $pdlImg=null when you create the PLplot plot object.
I can't help with your second question, I have no experience with Gtk3, sorry.
I am using PERL (for legacy reasons) and I would like to format fixed width columns in a CSV file. How do I format the following values:
1.0001
10.0001
100.0001
1000.0001
1000000.1
100000001
into fixed width of 8 by right padding floats with zeros or truncating, BUT if a large integer is encountered the field width must grow to accomodate:
1.000100
10.00010
100.0001
1000.000
1000000.
100000001
I am not performing any operations, so they could possibly be treated as strings or other. I've tried about every combination in the sprintf documentation.
Thanks.
[The question was changed after this was posted. This no longer answers the question.]
substr(sprintf("%.6f", $x), 0, 8)
or
substr($x.("0"x5), 0, 8)
There's probably a neater way, but this example should work:
my #array = qw(1.0001 10.0001 100.0001 1000.0001);
for my $nums (#array) {
$nums .= '0' while length $nums < 8;
print "$nums\n";
}
1.000100
10.00010
100.0001
1000.0001
I've googled around and found this question very common but I can't seem to find a proper and direct answer. I'm using FPDF and I want to generate tables using MultiCell() since I need the line break property of it. Tried Cell() but it can't read the line break.
$col1="PILOT REMARKS\n\n";
$pdf->MultiCell(189, 10, $col1, 1, 1);
$col2="Pilot's Name and Signature\n".$name;
$pdf->MultiCell(63, 10, $col2, 1);
$pdf->Ln(0);
$col3="Date Prepared\n".$date;
$pdf->MultiCell(63, 10, $col3, 1);
But I can't generate it properly 'cause MultiCell() stacks the result. How can I achieve having MultiCell() printed adjacently with each other in a most simple and easy way?
Found this similar question but it doesn't provide a clear answer. Any help will be appreciated. Thanks in advance.
Try storing the X and Y co-ordinates and then setting them after the write
$x = $pdf->GetX();
$y = $pdf->GetY();
$col1="PILOT REMARKS\n\n";
$pdf->MultiCell(189, 10, $col1, 1, 1);
$pdf->SetXY($x + 189, $y);
$col2="Pilot's Name and Signature\n".$name;
$pdf->MultiCell(63, 10, $col2, 1);
$pdf->Ln(0);
$col3="Date Prepared\n".$date;
$pdf->MultiCell(63, 10, $col3, 1);
Just to add to Danny's answer. I like keeping the Width of each column stored and then use that when executing the SetXY method.
Example:
$x = $this->x;
$y = $this->y;
$push_right = 0;
$this->MultiCell($w = 100,3,"Column\r\nNumber 1",1,'C',1);
$push_right += $w;
$this->SetXY($x + $push_right, $y);
$this->MultiCell($w = 60,3,"Column\r\nNumber 2",1,'C',1);
$push_right += $w;
$this->SetXY($x + $push_right, $y);
$this->MultiCell(0,3,"Column 3\r\nFilling in the Rest",1,'C',1);
You can use SetXY(x,y) function to set cursor in pdf .
$pdf->SetXY(x,y);
Set cursor to print data in pdf
Where x is x-axis value and y is y-axis value
None of these worked for me. I had to SetXY before each element (for some reason it's reseting to the start of the multicell after write of any element). So before each and every element, manually SetXY.
use $pdf->Ln(10);
with $pdf->cell();
Example:
$pdf->cell(100,10,"your content");
$pdf->Ln(10);
I have an Objective-C class (although I don't believe this is anything Obj-C specific) that I am using to write a video out to disk from a series of CGImages. (The code I am using at the top to get the pixel data comes right from Apple: http://developer.apple.com/mac/library/qa/qa2007/qa1509.html). I successfully create the codec and context - everything is going fine until it gets to avcodec_encode_video, when I get EXC_BAD_ACCESS. I think this should be a simple fix, but I just can't figure out where I am going wrong.
I took out some error checking for succinctness. 'c' is an AVCodecContext*, which is created successfully.
-(void)addFrame:(CGImageRef)img
{
CFDataRef bitmapData = CGDataProviderCopyData(CGImageGetDataProvider(img));
long dataLength = CFDataGetLength(bitmapData);
uint8_t* picture_buff = (uint8_t*)malloc(dataLength);
CFDataGetBytes(bitmapData, CFRangeMake(0, dataLength), picture_buff);
AVFrame *picture = avcodec_alloc_frame();
avpicture_fill((AVPicture*)picture, picture_buff, c->pix_fmt, c->width, c->height);
int outbuf_size = avpicture_get_size(c->pix_fmt, c->width, c->height);
uint8_t *outbuf = (uint8_t*)av_malloc(outbuf_size);
out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture); // ERROR occurs here
printf("encoding frame %3d (size=%5d)\n", i, out_size);
fwrite(outbuf, 1, out_size, f);
CFRelease(bitmapData);
free(picture_buff);
free(outbuf);
av_free(picture);
i++;
}
I have stepped through it dozens of times. Here are some numbers...
dataLength = 408960
picture_buff = 0x5c85000
picture->data[0] = 0x5c85000 -- which I take to mean that avpicture_fill worked...
outbuf_size = 408960
and then I get EXC_BAD_ACCESS at avcodec_encode_video. Not sure if it's relevant, but most of this code comes from api-example.c. I am using XCode, compiling for armv6/armv7 on Snow Leopard.
Thanks so much in advance for help!
I have not enough information here to point to the exact error, but I think that the problem is that the input picture contains less data than avcodec_encode_video() expects:
avpicture_fill() only sets some pointers and numeric values in the AVFrame structure. It does not copy anything, and does not check whether the buffer is large enough (and it cannot, since the buffer size is not passed to it). It does something like this (copied from ffmpeg source):
size = picture->linesize[0] * height;
picture->data[0] = ptr;
picture->data[1] = picture->data[0] + size;
picture->data[2] = picture->data[1] + size2;
picture->data[3] = picture->data[1] + size2 + size2;
Note that the width and height is passed from the variable "c" (the AVCodecContext, I assume), so it may be larger than the actual size of the input frame.
It is also possible that the width/height is good, but the pixel format of the input frame is different from what is passed to avpicture_fill(). (note that the pixel format also comes from the AVCodecContext, which may differ from the input). For example, if c->pix_fmt is RGBA and the input buffer is in YUV420 format (or, more likely for iPhone, a biplanar YCbCr), then the size of the input buffer is width*height*1.5, but avpicture_fill() expects the size of width*height*4.
So checking the input/output geometry and pixel formats should lead you to the cause of the error. If it does not help, I suggest that you should try to compile for i386 first. It is tricky to compile FFMPEG for the iPhone properly.
Does the codec you are encoding support the RGB color space? You may need to use libswscale to convert to I420 before encoding. What codec are you using? Can you post the code where you initialize your codec context?
The function RGBtoYUV420P may help you.
http://www.mail-archive.com/libav-user#mplayerhq.hu/msg03956.html