Ejemplo n.º 1
0
 /** Creates new PdfStamperImp.
 * @param reader the read PDF
 * @param os the output destination
 * @param pdfVersion the new pdf version or '\0' to keep the same version as the original
 * document
 * @param append
 * @throws DocumentException on error
 * @throws IOException
 */
 internal PdfStamperImp(PdfReader reader, Stream os, char pdfVersion, bool append)
     : base(new PdfDocument(), os)
 {
     if (!reader.IsOpenedWithFullPermissions)
         throw new BadPasswordException("PdfReader not opened with owner password");
     if (reader.Tampered)
         throw new DocumentException("The original document was reused. Read it again from file.");
     reader.Tampered = true;
     this.reader = reader;
     file = reader.SafeFile;
     this.append = append;
     if (append) {
         if (reader.IsRebuilt())
             throw new DocumentException("Append mode requires a document without errors even if recovery was possible.");
         if (reader.IsEncrypted())
             crypto = new PdfEncryption(reader.Decrypt);
         pdf_version.SetAppendmode(true);
         file.ReOpen();
         byte[] buf = new byte[8192];
         int n;
         while ((n = file.Read(buf)) > 0)
             this.os.Write(buf, 0, n);
         file.Close();
         prevxref = reader.LastXref;
         reader.Appendable = true;
     }
     else {
         if (pdfVersion == 0)
             base.PdfVersion = reader.PdfVersion;
         else
             base.PdfVersion = pdfVersion;
     }
     base.Open();
     pdf.AddWriter(this);
     if (append) {
         body.Refnum = reader.XrefSize;
         marked = new IntHashtable();
         if (reader.IsNewXrefType())
             fullCompression = true;
         if (reader.IsHybridXref())
             fullCompression = false;
     }
     initialXrefSize = reader.XrefSize;
 }