Rectangle 27 1

by default (A4) the page width is 210, page height is 297.You can probably make a box on every page by overriding the header

$pageWidth = 210;
$pageHeight = 297;

function Header()
{
  $margin = 10;
  $this->Rect( $margin, $margin , $pageWidth - $margin , $pageHeight - margin);
}

For width and height you must subtract the margin twice, else you will not have a margin right and bottom. I updated your answer.

You missed the $ sign from margin, it should be $margin. $this->Rect( $margin, $margin , $pageWidth - $margin , $pageHeight - $margin);

And as Timo002 metioned you must subtract the margin twice $this->Rect($margin, $margin , $pageWidth - $margin * 2 , $pageHeight - $margin * 2);

php - How to set border to pdf in fpdf? - Stack Overflow

php fpdf
Rectangle 27 11

By default it's going to render on 'US Letter', you can change this by using:

$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait');

You can use 'letter', 'legal', 'A4', etc..

$customPaper = array(0,0,360,360);
$dompdf->set_paper($customPaper);
@page
@page { size: a4 landscape; }
@page { size: 360pt 360pt; }

You can see the full list of supported named sizes in the CPDF Adapter source.

Thanks for your help. This one worked for me.

Glad to be of service.

php - How to set custom width and height of pdf using dompdf? - Stack ...

php dompdf
Rectangle 27 1

Here is an example using my Python package pdfrw. pdfrw may or may not already be installed on your system; if not, you can install it with the usual pip or easy_install (or even possibly apt-get install python-pdfrw), or pull it straight from github.

This example uses a PDF feature called Form XObjects. If your output processing software doesn't support those, then we could create a version that recreates the math done by pdfrw, but updates the actual page streams. (I used to do that before I started using Form XObjects, but the latter are usually much cleaner.)

Also note that pdfrw does not support encrypted PDFs, so those would have to be decrypted first. If this doesn't work on your PDF, send me an example, and I'll look at it.

Those caveats aside, this actually has a bit more functionality than you requested -- it will scale down pages that are too big, and center pages that are too small:

#!/usr/bin/env python


import sys
import os

from pdfrw import PdfReader, PdfWriter, PageMerge


# Change these constants to change output size or orientation

outbox = 0, 0, 8.5 * 72, 11 * 72

# Generic calculations from box

out_x = outbox[0]
out_y = outbox[1]
out_w = outbox[2] - out_x
out_h = outbox[3] - out_y
out_landscape = out_w > out_h

inpfn, = sys.argv[1:]
outfn = 'normalized.' + os.path.basename(inpfn)
inp = PdfReader(inpfn)
out = PdfWriter()

def fixpage():
    # Figure out the rotation requirement before instantiating 
    landscape = bool(rotate % 180) ^ (mbox[2] - mbox[0] > mbox[3] - mbox[1])
    rotation = 0 if landscape == out_landscape else 90

    # Create a canvas, add the page, and get a reference to the page rectangle
    canvas = PageMerge()
    canvas.add(page, rotate=rotation)
    rect = canvas[0]

    # Scale the page rectangle if it doesn't fit our output size
    scaling = max(rect.w / out_w, rect.h / out_h)
    if scaling > 1.0:
        rect.scale(1.0/scaling)

    # Center the page rectangle on the output
    rect.x = out_x + (out_w - rect.w) / 2
    rect.y = out_y + (out_h - rect.h) / 2
    canvas.mbox = outbox
    return canvas.render()

for page in inp.pages:
    rotate = int(page.inheritable.Rotate or 0)
    mbox = tuple(float(x) for x in page.inheritable.MediaBox)
    out.addpage(fixpage() if rotate or mbox != outbox else page)

out.write(outfn)

Wow Patrick, this sounds great! I'll try it out on Monday morning. (Small thing, should the line be out_portrait = out_h > out_w?)

Umm, yeah... Good catch! Would work for your PDF anyway. (Maybe it doesn't look like it, but I did do a bit of testing :-) Will edit. Was considering making it landscape instead for more consistency anyway.

I started to use pdfrw but I changed over to just keeping it in FPDF as per Jan below. I had an issue with both libraries that I added in above.

php - How to rotate a PDF page so that *Box is set (and it doesn't jus...

php fpdf fpdi
Rectangle 27 1

You can rotate the imported page with FPDF by simply using the Rotate() function from this script before using useTemplate(). There's no need to switch to another language.

Thanks, Jan. I started with Patrick's pdfrw but shifted to using FPDF only and ultimately was able to get the result I wanted. There was one issue that I had with both libraries that have now noted above.

php - How to rotate a PDF page so that *Box is set (and it doesn't jus...

php fpdf fpdi
Rectangle 27 1

You can do this in dompdf by specifying the view in a meta element, e.g.

<meta name="dompdf.view" content="FitV" />
<meta name="dompdf.view" content="XYZ,0,0,1" />

You can also call the set_default_view() method of the canvas class, e.g.

$dompdf->get_canvas()->set_default_view('FitV')

Using the above method can only be done after the PDF document has been instantiated. As of dompdf 0.6.1 that is done after calling $dompdf->render().

php - Set the default page layout of a PDF file with DomPDF - Stack Ov...

php dompdf
Rectangle 27 0

No. But if you're thinking of reducing size of the document, you could use FPDF SetCompression() method:

php - Is there a way to set the DPI of output pdf using FPDF library? ...

php fpdf
Rectangle 27 0

OK so i found a shell script that invokes ghostscript with all the right parameters here: https://gist.github.com/ongardie/6800587. I installed that on my server. Now my file format conversion php code looks like this:

chdir("../pdf_to_pcl");
$ident = uniqid();
$pdf_filename = $ident.".pdf";
$pdf_file = fopen($pdf_filename,'w+');
fwrite($pdf_file,$pdf_data);
fclose($pdf_file);

exec("./pdf2pcl $pdf_filename");

$pcl_filename = $ident.".pcl";
$pcl_file = fopen($pcl_filename,"r+");
while($dt = fread($pcl_file,4096)) {
    $pcl_data .= $dt;    
}

fclose($pcl_file);
unlink($pdf_filename);
unlink($pcl_filename);

The image data I am converting is in $pdf_data. The pcl formatted data is in $pcl_data. I can open a socket to a RAW print server (port 9100) for a PCL printer and write $pcl_data straight to it and it works. Hope this helps.

pdf - how do i set the image to high quality when converting to PCL us...

php pdf imagemagick imagick printer-control-language
Rectangle 27 0

clearing the fast search cache in Adobe Reader.

Even without encryption, the fast find feature from Adobe Reader is using the /ID entry (if it is set) to somehow identify all text content of the document.

Once I have cleared the fast find cache from "Preferences -> Search" I was again able to search

So in future I will use something similar to md5(#timestamp#) to make sure every document has its own unique fileIdentifer stored in /ID entry of the document trailer.

I fully agree, but I also think noone knew that this effects the fast find feature in AAR. Anyway problem is solved.

It was new to me, too, but @VadimR seems to have had experienced something like that before. ;-)

php - Adobe Reader XI search fail when pdf fileIdentifier (/ID) is set...

php search pdf adobe-reader
Rectangle 27 0

You have to create new class extend to FPDF class. please refer the following links the solution is there

link only answers are discouraged

How to set the header and footer in PDF table using the fpdf library i...

php
Rectangle 27 0

Here is Html2PDF which is easy to use and it also offers good examples how it's been used =)

Just define something like a table and then output it formatted with css to an PDF file.

looking into it.is it free? Define a static HTML table or a looping dynamic PHP table?

looping a dynamic or define a static html table is possible and it's free.

How to generate PDF reports querying specific set of data from databse...

php mysql report fpdf
Rectangle 27 0

You cannot set a file name while embedding the PDF in a frame or a browser tab

  • you change the title of the frame
  • you make another button for download where you force the user to download with your custom name

php - Opening PDF inline in a frame - how to set the file name? - Stac...

php firefox pdf
Rectangle 27 0

$im = new imagick();
$im->setResolution(200,200);
$im->readImage(__DIR__ . DIRECTORY_SEPARATOR.$PDFName.'['.$i.']');

pdf - set density parameter for imagick with php - Stack Overflow

php pdf png imagick
Rectangle 27 0

How much of an example do you actually need?

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->setSheetIndex(1);
$objWriter->save('php://output');

Will generate a report showing the second worksheet (sheets are indexed from 0)

I get that point. The only thing i don't know how to do, is to create all the pages, if i have 10 sheets i wan't to create the 10 pages in the pdf and i just getting 1 page with setSheetIndex()

Well one option would be to save each to a temp file, and then either zip those files up together and download that zip, or use a PDF "stitcher" to combine them all into a single PDF for download

i'm really new in this area, and i'm a little confused. i understand all you're saying. But the only thing i want to know is: "how i can create all the pdf pages at once?" i link you the code i'm using. thanks link

php - PHPExcel set multiple pages on PDF - Stack Overflow

php pdf phpexcel
Rectangle 27 0

You could use Zend_Pdf. It's from the Zend Framework but can be used as a standalone component. Adding metadata is as easy as:

$pdf = Zend_Pdf::load($pdfPath);
$pdf->properties['Title'] = 'New Title.';
$pdf->save($pdfPath);

I had already read that post, but I would avoid using Zend

php - set meta tags in existing pdf - Stack Overflow

php pdf
Rectangle 27 0

As far as I know, PDF documents do not have DPI settings, given that they are vector objects. I assume you actually refer to embedded raster images (JPEG, GIF...). In that case, just check the documentation for the Image() function: forth and fifth parameters ($w and $h) can express the desired DPI if you write a negative value:

php - Is there a way to set the DPI of output pdf using FPDF library? ...

php fpdf
Rectangle 27 0

You can set the dimensions in the constructor:

FPDF([string orientation [, string unit [, mixed size]]])
$pagesize = array(107, 199);
$pdf234 = new FPDF( 'P', 'mm', $pagesize );
AddPage([string orientation [, mixed size]]);
$pdf234->AddPage('P','A5');

Adds a new page to the document.

Page size. It can be either one of the following values (case insensitive):

or an array containing the width and the height (expressed in user unit).

The default value is the one passed to the constructor.

$specs = $pdf234->getTemplateSize($pdf234->_tplIdx); $pdf234->AddPage('L',$specs);

php - fpdf set pdf height and oriention to auto - Stack Overflow

php fpdf
Rectangle 27 0

$fullPathToFile = $target_path;

    class custom_PDF extends AlphaPDF {

    var $_tplIdx;
    var $file;

    function Header() {
        if (is_null($this->_tplIdx)) {
        // THIS IS WHERE YOU GET THE NUMBER OF PAGES
        $this->numPages = $this->setSourceFile($this->file);
        $this->_tplIdx = $this->importPage(1);
        }
        $this->useTemplate($this->_tplIdx, 0, 0);
    }

    function Footer() {

    }

    function setFile($param) {
        $this->file = $param;
    }

    function RotatedText($x, $y, $txt, $angle) {
        //Text rotated around its origin
        $this->Rotate($angle, $x, $y);
        $this->Text($x, $y, $txt);
        $this->Rotate(0);
    }

    }

    $pdf234 = new custom_PDF();
    $pdf2345 = new custom_PDF(); //detect size of uploaded pdf
    $pdf234->setFile($fullPathToFile);
    $pdf2345->setFile($fullPathToFile);
    $pdf2345->AddPage();
    $specs = $pdf2345->getTemplateSize($pdf2345->_tplIdx);
    if ($specs['w'] > $specs['h']) {
    $pdf234->AddPage('L', array($specs['w'], $specs['h']));
    } else {
    $pdf234->AddPage();
    }
    $pdf234->SetAutoPageBreak(TRUE, 0);
    $pdf234->SetAlpha(0.7);
    $pdf234->SetFont('courier', '', 10);
    $pdf234->SetTextColor(0, 0, 0);
    $pdf234->SetDisplayMode('fullpage');
    $utf8text1 = $current_user->user_login . "(" . str_ireplace('_', ' ', $current_user->roles[0]) . ")," . get_bloginfo('name') . "," . get_bloginfo('url');
    $utf8text2 = date("d M Y,h:i:s a") . "," . $current_user->data->user_email;
    $pdf234->SetFont('helvetica', '', 13);
    $pdf234->SetTextColor(128, 128, 128);
    if ($specs['w'] > $specs['h']) {

    $pdf234->RotatedText(($specs['w'] / 2) - 50, ($specs['h'] / 2) + 45, $utf8text1, 40);
    $pdf234->RotatedText(($specs['w'] / 2) - 40, ($specs['h'] / 2) + 45, $utf8text2, 40);
    } else {
    $pdf234->RotatedText(45, 180, $utf8text1, 40);
    $pdf234->RotatedText(55, 180, $utf8text2, 40);
    }
    if ($pdf234->numPages > 1) {
    for ($i = 2; $i <= $pdf234->numPages; $i++) {
        //$pdf->endPage();
        $pdf234->_tplIdx = $pdf234->importPage($i);
        $pdf234->AddPage();
        $pdf234->SetAutoPageBreak(TRUE, 0);
        $pdf234->SetY(280);
        $pdf234->SetAlpha(0.7);
        $pdf234->SetFont('helvetica', '', 13);
        $pdf234->SetTextColor(128, 128, 128);
        $pdf234->RotatedText(45, 180, $utf8text1, 40);
        $pdf234->RotatedText(55, 180, $utf8text2, 40);
    }
    }
    $pdf234->Output($line['name'], 'D');
    die();

php - fpdf set pdf height and oriention to auto - Stack Overflow

php fpdf
Rectangle 27 0

You can set the dimensions in the constructor:

FPDF([string orientation [, string unit [, mixed size]]])
$pagesize = array(107, 199);
$pdf234 = new FPDF( 'P', 'mm', $pagesize );
AddPage([string orientation [, mixed size]]);
$pdf234->AddPage('P','A5');

Adds a new page to the document.

Page size. It can be either one of the following values (case insensitive):

or an array containing the width and the height (expressed in user unit).

The default value is the one passed to the constructor.

$specs = $pdf234->getTemplateSize($pdf234->_tplIdx); $pdf234->AddPage('L',$specs);

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

php - fpdf set pdf height and oriention to auto - Stack Overflow

php fpdf