c# dll generated pdf file is damaged -
i using itextsharp write pdf file in c#. have created classlibrary project , referenced in windows application. dll created pdf file when called, when open pdf file view says there error opening document. file damaged , not repaired.
here dll code create pdf file
public class class1 { public void createpdf() { // orignal string filename = "desktop\\test_" + datetime.now.tostring("yyyymmddhhmm") + ".pdf"; filestream fs = new filestream(filename, filemode.create, fileaccess.write, fileshare.none); document doc = new document(pagesize.a4, 10, 10, 10, 10); doc.setmargins(10, 10, 10, 10); pdfwriter writer = pdfwriter.getinstance(doc, fs); doc.open(); doc.newpage(); basefont bftimes = basefont.createfont(basefont.times_roman, basefont.cp1252, false); itextsharp.text.font times = new itextsharp.text.font(bftimes, 9, itextsharp.text.font.italic, itextsharp.text.basecolor.red); itextsharp.text.font font = fontfactory.getfont(fontfactory.helvetica, 9, basecolor.black); itextsharp.text.font fontsmall = fontfactory.getfont(fontfactory.helvetica, 2, basecolor.black); itextsharp.text.font fontbold = fontfactory.getfont(fontfactory.helvetica_bold, 9, basecolor.black); paragraph clientname = new paragraph("client name :" + " " + "client", font); paragraph date = new paragraph("date :" + " " + datetime.today.toshorttimestring(), font); doc.add(clientname); doc.add(date); lineseparator ls = new lineseparator(); ls.linewidth = 7f; doc.add(new chunk(ls, font.isbold())); paragraph some= new paragraph("some data", fontbold); doc.add(some); doc.add(new chunk(ls, font.isbold())); dmtximageencoder encoder = new dmtximageencoder(); dmtximageencoderoptions options = new dmtximageencoderoptions(); options.sizeidx = dmtxsymbolsize.dmtxsymbol18x18; options.scheme = dmtxscheme.dmtxschemec40; bitmap qrbitmap = encoder.encodeimage("123456789", options); itextsharp.text.image qrpic = itextsharp.text.image.getinstance(qrbitmap, system.drawing.imaging.imageformat.jpeg); qrpic.scalepercent(15f); doc.add(qrpic); doc.close(); //system.diagnostics.process.start(filename); } } and how calling in windows application
testdll.class1 m = new testdll.class1(); m.createpdf(); messagebox.show("done"); it creates pdf file damaged. please let me know doing wrong , how can fix code.
all things aside if remove current logic creating qr codes - itextsharp supports few different types of qr/barcode creation methods.
aside not making use of using statements following code (along current code) started generating qr/barcodes. i'm not sure want populate qr/barcode i'm unable create exact working copy you, should off ground!
if unclear please let me know , can edit answer provide more clear understanding.
the below code taken official itext docs (originally in java), changed purposes.
doc.add(new paragraph("barcode pdf417")); barcodepdf417 pdf417 = new barcodepdf417(); string text = "call me ishmael. years ago--never mind how long " + "precisely --having little or no money in purse, , nothing " + "particular interest me on shore, thought sail " + "a little , see watery part of world."; pdf417.settext(text); image img = pdf417.getimage(); img.scalepercent(50, 50 * pdf417.yheight); doc.add(img); doc.add(new paragraph("barcode datamatrix")); barcodedatamatrix datamatrix = new barcodedatamatrix(); datamatrix.generate(text); img = datamatrix.createimage(); doc.add(img); doc.add(new paragraph("barcode qrcode")); barcodeqrcode qrcode = new barcodeqrcode("moby dick herman melville", 1, 1, null); img = qrcode.getimage(); doc.add(img); below example of output:

Comments
Post a Comment