Merge FDF and PDF without PDFTK - php

Is there a way to merge FDF file and a PDF File to create a flat format of all the data and form into 1 pdf without using PDFTK?
Any light shed upon this would be greatly appreciated.

No.. There's no other way easy way to flatten, but it's awesome. Why would you need anything else?
PDFTK is actually mostly Java (literally hundreds of Java files). You could think about wrapping your own project around it. The functionality that you're looking for is here (java/com/lowagie/text/pdf/AcroFields.java:931):
/** Sets the fields by XFDF merging.
* #param xfdf the XFDF form
* #throws IOException on error
* #throws DocumentException on error
*/
public boolean setFields(XfdfReader xfdf) throws IOException, DocumentException {
boolean ret_val_b= false; // ssteward
xfdf.getFields();
for (Iterator i = fields.keySet().iterator(); i.hasNext();) {
String f = (String)i.next();
String v = xfdf.getFieldValue(f);
String rv = xfdf.getFieldRichValue(f); // ssteward
if (rv != null)
ret_val_b= true;
if (v != null)
setField(f, v, v, rv); // ssteward
}
return ret_val_b; // ssteward
}

Related

Fix the Model Flutter / Dart

I have a PHP backend and I use it on my localhost so everything okay but I have a problem that the image URL I get from API is a wrong path and I can't change it from server-side so I decide to fix it on my client-side
I can display an image on my emulator with this path :
http://10.0.2.2:8000/storage/app/public/171/conversions/api-icon.jpg
and the API gives me this path
http://192.168.1.114/multi-restaurants/public/storage/app/public/171/conversions/api-icon.jpg
I fix it by making a function to change the path but it takes a lot of work like I should put this function in every place I wanna display an image!!
I'm sure there is a way to change the path directly from the model when I receive the api
here is my model
class Media {
String id;
String name;
String url;
String thumb;
String icon;
String size;
Media();
Media.fromJSON(Map<String, dynamic> jsonMap)
: id = jsonMap['id'].toString(),
name = jsonMap['name'],
url = jsonMap["url"] ,
thumb = jsonMap['thumb'],
icon = jsonMap['icon'],
size = jsonMap['formated_size'];
This function that I'm using in every class to change path Url
String changepath(String uuu) {
final uri = Uri.parse(uuu);
print("This is $uri");
if (uri.path.contains("multi-restaurants")) {
print("http://10.0.2.2:8000/${uri.pathSegments[2]}/${uri.pathSegments[3]}/${uri.pathSegments[4]}/${uri.pathSegments[5]}/${uri.pathSegments[6]}");
return"http://10.0.2.2:8000/${uri.pathSegments[2]}/${uri.pathSegments[3]}/${uri.pathSegments[4]}/${uri.pathSegments[5]}/${uri.pathSegments[6]}";
}
}
}
If the API constantly sending the URL in "http://192.168.1.114/multi-r ... " in this format, then there is a solution for it, don't know is this a smart move or anything you looking for.Just create String type Function,pass the url from json url = changer(jsonMap["url"]); and use it to convert the URL to desired URL.
String changer(String _string1) {
String _string2 = _string1.replaceAll("http://192.168.1.114/multi-restaurants/public", "http://10.0.2.2:8000");
return _string2;
}
I Solve the Problem with Create a Helper Class and put inside it a static function and call it in every widget I wanna display (Url)
static String changer(String _string1) {
String _string2 = _string1.replaceAll(
"http://192.168.1.114/multi-restaurants/public",
"http://10.0.2.2:8000");
print(_string2);
return _string2;
}

Getting a message from MQTT broker stops page from working

I'm using a simple MQTT client in PHP - https://github.com/sskaje/mqtt - and want to retrieve exactly one message (which is retained - always there) from broker, and then display it on a page. Everything works good, but I cannot get it to display the whole page. It displays "Test Text 1", then debugging code, then my message, and stops there, not showing "Test Text 2" nor "Test Text 3". If anyone would help me, I would be incredibly grateful, as I have no idea at all, what does not work, and have spent a lot of time working on it. Thanks!
Test Text 1
<?php
require('spMQTT.class.php');
$mqtt = new spMQTT('tcp://127.0.0.1:1883/');
spMQTTDebug::Enable();
$mqtt->setKeepalive(5);
$connected = $mqtt->connect();
if (!$connected) {
die("Not connected\n");
}
$topics['#'] = 0;
$mqtt->subscribe($topics);
$mqtt->loop('default_subscribe_callback');
$mqtt->unsubscribe(array_keys($topics));
printf("Test Text 2");
/**
* #param spMQTT $mqtt
* #param string $topic
* #param string $message
*/
function default_subscribe_callback($mqtt, $topic, $message) {
printf("Message received: Topic=%s, Message=%s\n", $topic, $message);
break;
}
?>
Test Text 3
I'm not familiar with that mqtt library, but it looks very much like the call to loop() is blocking, so you will have to approach the problem differently.

Doctrine2 has problems with more than 1000 rows at select

I have this query which returns me all POIs in the given area:
$query = $em
->createQuery(
'SELECT f FROM MyApplication\MyBundle\Entity\POI p
WHERE (p.latitude BETWEEN :southEastLatitude AND :norhtWestLatitude) AND
(p.longitude BETWEEN :southEastLongitude AND :norhtWestLongitude)
ORDER BY p.name
');
$query->setParameter(":norhtWestLatitude", $northWestLat);
$query->setParameter(":norhtWestLongitude", $northWestLng);
$query->setParameter(":southEastLatitude", $southEastLat);
$query->setParameter(":southEastLongitude", $southEastLng);
If i try to access with a small area (with params with small differences), I successfully get the result. I think I get the result up to 1000 rows... I'm not quite sure.
If i try to access with a bigger area, I get an empty resultset...
Somehow firing the same query with the params of the bigger area, I'm getting the correct resultset (~1060 rows).
So I'm wondering about limitations of doctrine (or even Symfony??? I'm using doctrine inside my Symfony2 Project), are there any? I also tried the $query->setMaxResults(999999999); but it didn't help...
Anybody had the same problem?
Edit: Maybe the php memory usage is to high? I added these lines before and after the getresult:
echo "Memory usage before: " . (memory_get_usage() / 1024) . " KB" . PHP_EOL;
echo "Memory usage after: " . (memory_get_usage() / 1024) . " KB" . PHP_EOL;
The output was:
Memory usage after: 5964.0625 KB
Memory usage after: 10019.421875 KB
Edit:
Strange tests:
1) If I test with these parameters:
WHERE
(f.latitude BETWEEN 45.64273082966722 AND 47.29965978937995) AND
(f.longitude BETWEEN 4.93262593696295 AND 9.99999999999999)
I'm getting 923 rows (normal behaviour)
2) If I change the parameter 9.999999999999 to 10.000000000 (or some number bigger than 9.9999999), I'm getting an empty resultset in my application.
The database still returns 923 rows (for 10.000000000).
EDIT:
I could fix the problem, discussed here: https://groups.google.com/d/msg/doctrine-user/qLSon6m4nM4/y5vLztHcbDgJ
From the Doctrine2 mailing list I learned that you mapped the properties as type "string":
/** #ORM\Column(name="latitude", type="string", length=255, nullable=false) */
private $latitude;
/** #ORM\Column(name="longitude", type="string", length=255, nullable=false) */
private $longitude;
This means that your db will have VARCHAR columns for these properties. So when the db runs your query, it will perform a string-compare.
A string-compare is different from a (normal) number-compare. See these results:
$a = 1234567890;
$b = 987654321;
echo $a == $b ? '0' : ($a < $b ? '-1' : '1'); // output: 1 (means $a is bigger than $b)
echo strcmp( $a, $b ); // output: -8 (means $a is smaller than $b)
So it's probably best to map the properties as something that represents numbers in your db (DECIMAL would be a good choice):
/** #ORM\Column(name="latitude", type="decimal", nullable=false) */
private $latitude;
/** #ORM\Column(name="longitude", type="decimal", nullable=false) */
private $longitude;
PS: You mention you get valid results when you perform the query yourself. This is probably because you did:
... latitude BETWEEN 45.64273082966722 AND 47.29965978937995 ...
But Doctrine (because you mapped the properties as strings) will do:
... latitude BETWEEN '45.64273082966722' AND '47.29965978937995' ...
Note the quotes here. There is a big difference in how these two statements are treated, like my test-case shows ;)
It's probably related to memory usage. Please check your apache log for memory errors.
When selecting large amounts of data it may be helpful to use $query->iterate() instead of $query->getResult(), as pointed out in this article.
To check if your query generates the right SQL, you could log or otherwise output the result of calling $query->getSQL() (after setting the parameters). Feed the resulting SQL to the database client of your choice to see if the desired result comes back.

hibby jibby 123456789 [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am currently trying to create an application that can shorten a word with its abbreviation
that is stored in an external text file. The word can be followed by punctuation
characters which should also be retained after shortening.
I am unable to have the method return the original word if it cannot find an
abbreviation for it. By the looks of it the method isn't reaching my final return statement and
I am unsure why.
public class WordShortener {
private Scanner fileIn;
private String shortenedWord ="";
private String s="";
public WordShortener() throws Exception {
// to be completed
Scanner fileIn = new Scanner(new File("abbs.txt"));
this.fileIn = fileIn;
}
public String wordShortener( String WordToShorten ) {
// to be completed
String s = wordToShorten;
String shortened ="";
while ( shortenedWord.equals(WordToShorten) && fileIn.hasNextLine() ) {
String line = fileIn.nextLine();
String punctuationChar="";
String[] lines = line.split(",");
String originalWord = lines[0];
String shortenedWord = lines[1];
String punctuations = "'?.";
if ( punctuations.contains(s.substring(s.length() - 1)) ) {
punctuationChar = s.substring(s.length() - 1);
}
if ( wordToShorten.contains(lines[0]) ) {
String shortenedWord = s.replaceAll(wordToShorten, lines[1]);
shortenedWord = shortened + punctuationChar;
}
}
if ( shortenedWord == wordToShorten ) {
return wordToShorten;
}
fileIn.close();
return shortenedWord;
}
this is the otherfile that is used to conduct the shortenWord message on a given word(I have imported java util and java io in the file on my computer:
public class cmdShortener {
public static void main(String[] args) throws Exception {
WordShortener WS = new WordShortener();
String return = WS.shortenWord("hello");
System.out.println( "Shortened Message:" + return );
}
}
some example lines from abbreviations file seperated by commas (these will not be edited):
eight,8
nine,9
you,u
You should change the loop condition:
while ( shortenedWord.equals(inWord) | fileIn.hasNextLine() )
to this:
while ( shortenedWord.equals(inWord) && fileIn.hasNextLine() )
Indeed, the loop is continuing as long as you don't find an abbreviation OR there are remaining lines in the file. If you had no more lines, and found no abbreviation, it would then never end.
Also, you should always use the logical operators (&& and ||) instead of the bitwise operator (& and |) because the formers do not evaluate the rest of the expression if it is not necessary.
Edit: I see you are struggling to ask a good question, but you still fail to give code that would compile. So I'm going to try to help you with what I have. Actually, this code is way too complicated for what it tries to achieve. What you want is more something like this:
private static final String PUNCTUATIONS = "'?.!;";
public String shortenWord( String inWord ) {
String originalWord = inWord; // keep track of original input
// Step 1: get punctuation char and trim inWord to what is needed
String punctuationChar = "";
int lengthMinus1 = inWord.length() - 1;
if (PUNCTUATIONS.contains(inWord.substring(lengthMinus1))) {
punctuationChar = inWord.substring(lengthMinus1);
inWord = inWord.substring(0, lengthMinus1);
}
while (fileIn.hasNextLine()) {
// Step 2: get the parts from the line.
String line = fileIn.nextLine();
if (line.isEmpty()) {
continue;
}
String[] parts = line.split(",");
// Step 3: check that inWord is the left part
if (inWord.equals(parts[0])) {
// Step 4: return the result
return parts[1] + punctuationChar;
}
}
// Step 5: if nothing is found, return original.
fileIn.close();
return originalWord;
}
I hope it's self-explanatory :)
First of all Don't use Short as variable name in your code as Short is itself a class in java.lang package.That was the side note. Now your method is returning empty string in this block:
if ( inWord.contains(parts[0]) ) {
String Short = s.replaceAll(inWord, parts[1]);
shortenedWord = Short + punctuationChar;
return shortenedWord;//This is returning blank
}
It might be because s is getting value blank in your code.!!
EDIT Going by your point in comment I think that you need the following code for method shortenWord:
public String shortenWord( String inWord )
{
String punctuations = "'?.!;";
if (punctuations.contains(String.valueOf(inWord.charAt(inWord.length() - 1)))
{
while (fileIn.hasNextLine())
{
String read = fileIn.nextLine();
String parts[] = read.split(",");
if (parts[0].equals(inWord.substring(0,inWord.length() - 1))))
{
return parts[1];
}
}
}
fileIn.close();
return inWord;
}

Get iso8601.time tag from SimpleXMLElement in PHP

I have the function bellow. I want to add support for iso8601 time format but I just can't get it to work. Since I in php can't do (string)$tag->iso8601.time. Is there a way to get the iso8601.time element? The tag is a SimpleXMLElement.
private function _tagToPhpType($tag) {
/*
* <i4> or <int> four-byte signed integer -12
* <boolean> 0 (false) or 1 (true) 1
* <string> string hello world
* <double> double-precision signed floating point number -12.214
* <dateTime.iso8601> date/time 19980717T14:08:55
* <base64> base64-encoded binary eW91IGNhbid0IHJlYWQgdGhpcyE=
*
* Source: http://www.xmlrpc.com/spec
*/
if(!empty($tag->string)) {
return (string)$tag->string;
}
elseif(!empty($tag->int)) {
return (int)$tag->int;
}
elseif(!empty($tag->i4)) {
return (int)$tag->i4;
}
elseif(!empty($tag->boolean)) {
return (bool)$tag->boolean;
}
elseif(!empty($tag->double)) {
return (double)$tag->double;
}
elseif(!empty($tag->base64)) {
// #todo: Decode BASE64
return (int)$tag->base64;
} // #todo: Add iso8601 time type
else {
return (string)$tag;
}
}
As noted in the manual (SimpleXML basic usage) and the associated example (#3):
Accessing elements within an XML document that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe.
So in your case $tag->{'dateTime.iso8601'} will get an <dateTime.iso8601> element.
(Your iso8601.time doesn't match the comment in the code, though if you need to get that tag then it should be easy to work out from the answer above.)

Categories