PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

PDF to a new window browser
http://forum.pdfsharp.de/viewtopic.php?f=2&t=1333
Page 1 of 1

Author:  ki_ko [ Thu Sep 16, 2010 9:41 am ]
Post subject:  PDF to a new window browser

Hello all, a have a webaplication in aspx using c#, and i'm using pdfsharp to create a document and now i open the document in the same window, but i want to open in a new browser window, could someone help me.
thanks.

this is part off my code:

MemoryStream stream = new MemoryStream();
document.Save(stream, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", stream.Length.ToString());
Response.BinaryWrite(stream.ToArray());
Response.Flush();
stream.Close();
Response.End();


thanks

Author:  Thomas Hoevel [ Thu Sep 16, 2010 11:07 am ]
Post subject:  Re: PDF to a new window browser

Hi!

To open a new window, specify "target='_blank'" in the link that calls the ASPX page.
AFAIK you can't control this with response headers.

See also here:
viewtopic.php?p=1470#p1470

Author:  ki_ko [ Thu Sep 16, 2010 11:31 am ]
Post subject:  Re: PDF to a new window browser

Code:
MemoryStream stream = new MemoryStream();
        document.Save(stream, false);
        Response.Clear();
       
       //Response.ContentType = "application/pdf"
        Response.AddHeader("Content-Disposition", "inline;");
        Response.AddHeader("content-length", stream.Length.ToString());
       
        Response.BinaryWrite(stream.ToArray());
        Response.Write("<script>window.open('Teste.aspx','_blank');</script>");
        Response.Flush();
        stream.Close();
        Response.End();


whit this code instead off open a new window, it open a dialog box to save the pdf file.
but i want a new window

Author:  ki_ko [ Mon Sep 20, 2010 4:29 pm ]
Post subject:  Re: PDF to a new window browser

in firefox he opens in the same windows and show this:

%PDF-1.4 %���� 1 0 obj << /CreationDate(D:20100920172655+01'00') /Title(Estatistica) /Creator(PDFsharp 1.31.1789-g \(www.pdfsharp.com\)) /Producer(PDFsharp 1.31.1789-g \(www.pdfsharp.com\)) >> endobj 2 0 obj << /Type/Catalog /Pages 3 0 R >> endobj 3 0 obj << /Type/Pages /Count 1 /Kids[4 0 R] >> endobj 4 0 obj << /Type/Page /MediaBox[0 0 595 842] /Parent 3 0 R /Contents 5 0 R /Resources << /ProcSet [/PDF/Text/ImageB/ImageC/ImageI] /ExtGState << /GS0 6 0 R /GS1 12 0 R >> /Font << /F0 8 0 R /F1 11 0 R >> /XObject << /I0 9 0 R >> >> /Group << /CS/DeviceRGB /S/Transparency /I false /K false >> >> endobj 5 0 obj << /Length 789 /Filter/FlateDecode >> stream x���MnA��s�Z�����n/! ���b�M�ȱۀ�=8W�6,Y��Tg��Ɖ�H�Nb�^���^��]!�1I�QpqC���Z�/�b���r[LOH��XH��u� ��r��,�����j ��]���]]�a^����f���\ϫ-�0� .....(etc.)

Author:  ki_ko [ Tue Sep 21, 2010 1:36 pm ]
Post subject:  Re: PDF to a new window browser

please help me:
in my page i have a button that have part off this code:

Code:
  MemoryStream stream = new MemoryStream();
        document.Save(stream, false);
        Response.Clear();

        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "inline;");
      //  Response.AddHeader("content-length", stream.Length.ToString());
       
        Response.BinaryWrite(stream.ToArray());
   

        // Response.Write("<script>window.open('TesteImpressao.aspx','_blank');</script>");
        Page.ClientScript.RegisterStartupScript(this.GetType(), "client", "window.open('http://localhost:50154/Teste/TesteImpressao.aspx','_blank');", true);


        Response.Flush();
        stream.Close();
        Response.End();




and i have TesteImpressao.aspx empty , what i have missing.

Author:  Thomas Hoevel [ Tue Sep 21, 2010 2:02 pm ]
Post subject:  Re: PDF to a new window browser

ki_ko wrote:
and i have TesteImpressao.aspx empty , what i have missing.


The page that returns the PDF file must be called with a link that opens a new window.
Your page returns a PDF file - and tries to open a new windows.

So if e. g. MyPage.aspx has a button that calls MyPDF.aspx to show a PDF file, then you must add the "_blank" stuff in MyPage.aspx.
User clicks on the button in MyPage.aspx, browser opens a new window and calls MyPDF.aspx to get the contents for the new window.

Author:  ki_ko [ Tue Sep 21, 2010 4:51 pm ]
Post subject:  Re: PDF to a new window browser

ok i have one button in my page that create the pdf and i want that the same button send the pdf to another page .
i have tried this way in button click():

Code:
        MemoryStream stream = new MemoryStream();
        document.Save(stream, false);
        Response.Clear();
        Response.ContentType = "application/pdf";
        Response.AddHeader("Content-Disposition", "inline;");
       Response.AddHeader("content-length", stream.Length.ToString());       
        Response.BinaryWrite(stream.ToArray());   
         //Response.Write("<script>window.open('TesteImpressao.aspx','_blank');</script>");
        Page.ClientScript.RegisterStartupScript(this.GetType(), "client", "window.open('TesteImpressao.aspx','_blank');", true);
   
        //Context .Response .BinaryWrite (stream );

        Response.Flush();
        stream.Close();
        Response.End();


but it keeps open the pdf in the same page.
know i'm confused

Author:  Thomas Hoevel [ Wed Sep 22, 2010 11:19 am ]
Post subject:  Re: PDF to a new window browser

ki_ko wrote:
but it keeps open the pdf in the same page.
know i'm confused

The page that returns the PDF file must be called with a link that opens a new window.
Your page returns a PDF file - and at the same time tries to open a new windows.

So if e. g. MyPage.aspx has a button that calls MyPDF.aspx to show a PDF file, then you must add the "_blank" stuff in MyPage.aspx.
User clicks on the button in MyPage.aspx, browser opens a new window and calls MyPDF.aspx to get the contents for the new window.

The button click() is IMHO the wrong place to try and open the new window and to create the PDF at the same time.

Open a new window with an *.aspx as content and have that *.aspx return the PDF file.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/