Select.PDF <img> Not Appearing in Rendered PDF - pdf-generation

I am using select.pdf to output a PDF file. My process starts by grabbing the text of an HTML file in my visual studio project using this:
string strHTML = string.Join(" ", File.ReadAllLines("Template.html", Encoding.UTF8));
Once I have the strHTML set to the text from the HTML template, I run a few replaces to replace variables I have in the template, like this:
strHTML = strHTML.Replace("PARAM_A", "My Replaced Value");
Once all of that is done, I render the PDF using:
PdfDocument doc = converter.ConvertHtmlString(strHTML);
My problem is this - In the Template.html file I have an HTML img that has a src property set to an image in a Publicly Available Azure BLOB container, like this:
<img style="float:left; height:125px; width:125px" src="FULL PATH TO PNG IN AZURE BLOB CONTAINER" />
While developing and debugging on my local machine, everything works great and the PDF includes the image referenced. The project is an Azure Web Job and when I deploy it, the PDF gets generated as expected but the PDF does not include the image.
I read that the Select.pdf ConvertHtmlString method takes two parameters, my strHTML text and also a baseUrl string property, but I'm not sure what to put here in my situation. I am dynamically generating all of the HTML and then trying to output the PDF.
Any advice would be appreciated.
Daniel

As your description, I can see that you convert complete HTML document to a string, and then convert it to pdf.
Use the command include two parameters:
PdfDocument doc = converter.ConvertHtmlString(htmlString, baseUrl);
Here is a sample works perfectly.
And this is the decompile code may help you to refer:
public PdfDocument ConvertHtmlString(string htmlString, string baseUrl)
{
int num1;
PdfDocument pdfDocument;
short num2;
switch (0)
{
case 0:
label_2:
pdfDocument = (PdfDocument) null;
num2 = (short) 4;
num1 = (int) (IntPtr) num2;
goto default;
default:
while (true)
{
switch (num1)
{
case 0:
if (!GlobalProperties.RenderWithRestrictedEngine)
{
pdfDocument = PdfDocument.ᜀ(this.ᜁ((string) null, htmlString, baseUrl, baseUrl, false));
num2 = (short) 3;
num1 = (int) (IntPtr) num2;
continue;
}
num2 = (short) 5;
num1 = (int) (IntPtr) num2;
continue;
case 1:
case 3:
goto label_13;
case 2:
num2 = (short) 0;
num1 = (int) (IntPtr) num2;
continue;
case 4:
label_3:
num2 = (short) 1;
if (num2 == (short) 0)
;
if (this.Options.RenderingEngine != RenderingEngine.WebKitRestricted)
{
num2 = (short) 2;
num1 = (int) (IntPtr) num2;
continue;
}
break;
case 5:
num2 = (short) 21784;
int num3 = (int) num2;
num2 = (short) 21784;
int num4 = (int) num2;
switch (num3 == num4 ? 1 : 0)
{
case 0:
case 2:
goto label_3;
default:
num2 = (short) 0;
if (num2 == (short) 0)
break;
break;
}
break;
default:
goto label_2;
}
pdfDocument = PdfDocument.ᜀ(this.ᜀ((string) null, htmlString, baseUrl, baseUrl, false));
num2 = (short) 0;
num2 = (short) 1;
num1 = (int) (IntPtr) num2;
}
label_13:
return pdfDocument;
}
}

Related

Menu type display in LCD using 4x4 Keypad in Arduino

I am trying to display two menu type in 16x2 LCD display using keypad in Arduino.
Here is the code;
`#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
byte rowPins[4]={9,8,7,6};
byte colPins [4]={5,4,3,2};
char keys[4][4]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
LiquidCrystal_I2C lcd(0x27,16,2);
boolean present = false;
boolean next = false;
boolean final = false;
String num1, num2; //
float ans;//
char op;//
//String Line1 = " ";
//String Line2 = " ";
//char cursors = 0;
//
////phaseshift
//char phase_value[2];
//int phase_cursor;
//int phase_index;
//char phasesign;
//
////declare function
//void Phaseshift_Fn();
//void CV_Fn();
//void CC_Fn();
//void Remote_Fn();
void setup() {
lcd.init();
lcd.backlight();
lcd.begin (16,2);
lcd.clear();
lcd.setCursor(0, 0); lcd.print(Line1);
lcd.setCursor(0, 1); lcd.print(Line2);
delay(100);
lcd.setCursor(5,0);
lcd.print("HELLO");
lcd.setCursor(0,1);
lcd.print("PRESS FWD Button");
delay(2000);
lcd.clear();
delay(1000);
}
void loop() {
char key = keypad.getKey();
if(key == 'B'){
lcd.setCursor(0,0);
lcd.print("IF NO AIR BUBBLE");
lcd.setCursor(0,1);
lcd.print("PRESS STOP");
}
if(key == 'A'){
lcd.clear();
lcd.setCursor(0,0);
lcd.print("PRESS MODE");
lcd.setCursor(0,1);
switch(mode)
{
case Startup:
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
Line1 = "Enter Amount";
lcd.print(Line1);
lcd.setCursor(0,1);
Line2 = "Enter Time";
lcd.print(Line2);
delay(1000);
mode = Mainmenu;
break;
}
if (key != NO_KEY && (key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9'||key=='0'))
{
if (present != true)
{
num1 = num1 + key; // storing the value of key pressed in num1
float numLength = num1.length();
lcd.setCursor(0, 1); /* decaling the place where the first entry will be displayed*/
lcd.print(num1); // printing the first number entered
}
else
{
num2 = num2 + key;//storing the value of second key pressed in num2
float numLength = num2.length();
lcd.setCursor(4, 1);/*decaling the place where the second entry will be displayed*/
lcd.print(num2); //printing the second number entered
final = true;
}
}
}`
As a beginner of the Arduino programming I tried so many methods including switch methods also.
But it didn't display. Please anyone can help me to solve this code?
I am trying to display this;enter image description here
Here I want to display
when I click the S button there two menus are displaying. They are Stop and Start. I want to display that two in LCD and if start button click then machine is forward after that when I click the stop button it should be stopped.

I want to break this into multiple functions what data type can i use?

There's more code than this, but I'm retrieving data from multiple edit controls and an external file to count currency. I want to break this down into multiple smaller functions, but I don't know what data type it would use to run successfully.
HANDLE hBuck = CreateFile(FileName, GENERIC_ALL, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD bytes_read;
DWORD leni = GetFileSize(hBuck, NULL);
LPSTR buffer = (LPSTR)GlobalAlloc(GPTR, leni +1);
ReadFile(hBuck, buffer, leni, &bytes_read, NULL);
double xt = atof(buffer);
CloseHandle(hBuck);
DWORD len = GetWindowTextLength(hPen) +1;
buffer = (LPSTR)GlobalAlloc(GPTR, len +1);
GetWindowText(hPen, buffer, len);
double num1 = atof(buffer);
len = GetWindowTextLength(hNick) +1;
buffer = (LPSTR)GlobalAlloc(GPTR, len +1);
GetWindowText(hNick, buffer, len);
double num2 = atof(buffer);
len = GetWindowTextLength(hDime) +1;
buffer = (LPSTR)GlobalAlloc(GPTR, len +1);
GetWindowText(hDime, buffer, len);
double num3 = atof(buffer);
len = GetWindowTextLength(hQuart) +1;
buffer = (LPSTR)GlobalAlloc(GPTR, len +1);
GetWindowText(hQuart, buffer, len);
double num4 = atof(buffer);
Try something like this:
bool ReadDoubleFromFile(LPCSTR FileName, double *value)
{
if (!value) return false;
*value = 0.0;
HANDLE hBuck = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hBuck == INVALID_HANDLE_VALUE) return false;
DWORD len = GetFileSize(hBuck, NULL);
if (len == INVALID_FILE_SIZE) {
CloseHandle(hBuck);
return false;
}
LPSTR buffer = (LPSTR) LocalAlloc(LPTR, len + 1);
if (!buffer) {
CloseHandle(hBuck);
return false;
}
DWORD bytes_read;
if (!ReadFile(hBuck, buffer, len, &bytes_read, NULL)) {
LocalFree((HLOCAL)buffer);
CloseHandle(hBuck);
return false;
}
CloseHandle(hBuck);
*value = atof(buffer);
LocalFree((HLOCAL)buffer);
return true;
}
bool ReadDoubleFromEdit(HWND hEdit, double *value)
{
if (!value) return false;
*value = 0.0;
DWORD len = GetWindowTextLengthA(hEdit);
if (len > 0) {
++len;
LPSTR buffer = (LPSTR) LocalAlloc(LPTR, len);
if (!buffer) return false;
if (!GetWindowTextA(hEdit, buffer, len)) {
LocalFree((HLOCAL)buffer);
return false;
}
*value = atof(buffer);
LocalFree((HLOCAL)buffer);
}
return true;
}
...
double xt, num1, num2, num3, num4;
if (ReadDoubleFromFile(FileName, &xt) &&
ReadDoubleFromEdit(hPen, &num1) &&
ReadDoubleFromEdit(hNick, &num2) &&
ReadDoubleFromEdit(hDime, &num3) &&
ReadDoubleFromEdit(hQuart, &num4))
{
// use values as needed...
}
else
{
// error
}
On the other hand, if you are using C++ instead of C (you did not say which language you are using), this becomes a bit simpler:
double ReadDoubleFromFile(const std::string &FileName)
{
std::ifstream inFile;
inFile.exceptions(std::ifstream::failbit);
inFile.open(FileName.c_str());
double value;
inFile >> value;
return value;
}
double ReadDoubleFromEdit(HWND hEdit)
{
double value = 0.0;
DWORD len = GetWindowTextLength(hEdit);
if (len > 0) {
std::basic_string<TCHAR> buffer(len, TEXT('\0'));
if (!GetWindowText(hEdit, buffer.data(), len + 1))
throw std::runtime_error("GetWindowText failed");
value = std::stod(buffer);
}
return value;
}
...
try
{
double xt = ReadDoubleFromFile(FileName);
double num1 = ReadDoubleFromEdit(hPen);
double num2 = ReadDoubleFromEdit(hNick);
double num3 = ReadDoubleFromEdit(hDime);
double num4 = ReadDoubleFromEdit(hQuart);
// use values as needed...
}
catch (const std::exception &ex)
{
// handle error as needed...
}

"Use of unassigned local variable 'result'"

static void Main(string[] args)
{
Console.WriteLine(GetMax(2, 10, 40));
}
static int GetMax(int num1, int num2, int num3)
{
int result;
if (num1 >= num2 && num1 >= num3)
{
result = num1;
}
else if (num2 >= num1 && num2 >= num3)
{
result = num2;
}
else if (num3 >= num1 && num3 >= num2)
{
result = num3;
};
return result;
}
"result" is underlined. im trying to return the maximum number to the main method but it doesn't work.
I think your issue is just that you need to initialize 'result' with something first. At the beginning of your GetMax function, instead of:
int result;
try:
int result = 0;
By initializing the value as something, you should be good.
Another option would be to pass an array to GetMax instead of individual numbers. Then use a for loop to go through the array and assign the biggest one to 'result'. This method would allow you to compare arrays of any length of numbers, not just 3:
static void Main(string[] args)
{
int[] numbers = {2, 10, 40};
Console.WriteLine(GetMax(numbers));
}
static int GetMax(int[] nums)
{
int result = 0;
for (int i = 0; i < nums.Length; i ++)
if (nums[i] > result){
result = nums[i];
}
return result;
}
Hope one of these options works for you!

String Encoding Umlaute

I want to send a string with a webclient and i have problems with german umlaute.
Checking with Fiddler, I see that the following conversion for the post parameter is made:
ä to %E4 (which is iso-8859-1 according to online encoder tool)
Do you know how i can achive this for WP7?
I tried already:
string urlstring = HttpUtility.UrlEncode("ä");
RESULT: %c3%a4
string urlstring1 = HttpUtility.HtmlEncode("ä");
RESULT: ä
Encoding isoenc = Encoding.GetEncoding("ISO-8859-1");
byte[] utf8characters = Encoding.UTF8.GetBytes("ä");
byte[] isoArray = Encoding.Convert(Encoding.UTF8, Encoding.GetEncoding("ISO-8859-1"),utf8characters);
string finalString = isoenc.GetString(isoArray,0, isoArray.Length);
RESULT: ä
I also checked this silverlight tool where you can create custom encoding.. without success.
I'm getting really crazy about this issue, if anyone has an idea please let me know.
Thanks,
Ralf
The solution provided by nwellnhof is good, but the HttpUtility.UrlEncode overload that takes an encoding as parameter isn't available on Windows Phone. Fortunately, by decompiling the framework assemblies, it's easy to modify it to use the encoding you want:
public class HttpUtilityEx
{
public static string UrlEncode(string url, Encoding encoding)
{
if (url == null)
{
return null;
}
byte[] bytes = encoding.GetBytes(url);
int num = 0;
int num1 = 0;
int length = (int)bytes.Length;
for (int i = 0; i < length; i++)
{
char chr = (char)bytes[i];
if (chr == ' ')
{
num++;
}
else if (!IsSafe(chr))
{
num1++;
}
}
if ((num != 0 ? true : num1 != 0))
{
byte[] hex = new byte[length + num1 * 2];
int num2 = 0;
for (int j = 0; j < length; j++)
{
byte num3 = bytes[j];
char chr1 = (char)num3;
if (IsSafe(chr1))
{
int num4 = num2;
num2 = num4 + 1;
hex[num4] = num3;
}
else if (chr1 != ' ')
{
int num5 = num2;
num2 = num5 + 1;
hex[num5] = 37;
int num6 = num2;
num2 = num6 + 1;
hex[num6] = (byte)IntToHex(num3 >> 4 & 15);
int num7 = num2;
num2 = num7 + 1;
hex[num7] = (byte)IntToHex(num3 & 15);
}
else
{
int num8 = num2;
num2 = num8 + 1;
hex[num8] = 43;
}
}
bytes = hex;
}
return encoding.GetString(bytes, 0, (int)bytes.Length);
}
private static bool IsSafe(char ch)
{
if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9')
{
return true;
}
char chr = ch;
if (chr != '!')
{
switch (chr)
{
case '\'':
case '(':
case ')':
case '*':
case '-':
case '.':
{
break;
}
case '+':
case ',':
{
return false;
}
default:
{
if (chr != '\u005F')
{
return false;
}
else
{
break;
}
}
}
}
return true;
}
internal static char IntToHex(int n)
{
if (n <= 9)
{
return (char)(n + 48);
}
return (char)(n - 10 + 97);
}
}
From there, you just need to call it like you would for HttpUtility:
var result = HttpUtilityEx.UrlEncode("ä", Encoding.GetEncoding("ISO-8859-1"));
HttpUtility.UrlEncode has an optional second parameter which specifies the encoding. The following should work:
Encoding isoenc = Encoding.GetEncoding("ISO-8859-1");
String urlstring = HttpUtility.UrlEncode("ä", isoenc);

Generate 5 different non repeatable random numbers in unityscript

please tell me how to generate 5 different non repeatable random number between 1,20 in javascript for unity3d
this the code i have written.. this works 1st 3 times but crashes the last time. please tell me how i can improvise this i have taken numbers in an array to print them on screen n n checked for their repeatability. this works ly 3 times.. for 4th time unity crashes. i know the reason dunno how solve it.. i think it is because it is not able to detect the remaining numbers of the array. Please tell me where i have gone wrong.. i'm new to unity.
var temp : int = 0;
var array = new Array();
var count : int = 0;
var n : int = 0;
var b : int = 0;
var num = new Array();
var num1 : int = 0;
var num2 : int = 0;
var num3 : int = 0;
var num4 : int = 0;
var num5 : int = 0;
var number1 : GUIText;
var number2 : GUIText;
var number3 : GUIText;
var number4 : GUIText;
var number5 : GUIText;
function Start () {
if((temp == 0) || (temp ==20))
{
//for(a=1;a<=20;a++)
//{
temp=0;
array[1]=1;
array[2]=2;
array[3]=3;
array[4]=4;
array[5]=5;
array[6]=6;
array[7]=7;
array[8]=8;
array[9]=9;
array[10]=10;
array[11]=11;
array[12]=12;
array[13]=13;
array[14]=14;
array[15]=15;
array[16]=16;
array[17]=17;
array[18]=18;
array[19]=19;
array[20]=20;
//array[1]=a;
//}
}
}
function OnGUI ()
{
if (GUI.Button (Rect (100,200,100,100), "Click Me"))
{
count=0;
//print(count);
genrandom() ;
for(a=1;a<=6;a++)
{
//print("A is"+a);
genrandom() ;
temp++;
count=count+1;
//print("Count is :"+count);
if(count>=6){count = 0;}
}
}
}
function genrandom()
{
//temp++;
//print(temp);
if(count<=5)
{
n = Random.Range(1,20);
//print("N is"+n);
if(array[n]!=0)
{
if(count==1)
{
print("Count is 1");
num1 = array[n];
array[n]=0;
number1.text = ""+num1;
//count++;
}
if(count==2)
{
print("Count is 2");
num2 = array[n];
array[n]=0;
number2.text = ""+num2;
//count++;
}
if(count==3)
{
print("Count is 3");
num3 = array[n];
array[n]=0;
number3.text = ""+num3;
//count++;
}
if(count==4)
{
print("Count is 4");
num4 = array[n];
array[n]=0;
number4.text = ""+num4;
//count++;
}
if(count==5)
{
print("Inside count= 5");
num5 = array[n];
array[n]=0;
number5.text = ""+num5;
//count++;
}
}
else
{
genrandom();
}
}
}
One way to go about this would be to create the array of possible values, shuffle it, and look at the first five elements:
http://en.wikipedia.org/wiki/Fisher-Yates
http://jsfromhell.com/array/shuffle
Example: http://jsfiddle.net/Q9ZAZ/

Resources