How can I POST data to a website using the PurePDF library?

422 views Asked by At

I'm evaluating the differences between the purePDF and alivePDF libraries in flex, and I'm setting up some IO code so that I can save documents from either from a web based flex application.

AlivePDF gives a very convenient save() function that sends the data to a web service, which can simply bounce it back using Content-Disposition: Attatchment, but PurePDF has no such feature. How can I send the PDF data from purePDF to a webservice in a similar way?

1

There are 1 answers

0
Dan Monego On BEST ANSWER

The trick is to create a byte array before creating the PdfWriter, pass that into the writer when you create it, and read the document off of the writer.

        var bytes:ByteArray = new ByteArray()
        var writer:PdfWriter = PdfWriter.create(bytes, PageSize.A10);
        var printPage:PdfDocument = writer.pdfDocument;
        var rect:RectangleElement = new RectangleElement(1, 10, 10, 1);
        rect.backgroundColor = new RGBColor(255, 0, 0);
        printPage.open();
        printPage.add(rect);
        printPage.close();

        var urlRequest:URLRequest = new URLRequest("http://someserver.com/someservice");
        urlRequest.method = "POST";
        urlRequest.data = bytes;
        navigateToURL(urlRequest);