TCPDF show ? instead of Č - tcpdf

I have problem with TCPDF to show on PDF page my UTF-8 data. Here is part of my code :
TCPDF work fine, but when create Pdf I get ?a?anska insted Čačanska.
I try with "SET NAMES 'utf8'" ,but no result.. If I remove utf8_encode, get blank page.
I try to use this answer, but no help:
Why cant I use č,ć,đ charters in TCPDF table?
and my old question:
TCPDF don't show č,ć,ž,š,đ from mysql only blank page
Font:
$pdf->SetFont('freeserif', '', 14, '', true);
Create Pdf:
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
Part od code :
$id =$_POST['ajde']; // get data from jqgrid
$result = mysqli_query($con,"SELECT * FROM kuca where id=$id ");
while($row = mysqli_fetch_array($result))
{
$u= $row['adresa'];
$html = '
<table width="540" height="339" border="1" align="center" cellpadding="2" class="table table-hover" >
<tr>
<td><div align="left">Adresa:</div></td>
<td style="font-family:freesans" ">' . $u. '</td>
</tr>
</table>
$pdf->writeHTML(utf8_encode($html), true, 0, true, 0);
Tnx,
Pavle

I'm not sure if you still need to know this, but I already explained it in one of my answers, but you need to encode you content to utf-8 again (and utf-8 already encoded, remains utf-8 in PHP) and convert it to HTML_ENTITIES. I may explained it a bit weird, so people can correct me on that : )
In short:
$your_new_content = mb_convert_encoding(utf8_encode($your_content), 'HTML-ENTITIES', 'UTF-8');
Oh, a reminder that this fix will mess up your regular echoes, but it will turn out well in TCPDF. This fix can be used on various things, so I hope this helps.

Related

Regarding-Grails GSP

I created a word document that is in local drive and it should be opened in browser using grails gsp page.
What are the options for creating whether to create a link or by using script.
Thanks in advance for helping.
to be Opened or Downloaded there are lots of options
is to use File Viewer Grails plugin Grails File Plugin
Just to provide the link in your .gsp file as below and make a download or view option/open option when u press the link of that document using the following code.
in a table list show the link fetched from data base or some other source
<table>
<thread>
<tr>
<g:sortableColumn property="filename" title="Filename" />
<g:sortableColumn property="upload" title="Upload Date" />
</tr>
</thread>
<tbody>
<g:each in="${documentInstanceList}" status="i"
var="documentInstance">
<tr class="${(i%2)==0?'even':'odd'}">
<td><g:link action="download" id="${documentInstance.id}">
${documentInstance.filename}
</g:link></td>
<td><g:formatDate date="${documentInstance.uploadDate}" /></td>
</g:each>
</tbody>
</table>
inside you DocumentController under download action put this code to make the file available to be downloaded or viewed based on the browser option
def download(long id) {
Document documentInstance = Document.get(id)
if (documentInstance == null) {
flash.message = "Document not found."
redirect(action:'list')
}
else {
response.setContentType("APPLICATION/OCTET-STREAM")
response.setHeader("Content-Disposition","Attachment;Filename=\"${documentInstance.filename}\"")
def file = new File(documentInstance.fullpath)
def fileInputStream = new FileInputStream(file)
def outputStream = response.getOutputStream()
byte[] buffer = new byte[4096];
int len ;
while((len = fileInputStream.read(buffer))>0) {
outputStream.write(buffer,0,len);
}
outputStream.flush()
outputStream.close()
fileInputStream.close()
}
}
Just let me now anything .. . .
I'm not aware of any plugins that allow you to directly render a word document in a browser / grails application. This used to be possible with old versions of Word & IE 7/8, but this is no longer the case.
A word document is basically an XML document with various markup telling the text how to render etc, and you could possibly look into loading this format. Someone has probably done this before so i'd suggest google-ing "word document parsing" or similar if you wish to investigate this option. On the other hand maybe it might be possible to save the word document as txt if you are only interested in the document text?
Hope that helps.

Are dynamically created table rows not targetable by jQuery?

I'm trying to make table rows draggable and then connectToSortable -able.
For some reason, when I put the ID of the tbody ("#sem1") in the selector, it works but obviously drags the whole table-body with all of its rows.
However, when I put "#sem1 tr" in the selector the webpage seems to just ignore that code, meaning the table still shows up correctly, but nothing becomes draggable.
HTML:
<table class = "sem">
<thead>
<th class = "header1">header</th>
<th class = "header2">header</th>
<tr>
<td class = "static1">static1</td>
<td class = "static2">static2</td>
</tr>
</thead>
<tbody id = "sem1">
</tbody>
</table>
Through some JavaScript table rows get added to sem1 like so.
JavaScript:
First pos0[0] (an array) gets populated:
for(var i in setPos[0]){
setPos[0][i]=("<tr><td class = " + String(setClass[i])+ ">" + setPos[0][i].slice(2) + "</td><td class = 'someClass'>"+setThis[i]+"</td></tr>");
}
Then pos0[0][a] gets added to sem1 like this:
for(var a in pos0[0]){
document.getElementById("sem1").innerHTML += pos0[0][a];
}
and when I try to make the rows draggable, it just doesn't work.
jQuery:
$("#sem1 tr").draggable()
Putting just tr in the selector doesn't work either (I don't mind if all the table rows in the whole document are draggable)
**I know that the code says setPos[0] - it's part of a function that does the same thing to pos1, pos2...
Thanks in advance for any help!
My guess is that you are calling the $("#sem1 tr").draggable() line before the code that has inserted the new <tr>'s has been run, so it doesn't see the rows you've added.
Also, have you tried manually inserting some markup to check that the draggable code actually works on a per row basis?
It would help if you could post an example in jsfiddle or something so we can work on this with you.
Finally it could be overkill for this situation but have you looked into using a JavaScript templating engine if you are going to be building chunks of html in your app?

tcpdf : prevent page break within a block

I'm using TCPDF to print some tables of data: one big table (although usually not longer than a page) followed by a second, smaller one.
In some cases, the two tables together are longer than one page, so TCPDF inserts a page break in the middle of the second table. My clients want to avoid that behavior: they would rather have the second table completely on a new page, ie insert the page break before the table, if both table cannot fit on a single page.
Of course if both tables fit on one page, no page break should be used.
So does anybody know if there is a way to instruct TCPDF not to insert a page break within a given table?
Start a transaction, insert the table, check if you are in a new page, if yes, roll back and add a page before insering your table.
VERY IMPORTANT: don't forget the TRUE calling rollback:
$this->startTransaction();
$start_page = $this->getPage();
$this->writeHTMLCell( 0, 0, '', '', $html, 0, 1, false, true, 'C' );
$end_page = $this->getPage();
if ($end_page != $start_page) {
$this->rollbackTransaction(true); // don't forget the true
$this->AddPage();
$this->writeHTMLCell( 0, 0, '', '', $html, 0, 1, false, true, 'C' );
}else{
$this->commitTransaction();
}
Hope it helps
michel
according to docs, there is a option to add nobr="true" to table tag as attribute.
$tbl = <<<EOD
<table border="1" cellpadding="2" cellspacing="2" nobr="true">
<tr>
<th colspan="3" align="center">NON-BREAKING TABLE</th>
</tr>
<tr>
<td>1-1</td>
<td>1-2</td>
<td>1-3</td>
</tr>
</table>
EOD;
$pdf->writeHTML($tbl, true, false, false, false, '');
http://www.tcpdf.org/examples/example_048.phps
Calculate a height of the second table in advance. Use a checkPageBreak method to add a page break if needed.

jquery attr title removing is not working in Mozilla FF

Cold you plz look the following code,
<table title="Demo1">
<tr>
<td> Test1 </td>
<td> Test2 </td>
</tr>
</table>
Here the both Test1 and Test2 links displays default title "Demo1"
But i do not want the title for both links, for this functionality i am doing as follows
$("#anch1").removeAttr("title");
$("#anch2").removeAttr("title");
or
$("#anch1").attr("title", "");
$("#anch2").attr("title", "");
this code works in IE, but M FF is not working, the title is still displaying, and the table title should be there, we should not remove the table tile,
Could you plz answer..
You need to temporary clear the parent table title when hovering over the links, then restore the title when mouse leave the links. Most simple way is adding id to the table itself then:
var $table = $("#table1");
var originalTitle = $table.attr("title");
$("#anch1, #anch2").hover(function() {
$table.attr("title", "");
}, function() {
$table.attr("title", originalTitle);
});
This way you're not dependent on browser behavior.
If you want this applied to all the links in the table, change the selector from "#anch1, #anch2" to $table.find("a").
Live test case.
Try:
$('table').removeAttr('title');
The title is applied to the table, not the anchors. Also, your table markup is malformed (you need to wrap TDs in TR), and that might confuse the selector engines.

Rendering a string as a color hex value in Ruby on Rails

I have a hex value that I am getting from an XML file and I am trying to use that hex value as the background color for a data table. However, in IE8 it keeps rendering as a string.
When I have used
<%= h(#dhex1[k]) %>
it renders as
<%hex>A8960A<%/hex> with hex tags (note % signs are so browser does not think they are tags)
in the browser. I have tried
<td style="background-color:#<%=h(#dhex1[k].to_s)%>">
<td style="background-color:#<%=h(#dhex1[k])%>">
<td style="background-color:#<%=#dhex1[k]%>">
<td style="background-color:<%=#dhex1[k]%>">
yet it will not render as a background color. The hex tags how the value is stored the XML doc itself and I am using
#hex1 = XPath.match( xmldoc, "///hex" )
to get the hex value, but it renders as A8960A. What do I need to change?
From your description, it seems that #dhex1[k] conatins an unwanted xml element. Either get rid of that at the place where you extract the value, as in
#hex1 = XPath.match(xmldoc, '//hex/text()')
or later, as in
<td style="background-color:#<%= #dhex1[k].gsub(/<.+?>/, '') %>">

Resources