Results 1 to 3 of 3

Thread: [RESOLVED] PDF Encoding

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    Resolved [RESOLVED] PDF Encoding

    Hey all,
    I am writing a desktop app and an ASP page that will work together. The ASP page will run on my customer's server and the app will run their vendors' computers. The app will allow the vendor to see what work is coming in the near future.

    When the app is run, I go through a series of login and authentication steps before the vendor gets to a list of part numbers and dates. When they click one of the part numbers, the app will send a post request to the ASP page which will then return the PDF drawing to the vendor. This all works fine except the PDF page is all black when I open in the default pdf viewer on the desktop machine.

    When I run the ASP page in the debugger, the browser displays the PDF correctly, so I'm pretty sure the problem lies on the desktop side; probably in the decoding.

    Here is the code I use to send the pdf from the ASP page (c#.. moved away from vb last year)....
    ASP.Net Code:
    1. Response.ContentType = "application/pdf";
    2. Response.ContentEncoding = System.Text.Encoding.Default;
    3. Response.WriteFile(filePath);

    and here is the code used in the desktop app to receive the response,
    c# Code:
    1. using (IO.Stream receiveStream = webResponse.GetResponseStream())
    2.             {
    3.                 IO.StreamReader readStream = new IO.StreamReader(receiveStream, System.Text.Encoding.Default);
    4.                 string returnString = readStream.ReadToEnd();
    5.                 IO.File.WriteAllText(fileName, returnString);      
    6.             }


    Any help would be greatly appreciated.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: PDF Encoding

    I am concerned that you are using WriteAllText, because the file presumably has binary data that might not get written correctly that way.

    WriteAllBytes seems more appropriate.

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,757

    Re: PDF Encoding

    yep. That was it.

    Was actually a problem on the c# side. Here is the working code which pushes the web response stream into a memory stream, then creates a byte array from the memory stream.
    C# Code:
    1. byte[] returnArray = null;
    2.             using (IO.Stream receiveStream = webResponse.GetResponseStream())
    3.             {
    4.                 using (IO.MemoryStream memoryStream = new IO.MemoryStream())
    5.                 {
    6.                     int count = 0;
    7.                     byte[] b = new byte[4096];
    8.                     do
    9.                     {
    10.                         count = receiveStream.Read(b, 0, b.Length);
    11.                         memoryStream.Write(b, 0, count);
    12.  
    13.                     } while (count != 0);
    14.                     returnArray = memoryStream.ToArray();
    15.                 }            
    16.             }
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width