PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Thu Jul 18, 2024 7:38 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Thu Sep 16, 2010 9:41 am 
Offline

Joined: Thu Sep 16, 2010 9:33 am
Posts: 5
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 16, 2010 11:07 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 16, 2010 11:31 am 
Offline

Joined: Thu Sep 16, 2010 9:33 am
Posts: 5
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 20, 2010 4:29 pm 
Offline

Joined: Thu Sep 16, 2010 9:33 am
Posts: 5
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.)


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 21, 2010 1:36 pm 
Offline

Joined: Thu Sep 16, 2010 9:33 am
Posts: 5
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.


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 21, 2010 2:02 pm 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Tue Sep 21, 2010 4:51 pm 
Offline

Joined: Thu Sep 16, 2010 9:33 am
Posts: 5
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 22, 2010 11:19 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group