ABCPDF with MSHTML engine not loading .JPG files - html

I am using ABCPDF and using the MSHTML engine for a certain report. It loads .PNG files fine, and our extensionless handler images, but when it comes to .jpg it shows an X. The pure HTML loads fine, but converting the html to PDF it doesnt load.
The other images in the screenshot are either PNG or extensionless. Also the Chrome Engine loads the image.
I even did a test with the same exact image, just different in how its sent to the browser. The first one is the image handler, that returns a JPG, and the second is reading the file directly from the file system. The handler works, but the one with the extension doesnt.
Any clue on why this is happening with the MSHTML engine?
/assets/files/210057 <-- Loads
/assets/files/210057.jpg <-- DOESNT
string theDir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + #"\files\";
string theURL = "file://" + theDir + "source.html";
using (Doc doc = new Doc())
{
doc.MediaBox.String = "Letter";
// Convert HTML
doc.Pos.Y = 0;
doc.Rect.Inset(0, 0);
doc.HtmlOptions.Engine = EngineType.MSHtml;
doc.Rect.String = doc.MediaBox.String;
var w = doc.MediaBox.Width;
var h = doc.MediaBox.Height;
var l = doc.MediaBox.Left;
var b = doc.MediaBox.Bottom;
doc.Transform.Rotate(90, l, b);
doc.Transform.Translate(w, 0);
doc.Rect.Width = h;
doc.Rect.Height = w;
int theID = doc.AddImageUrl(theURL, true, 800, true);
doc.SetInfo(doc.GetInfoInt(doc.Root, "Pages"), "/Rotate", "90");
while (true)
{
if (!doc.Chainable(theID)) break;
doc.Page = doc.AddPage();
theID = doc.AddImageToChain(theID);
}
for (int i = 1; i <= doc.PageCount; i++)
{
doc.PageNumber = i;
doc.Flatten();
}
string outFile = Path.Combine(theDir, $"out{XSettings.Version}{doc.HtmlOptions.Engine}.pdf");
doc.Save(outFile);
doc.Clear();
}

Well it turned out to be this added customHeader in the Web.Config. I will now either switch to ABCChrome or try to ignore this on images with a url rewrite rule.
<add name="X-Content-Type-Options" value="nosniff" />

Related

How to convert a json object into .csv file and how to export using Ionic 2 + angular 2?

I'm using a function in my angular 2 application to convert and export a JSON data into .CSV. The below is my function and is working fine in angular 2 application
(web). The Same I tried to use in mobile app which I developed using Ionic 2, it is not working in mobile app. Is there any way to do this?
Thanks!
saveAsCSV() {
let sampleJson : any = [{name:'ganesh', age:'24'},{name:'ramesh', age:'24'},{name:'suresh', age:'24'}]
this.saveData = [];
let a = document.createElement("a");
a.setAttribute('style', 'display:none;');
document.body.appendChild(a);
let csvData = ConvertToCSV(sampleJson);
let blob = new Blob([csvData], { type: 'text/csv' });
let url= window.URL.createObjectURL(blob);
a.href = url;
a.download = 'sample.csv';
a.click();
}
ConvertToCSV(objArray) {
let array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
let str = '';
let row = "";
for (let index in objArray[0]) {
//Now convert each value to string and comma-separated
row += index + ',';
}
row = row.slice(0, -1);
//append Label row with line break
str += row + '\r\n';
for (let i = 0; i < array.length; i++) {
let line = '';
for (let index in array[i]) {
if (line != '') line += ',';
line += array[i][index];
}
str += line + '\r\n';
}
return str;
}
Use "cordova-plugin-file" to export csv in Ionic 2.
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/
If you see the following error -
code:1 message:"NOT_FOUND_ERR"
Add one of the following lines in config.xml to resolve it.
<preference name="AndroidPersistentFileLocation" value="Internal" />
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
As explained in the documentation of the plugin, you can use one of these two option to:
choose whether to store files in the internal
file storage location, or using the previous logic, with a preference
in your application's config.xml file. Without this line, the File plugin will use Internal as the
default. If a preference tag is present, and is not one of these
values, the application will not start.
If your application has previously been shipped to users, using an
older (pre- 3.0.0) version of this plugin, and has stored files in the
persistent filesystem, then you should set the preference to
Compatibility if your config.xml does not specify a location for the
persistent filesystem. Switching the location to "Internal" would mean
that existing users who upgrade their application may be unable to
access their previously-stored files, depending on their device.
If your application is new, or has never previously stored files in
the persistent filesystem, then the Internal setting is generally
recommended.

progressive load and play video from base64 pieces

I have many pieces of a video in base64.
Just that I want is to play the video progressively as I receive them.
var fileInput = document.querySelector('input#theInputFile');//multiple
fileInput.addEventListener('change', function(e) {
var files = fileInput.files;
for (var i = 0; i < files.length; i++) {
var file = fileInput.files[i]
fileLoaded(file, 0, 102400, file.size);
};
e.preventDefault();
});
videoA=[];
function fileLoaded(file, ini, end, size) {
if (end>size){end=size}
var reader = new FileReader();
var fr = new FileReader();
fr.onloadend = function(e) {
if (e.target.readyState == FileReader.DONE) {
var piece = e.target.result;
display(piece.replace('data:video/mp4;base64,', ''));
}
};
var blob = file.slice(ini, end, file.type);
fr.readAsDataURL(blob);
var init = end;
var endt = init+end;
if (end<size){
fileLoaded(file, init, end, size);
}
}
Trying to display the video by chunks:
var a=0;
function display(vid, ini, end) {
videoA.push(vid);
$('#video').attr('src','data:video/mp4;base64,'+videoA[a]);
a++;
}
I know this is not the way but I`m trying to search and any response adjust to that I'm searching.
Even I'm not sure if it is possible.
Thanks!
EDIT
I've tried to play the chunks one by one and the first one is played well but the rest of them give the error:
"Uncaught (in promise) DOMException: Failed to load because no supported source was found".
If I could make the chunks to base64 correctly it's enough for me
Ok, the solution is to solve the creation of base64 pieces from the original uploaded file in the browser that can be played by an html5 player
So I've put another question asking for that.
Chunk video mp4 file into base64 pieces with javascript on browser

Change Report Name On PDF when exporting from report viewer

I have a working report, but I'd like to change the report name. By default it uses the RDL filename. I'd like to set different name for the downloaded files.
Is there a way to generate the file name for reports downloaded from SSRS dynamically?
Please try using DisplayName Property of ReportViewer
ReportViewer.ServerReport.DisplayName = <Your Parameter Value>;
ReportViewer.LocalReport.DisplayName = <Your Parameter Value>;
If you're using a data driven subscription you can set the report name dynamically with SQL.
Otherwise there is no way to do this within SSRS. You could always use an external script to rename the PDF for you after export but it isn't completely automatic.
You can also do this using a Javascript hook. There's a tutorial here which got me started but didn't fully work for me.
What I ended up doing was adding some javascript to ReportViewer.aspx in <sql server folder>\ReportServer\Pages\, in a script tag at the end of the <body>. The checks against the URL ensure that it only affects reports it is supposed to change the name on.
This works fine with spaces and other special characters (as long as they're allowed in a file name).
function modifyExportFileName() {
/* Change the name of file exports */
var filename = false;
if (window.location.href.indexOf('Folder/Report') !== -1) { //it's the report we want
filename = getParameter('parameter'); // returns false if not set
// should also have access to report DOM here, also Date(), etc.
} // could add more here as needed in else if blocks
if (filename) { // we have a filename set.
console.log('changing filename of exported reports to ' + filename);
changeFilename(filename);
}
}
function getParameter(param) {
//case sensitive parameter extractor.
var l = window.location.href;
if (l.indexOf(param + '=' > -1)) {
var param_location = l.indexOf(param + '=') + (param + '=').length;
return l.substring(param_location, l.indexOf('&', param_location + 1));
}
return false;
}
function changeFilename(filename) {
var r = null,
url = null;
try {
r = this.$find('ReportViewerControl')._getInternalViewer();
} catch(e) {
setTimeout(function () {changeFilename(filename)}, 1000); //maybe we're not done loading.
console.log("trying again");
return false;
}
url = r.ExportUrlBase;
if (url) {
var i = url.indexOf('FileName='),
j = url.indexOf('&', i+1);
r.ExportUrlBase = url.substring(0, i) + 'FileName=' + filename + url.substring(j);
console.log('reset filename to ' + filename);
}
}
modifyExportFileName();
Edit: I noticed that this code didn't run in IE on the corporate network. The reason is the console.logs. Comment them out if your site is running in IE Compatibility mode, as IE5 didn't have a console.

asp.net/HTML file upload control not uploading mutiple files as expected

I am using asp.net file control. I am uploading multiple files. The problem is when I select two or multiple files, it's only upload one file multiple times. I mean if I select two different images, It will upload the first image two times. And if I select three images, then it will upload first image three times.
My file upload control is following,
<asp:FileUpload runat="server" ID="file" multiple />
And I server side code is following
protected void click(object sender, EventArgs e) {
foreach (string s in Request.Files)
{
HttpPostedFile file = Request.Files[s];
int fileSizeInBytes = file.ContentLength;
string fileName = Request.Headers["X-File-Name"];
string fileExtension = "";
if (!string.IsNullOrEmpty(fileName))
fileExtension = Path.GetExtension(fileName);
// IMPORTANT! Make sure to validate uploaded file contents, size, etc. to prevent scripts being uploaded into your web app directory
string savedFileName = Path.Combine(#"D:\Temp\", Guid.NewGuid().ToString() + ".jpg");
file.SaveAs(savedFileName);
}
}
I have no idea why this is behaving this way. When I debug the server side code, it's giving me different names of files from "Request.Headers["X-File-Name"]" but somehow it's uploading same content (the first image from the multiple images that I try to upload)
You can get posted files from file upload control if you are using ASP.NET > 4.0 like this
foreach (HttpPostedFile f in file.PostedFiles)
{
//HttpPostedFile file = Request.Files[s];
int fileSizeInBytes = f.ContentLength;
string fileName = f.FileName;
string fileExtension = "";
if (!string.IsNullOrEmpty(fileName))
fileExtension = Path.GetExtension(fileName);
// IMPORTANT! Make sure to validate uploaded file contents, size, etc. to prevent scripts being uploaded into your web app directory
string savedFileName = Path.Combine(#"D:\Temp\", Guid.NewGuid().ToString() + ".jpg");
f.SaveAs(savedFileName);
}
With ASP.NET 4.0 or less aslo available in 4.0 and above
HttpFileCollection fc = Request.Files;
for (int i = 0; i < fc.Count; i++)
{
HttpPostedFile f = fc[i];
int fileSizeInBytes = f.ContentLength;
string fileName = f.FileName;
string fileExtension = "";
if (!string.IsNullOrEmpty(fileName))
fileExtension = Path.GetExtension(fileName);
// IMPORTANT! Make sure to validate uploaded file contents, size, etc. to prevent scripts being uploaded into your web app directory
string savedFileName = Path.Combine(#"D:\Temp\", Guid.NewGuid().ToString() + ".jpg");
f.SaveAs(savedFileName);
}

Accessing audio via function

In Unityscript I'm able to directly access audio data. In the scene, I have a gameobject with a sound file and a script attached to it.
var mySound : AudioClip;
mySound = audio.clip;
var mySoundChannels = mySound.channels;
However, I'm having problems trying to access audio data via a function:
#pragma strict
var mySound : AudioClip;
function Start()
{
mySound = audio.clip;
GetAudio(mySound);
}
function GetAudio(au)
{
print ("Audio: " + (mySound === au)); // true
//var mySoundChannels = mySound.channels; // works
var mySoundChannels = au.channels; // fails
var stereoOrNot = (mySound.channels == 2 ? "stereo" : " mono"); //works
print(stereoOrNot);
}
I thought I could access au.channels, but I'm not sure where I'm going wrong I (apart from wanting to access audio indirectly)
Since you are using a dynamic variable there, I'm not sure if the var mySoundChannels will be typed to an AudioClip or an int. If it is an AudioClip then it will fail because channels are read only. Try it with int mySoundChannels = au.channels;