调用webapi控件以返回pdf,但带有标题

时间:2016-05-16 13:41:08

标签: asp.net-web-api webclient

How to retrieve a PDF using WebBrowser or WebClient in .NET?

我对上面的请求有类似的要求,但我希望这是下载窗口或自动下载文件并显示在浏览器的底部。

我需要它能够在请求中发送标头(自制/读取标头)。如何重定向到页面,将下载文件而不是自动保存?

SetupWebClient是我设置我需要的标题....

WebClient wc = new WebClient();
wc = this.SetupWebClient(wc);
wc.DownloadData(http://www.testurl.com/PdfController/GetDocumentPDF/" + customerdocument.DocumentId + "/" + customerdocument.CustomerId);

1 个答案:

答案 0 :(得分:0)

以下是我必须要做的事情,如果其他人碰到这个......必须劫持这条小溪,然后执行以下操作:

package game;

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

/**
 *
 * @author rafal
 */
public class Game {

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     */
    public static void main(String[] args) throws IOException {
        BufferedImage image = ImageIO.read(new File("/home/rafal/Pulpit/obraz.png"));
        byte[][] pixels = new byte[image.getWidth()][];

    for (int x = 0; x < image.getWidth(); x++) {
    pixels[x] = new byte[image.getHeight()];

    for (int y = 0; y < image.getHeight(); y++) {
        pixels[x][y] = (byte) (image.getRGB(x, y) == 0xFFFFFFFF ? 0 : 1);
    }
}

    for (int x = 0; x < image.getWidth(); x++) {
         for (int y = 0; y < image.getHeight(); y++)
         {
             if(pixels[x][y] == 1);
             pixels[x][y] = 0;
         }

    }
    /*
 * Create a new 1-dimensional byte array which will hold the result
 * Set its size to the item count in the pixelData array
 */
byte[] oneDimArray = new byte[pixels.length * pixels[0].length];
 byte[][] twoDimArray = new byte[ image.getWidth()][ image.getHeight()];
/*
 * Loop through the "horizontal" row in the pixelData array
 */
for(int x = 0; x < pixels.length; x++) {
    /*
     * Loop through each item in the current vertical row
     */
    for(int y = 0; y < pixels[x].length; y++) {

        /*
         * Set each item in the 1-dimensional array to the corresponding
         * item in the 2-dimensional array
         */
        oneDimArray[x + y * pixels.length] = twoDimArray[x][y];
    }
}

   ByteArrayInputStream byteIn = new ByteArrayInputStream(oneDimArray);
   BufferedImage finalImage = ImageIO.read(byteIn);

   ImageIO.write(finalImage, "png",new File("/home/rafal/Pulpit/obraz2.png"));


    }

}