How to set a default open page in TCPDF? - tcpdf

I'm generating a PDF with TCPDF. When a user opens the file, I'd like to open the PDF on page 3 instead of page 1.
I seem to recall this being possible in other PDF libraries, but I haven't been able to find anything in the API documentation for TCPDF.
Is this possible?

It's possible, if file open in browser.
Use setDestination(); for create link:
$pdf->AddPage();
$pdf->setDestination('chapter1', 0, '');
$pdf->Cell(0, 10, 'Chapter 1', 0, 1, 'L');
$pdf->AddPage();
$pdf->setDestination('chapter2', 0, '');
$pdf->Cell(0, 10, 'Chapter 2', 0, 1, 'L');
And open file on selected page by link:
http://www.path.to/Your/file/name.pdf#chapter2
Tcpdf example;

Related

Display jsPDF in browser window

I am just starting to use jsPDF and I think it may actually work (after attempting a zillion different ways to produce PDFs in my Quasar/Electron desktop application that have not worked).
Is there a way to display the PDF in the application window?
this.doc = new jsPDF({
orientation: "landscape",
unit: "in",
format: [4, 2]
})
this.doc.text(this.dogArray[0].dogCallName, 1, 1)
this.doc.save("test.pdf")
That works and I can save the PDF, but I'd also like to be able to display the generated PDF in the Electron browser window. I can console.log out this.doc, and I can display it on the window, but it's just a bunch of string info.
Is there something like doc.view("file.pdf") that can be used? I'm looking through the jsPDF documentation but I'm not seeing what I'm looking for.
I want to be able to see the PDF like the author shows on his Demo Website

Encoding problem when adding text to existing PDF with CombinePDF

(Rails 6.0.2.2, ruby 2.7.1, combine_pdf 1.0.18)
I'm currently trying to write some text to an existing PDF with the CombinePDF gem. Unfortunately I'm running in some encoding problems.
I'm loading the existing PDF:
pdf = CombinePDF.load "#{Rails.root}/public/pdf/base.pdf"
Then I'm adding text to it:
pdf.pages[0].textbox "Straße", height: 20, width: 160, y: 527, x: 215, font_size: 12, box_color: nil, text_align: :left, text_padding: 0
When generating a new pdf out of it:
send_data pdf.to_pdf, filename: "output.pdf", type: "application/pdf"
the string gets displayed as StraˆŸe, so the ß isn't displayed correctly.
I also tried to replace it with unicode literals (\xc3\x9f) without any effect.
Anybody has an idea what else to try?
If you use HexaPDF you could do something like this:
require 'hexapdf'
require 'stringio'
doc = HexaPDF::Document.open("#{Rails.root}/public/pdf/base.pdf")
doc.pages[0].canvas.font("Helvetica", size: 12).text("Straße", at: [215, 527])
outio = StringIO.new(''.b)
doc.write(outio)
Just make sure that you use a font that contains glyphs for all characters you want to use. So better use a TrueType font instead of the builtin Helvetica (you can just provide the path to a TrueType font to the #font method).

VSCode set width for code formatting of arrays etc

If my array goes over a certain length:
const List hts = [200, 195, 190, 185, 180, 175, 170, 165, 160, 155, 150, 145];
VSCode formats it like this:
const List hts = [
200,
195,
190,
185,
180,
175,
170,
165,
160,
155,
150,
145,
140
];
I'd rather it didn't since it makes a short array take up half the page. How can I change this?
Also I get even weirder formatting like this which means if I comment out a line it only comments out half the line:
This:
Text('RESULTS', style: kMainText),
Text('Additional', textAlign: TextAlign.center, style: kSmallText),
Gets formatted as this:
Text('RESULTS', style: kMainText),
Text('Additional',
textAlign: TextAlign.center, style: kSmallText),
The second line is one line but I have to comment it out as two lines. It seems like there's some kind of 'length' setting somewhere that I could alter to avoid this. How can I edit all this behaviour?
The Dart VS Code extension uses dart_style for formatting, which ships in the Dart SDK.
There is a setting called "maximum line length" which can be configured in your VS Code settings in the Dart section which will allow lines to be longer before they wrap (though note that this applies to all lines, not just lists).
There's an issue requesting an alternative (more customisable) formatter in VS Code here:
https://github.com/Dart-Code/Dart-Code/issues/914
Please add a 👍 to the issue if it's something you'd like to see.
The dart formatter will preserve line breaks in an list if there's a comment line at the head of this list.
For example, to format a very long list in Dart:
[
// yeah
a,b,c,
d,e,f,
];
See the test case (link) from official dart style repository (https://github.com/dart-lang/dart_style)

Generate graphs in PDF file using TCPDF

There are tons of topics on this, none of which have solved my issue. What I'd like to do is simple - generate a bar graph and then embed this graph into a pdf file that I will be generating with a library called TCPDF.
I'm having no problems generating HTML content using TCPDF but when it comes to generating the graph and including it in the pdf file, I'm having all kinds of issues.
Generating the graph
I'm creating the graph using a library called svggraph. Generating the graph is very simple, the only problem is that there are headers being sent through the inclusion of the main class file. When headers are sent, TCPDF cannot generate the PDF document.
My setup now:
generatereport.php - TCPDF generates the pdf document on this page
graph.php - SVGGraph generates the bar graph on this page
I've tried:
file_get_contents('graph.php') from generatereport.php - nothing is being output in the pdf report when I use the built in writeHTML function that TCPDF offers
require_once('graph.php') - headers already sent error
echo file_get_contents('graph.php') - Headers already sent, but that was expected. The good news is that the graph was displayed properly.
Goal (What I'd like to happen)
TCPDF has a built in ImageSVG function that is used for this exact purpose. The first parameter can take a XML string of SVG data; the problem here is that I can't figure out how to return XML data from the graph.php page (I've read every documentation page I could find).
Does anyone have any experience using either of these two libraries?
Thanks!
Edit: Some code
Graph.php:
<?php
require_once 'svggraph/SVGGraph.php';
$graph = new SVGGraph(500, 400);
$graph->Values(1, 4, 8, 9, 16, 25, 27);
$graph->Render('LineGraph', true, true)
?>
generatereport.php
$html = file_get_contents('http://localhost:8080/vu/graph.php');
if(!empty($file)){
//$pdf->Write(0, $html, '', 0, 'L', true, 0, false, false, 0);
//$pdf->writeHTML($html, true, false, true, false, '');
$pdf->ImageSVG('#' . $html, $x=15, $y=30, $w='', $h='', $link='http://www.tcpdf.org', $align='', $palign='', $border=1, $fitonpage=false);
}
The # symbol tells the function that XML data is being sent to it, as opposed to an SVG file.
Use fetch - See below
<?php
require_once 'svggraph/SVGGraph.php';
$graph = new SVGGraph(500, 400);
$graph->Values(1, 4, 8, 9, 16, 25, 27);
$output = $graph->fetch('LineGraph');
?>
and then feed it to TCPDF (Since fetch without options generates the XML declaration and doctype)
This should generate $output of the format:
<svg style="overflow: hidden; position: relative;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1226" version="1.1" height="826"><image transform="matrix(1.0364,-0.3305,0.3305,1.0364,-41.846,108.0143)" preserveAspectRatio="none" x="10" y="10" width="205" height="154" xlink:href="wallpaper.jpg" opacity="1" stroke-width="1"></image><rect transform="matrix(1.0364,-0.3305,0.3305,1.0364,-41.846,108.0143)" x="165" y="114" width="50" height="50" r="0" rx="0" ry="0" fill="#C0C0C0" stroke="#000" opacity="0" stroke-width="1"></rect><image transform="matrix(1.1575,0.2385,-0.2385,1.1575,-442.1395,-145.4163)" preserveAspectRatio="none" x="500" y="10" width="205" height="154" xlink:href="wallpaper.jpg" opacity="1" stroke-width="1"></image><rect transform="matrix(1.1575,0.2385,-0.2385,1.1575,-442.1395,-145.4163)" x="655" y="114" width="50" height="50" r="0" rx="0" ry="0" fill="#C0C0C0" stroke="#000" opacity="0" stroke-width="1"></rect></svg>
Feed it like this
$pdf->ImageSVG('#' . $output, $x=15, $y=30, $w='', $h='', $link='http://www.tcpdf.org', $align='', $palign='', $border=1, $fitonpage=false);
In line with the comment above from $VSOverFlow.
Of course you can also save the output in a file and then provide the path to the file like so
$pdf->ImageSVG($file='images/file.svg', $x=15, $y=30, $w='', $h='', $link='', $align='', $palign='', $border=0, $fitonpage=false);

autoplay videos in lightbox programs

Hi im looking at intergrating fancybox with a youtube video but I want it so when you visit a website it pops up and automaticly plays without clicking a link.
for example. if you visit http://www.turkspoultry.com/ i want a video to suddenly popup and start playing about the history of turks poultry.
any ideas?
I was trying to figure out the same thing earlier, and I ended up ditching youtube. As far as I know, there is no way to autostart youtube videos, I could be wrong.
What I did is I loaded the video into EasyHTML5Video and it spat out 4 different video files and an index.html, I then put that index in a sub folder and I called the video/page in fancy box using:
$(document).ready(function () {
$.fancybox({
'width': 745,
'height': 565,
'autoScale': false,
'transitionIn': 'fade',
'transitionOut': 'fade',
'type': 'iframe',
'href': 'Mylinktothehtmlpage'
});
});
That auto opens the page and as long as you check mark AutoPlay when you are in EasyHTML5Video then all should work!

Resources