Asked  10 Months ago    Answers:  5   Viewed   207 times

Based on the question Open PDF in new browser full window, it looks like I can use JavaScript to open a new window with a PDF file with the following code:'MyPDF.pdf', '_blank');

I'd like to do so on a return trip from the server by adding a byte array instead of the file name to use as the URL location in

I'm currently returning PDF files like this:

Response.ContentType = "application/pdf";

Is there a way to open a new window with a PDF byte array in javascript.

Something like this:

var script = "'" + pdfByteArray + "', '_blank');";
ScriptManager.RegisterClientScriptBlock(Parent.Page, typeof(Page), "pdf", script, true);



It looks like will take a Data URI as the location parameter.

So you can open it like this from the question: Opening PDF String in new window with javascript:"data:application/pdf;base64, " + base64EncodedPDF);

Here's an runnable example in plunker, and sample pdf file that's already base64 encoded.

Then on the server, you can convert the byte array to base64 encoding like this:

string fileName = @"C:TEMPTEST.pdf";
byte[] pdfByteArray = System.IO.File.ReadAllBytes(fileName);
string base64EncodedPDF = System.Convert.ToBase64String(pdfByteArray);

NOTE: This seems difficult to implement in IE because the URL length is prohibitively small for sending an entire PDF.

Sunday, August 1, 2021

You can pass the argument to the function ezStream

$this->cezpdf->ezStream(array $options);

$options 'compress' => 0/1 to enable compression. For compression level please use $this->options['compression'] = at the very first point. Default: 1 'download' => 0/1 to display inline (in browser) or as download. Default: 0

Thursday, April 1, 2021

There is already a built-in method for that:

int[] array = IntStream.range(start, start + length).toArray();

IntStream.range returns a sequential ordered IntStream from the start (inclusive) to the end (exclusive) by an incremental step of 1.

If you want to include the end element, you can use IntStream.rangeClosed.

Saturday, August 14, 2021

There are some online services to converting from HTML to PDF. Here are links

Also there are some services to do vise versa.

Tuesday, November 23, 2021

you can call a javascript method from server side in by following ways:

protected void button_Click(object sender , EventArgs e)
        string jsMethodName= = "NewPage()";
        ScriptManager.RegisterClientScriptBlock(this, typeof(string), "uniqueKey", jsMethodName, true);

      //ScriptManager.RegisterStartupScript(this, GetType(), "NewPage()", false); 

you can use either ScriptManager.RegisterStartupScript or ScriptManager.RegisterClientScriptBlock

so difference between the two is explained below:

Let's say we have a .aspx page with the following form tag : (Line nos. are for reference)

1. <form id="Form1" runat="server">
2. ..
3. ..
4. ..
5. </form>

Now let's look at key differences for each method :

A. Page.RegisterClientScriptBlock() will insert the block of script before Line 2. Page.RegisterStartupScript() will insert the script after Line 4.

B. Page.RegisterClientScriptBlock() should usually be used for scripts encapsulated in functions. (hence the word "block") Page.RegisterStartupScript() can be used for any script, even if it's not in a function.

C. Page.RegisterClientScriptBlock() should be used for functions that don't need to run on Page load. Page.RegisterStartupScript() should be used for scripts that must run on Page Load.

D. Page.RegisterClientScriptBlock() should be used for a script that does not require the form elements to have been created. Page.RegisterStartupScript() should be used for scripts that require the form elements to have been created and uses references to them.

Notice that all the 4 differences are essentially related to each other (they build upon the prev. one). The difference put in one line can sometimes be too subtle.

you can know more about these from here and here

Wednesday, November 24, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :