public void StartBook(IDevice device, string destination, string bookname) { iTextSharp.text.Document doc = new iTextSharp.text.Document(); this._logDestination = Path.Combine(destination, bookname) + ".log"; string targetFile = Path.Combine(destination, bookname) + ".pdf"; this._document = new Document(new iTextSharp.text.Rectangle(device.Width, device.Height)); this._document.AddTitle(bookname); this._document.SetMargins(0,0,0,0); this._targetWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(this._document, File.Open(targetFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None)); this._document.Open(); this._bookname = bookname; this._count = 0; }
private void CommonConstructor( iTextSharp.text.Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom, System.IO.Stream stream, string fontpath, BackgroundImageDefinition bImageDefinition ){ if(this.fontpath != null)this.fontpath = fontpath; this.margin_left = marginLeft; this.margin_right = marginRight; this.margin_top = marginTop; this.margin_bottom = marginBottom; this.pageSize = pageSize; this._backgroundImage = bImageDefinition; _pdfDoc = new iTextSharp.text.Document(pageSize, margin_left, margin_right, margin_top, margin_bottom); _iPDFWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(PdfDoc, stream); PdfDoc.Open(); iPDFContent = PDFWriter.DirectContent; _init(); initRow(); }
/// <summary> /// Use this method to write XMP data to a new PDF /// </summary> /// <param name="writer"></param> private void CreateXmpMetadata(iTextSharp.text.pdf.PdfWriter writer) { // Set up the buffer to hold the XMP metadata byte[] buffer = new byte[65536]; System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer, true); try { // XMP supports a number of different schemas, which are made available by iTextSharp. // Here, the Dublin Core schema is chosen. iTextSharp.text.xml.xmp.XmpSchema dc = new iTextSharp.text.xml.xmp.DublinCoreSchema(); // Add Dublin Core attributes iTextSharp.text.xml.xmp.LangAlt title = new iTextSharp.text.xml.xmp.LangAlt(); title.Add("x-default", "Video rental system by Tripple Bounty"); dc.SetProperty(iTextSharp.text.xml.xmp.DublinCoreSchema.TITLE, title); // Dublin Core allows multiple authors, so we create an XmpArray to hold the values iTextSharp.text.xml.xmp.XmpArray author = new iTextSharp.text.xml.xmp.XmpArray(iTextSharp.text.xml.xmp.XmpArray.ORDERED); author.Add("Tripple bounty"); dc.SetProperty(iTextSharp.text.xml.xmp.DublinCoreSchema.CREATOR, author); // Multiple subjects are also possible, so another XmpArray is used iTextSharp.text.xml.xmp.XmpArray subject = new iTextSharp.text.xml.xmp.XmpArray(iTextSharp.text.xml.xmp.XmpArray.UNORDERED); subject.Add("Video casettes"); subject.Add("Video rental system"); dc.SetProperty(iTextSharp.text.xml.xmp.DublinCoreSchema.SUBJECT, subject); // Create an XmpWriter using the MemoryStream defined earlier iTextSharp.text.xml.xmp.XmpWriter xmp = new iTextSharp.text.xml.xmp.XmpWriter(ms); xmp.AddRdfDescription(dc); // Add the completed metadata definition to the XmpWriter xmp.Close(); // This flushes the XMP metadata into the buffer //--------------------------------------------------------------------------------- // Shrink the buffer to the correct size (discard empty elements of the byte array) int bufsize = buffer.Length; int bufcount = 0; foreach (byte b in buffer) { if (b == 0) { break; } bufcount++; } System.IO.MemoryStream ms2 = new System.IO.MemoryStream(buffer, 0, bufcount); buffer = ms2.ToArray(); //--------------------------------------------------------------------------------- // Add all of the XMP metadata to the PDF doc that we're building writer.XmpMetadata = buffer; } catch (Exception ex) { throw ex; } finally { ms.Close(); ms.Dispose(); } }