| 发表于:2007-09-07 14:03:26 楼主 |
memorystream m = new memorystream(); document document = new document(); htmlworker worker = new htmlworker(document); system.net.webclient mywebclient = new system.net.webclient(); mywebclient.credentials = system.net.credentialcache.defaultcredentials; byte[] pagedata = mywebclient.downloaddata( "http://localhost/web/products/itemshow.aspx?espno= "+baserequest.getstring( "espno ")); string pagehtml = system.text.encoding.default.getstring(pagedata); textreader filereader = new stringreader(pagehtml); //response.write(pagehtml); //response.end(); try { response.contenttype = "application/pdf "; response.addheader( "content-disposition ", "attachment; filename= "+baserequest.getstring( "espno ")+ ".pdf "); // filereader filereader = new filereader( "chinese.html "); pdfwriter.getinstance(document, m); //basefont bf = basefont.createfont( "c:\\windows\\fonts\\arial.ttf ", basefont.identity_h, basefont.not_embedded); //font font1 = new font(bf, 12, font.normal); document.open(); stylesheet styles = new stylesheet(); styles.loadtagstyle( "td ", "face ", "gulim "); styles.loadtagstyle( "td ", "encoding ", "identity-h "); styles.loadtagstyle( "td ", "leading ", "12,0 "); styles.loadtagstyle( "body ", "face ", "simhei "); styles.loadtagstyle( "body ", "encoding ", "identity-h "); styles.loadtagstyle( "body ", "leading ", "12,0 "); hashtable hashpars = new hashtable(); hashpars.add( "img_baseurl ", "http://localhost/web/products/ "); worker.style = styles; worker.interfaceprops = hashpars; worker.parse(filereader); } catch (documentexception ex) { console.error.writeline(ex.stacktrace); console.error.writeline(ex.message); } // step 5: close document document.close(); //response.end(); // // step 6: write pdf bytes to outputstream response.outputstream.write(m.getbuffer(), 0, m.getbuffer().length); response.outputstream.flush(); response.outputstream.close(); |
|
|
|
|