i manage convert image file pdf file.. want make automatically save specific location , without asking me save it. please me, appreciated. beginner here. here code im trying.
imports system.drawing imports system.drawing.imaging imports system.text imports system.windows.forms imports pdfsharp.pdf imports pdfsharp.drawing imports system.io public class form1 private sub capturescreen() 'button1_click(byval sender system.object, byval e system.eventargs) handles button1.click dim graph graphics = nothing try ' gets upper left hand coordinate of form dim frmleft system.drawing.point = me.bounds.location 'use commented out version full screen 'dim bmp new bitmap(screen.primaryscreen.bounds.width, screen.primaryscreen.bounds.height) 'this version size of form1 + 8 adds little right , bottom of captured. dim bmp new bitmap(me.bounds.width + 8, me.bounds.height + 8) 'creates grapgic graph = graphics.fromimage(bmp) 'gets x,y coordinates upper left start point 'used below dim screenx integer = frmleft.x dim screeny integer = frmleft.y ' - 5 here allows more of form shown top , left sides. graph.copyfromscreen(screenx - 5, screeny - 5, 0, 0, bmp.size) ' save screenshot file bmp.save("i:\eqa\temp.png") bmp.dispose() graph.dispose() catch ex exception msgbox(ex.message) end try end sub private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click capturescreen() ' create new pdf document , page dim doc new pdfdocument() dim opage new pdfpage() ' add page pdf document , add captured image doc.pages.add(opage) 'dim xgr xgraphics = xgraphics.frompdfpage(opage) dim img ximage = ximage.fromfile("i:\eqa\temp.png") 'xgr.drawimage(img, 0, 0) 'create ximage object file. using ximg = pdfsharp.drawing.ximage.fromfile("i:\eqa\temp.png") 'resize page width , height fit image size. opage.width = ximg.pixelwidth * 72 / ximg.horizontalresolution opage.height = ximg.pixelheight * 72 / ximg.horizontalresolution 'draw current image file page. dim xgr = pdfsharp.drawing.xgraphics.frompdfpage(opage) xgr.drawimage(ximg, 0, 0, opage.width, opage.height) end using ' instantiate bitmap object dim filesaveas new savefiledialog filesaveas.filter = ("pdf file|*.pdf") dim btnsave dialogresult = filesaveas.showdialog() if btnsave.equals(dialogresult.ok) doc.save(filesaveas.filename) doc.close() end if ' used dispose() function able ' save same form again, in case values have changed. ' when didn't use function, gdi+ error occurred. img.dispose() end sub end class
Comments
Post a Comment