當前位置: 首頁>>代碼示例>>C#>>正文


C# PdfStream.Put方法代碼示例

本文整理匯總了C#中iTextSharp.text.pdf.PdfStream.Put方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfStream.Put方法的具體用法?C# PdfStream.Put怎麽用?C# PdfStream.Put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在iTextSharp.text.pdf.PdfStream的用法示例。


在下文中一共展示了PdfStream.Put方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetFormXObject

 /**
 * Gets the stream representing this object.
 *
 * @param   compressionLevel    the compressionLevel
 * @return the stream representing this template
 * @since   2.1.3   (replacing the method without param compressionLevel)
 * @throws IOException
 */
 override public PdfStream GetFormXObject(int compressionLevel) {
     PdfStream s = new PdfStream(content.ToByteArray());
     s.Put(PdfName.TYPE, PdfName.XOBJECT);
     s.Put(PdfName.SUBTYPE, PdfName.PS);
     s.FlateCompress(compressionLevel);
     return s;
 }
開發者ID:Gianluigi,項目名稱:dssnet,代碼行數:15,代碼來源:PdfPSXObject.cs

示例2: Write

        // ---------------------------------------------------------------------------
        public void Write(Stream stream)
        {
            // step 1
              using (Document document = new Document()) {
            // step 2
            PdfWriter writer = PdfWriter.GetInstance(document, stream);
            // step 3
            document.Open();
            // step 4
            Rectangle rect = new Rectangle(100, 400, 500, 800);
            rect.Border = Rectangle.BOX;
            rect.BorderWidth = 0.5f;
            rect.BorderColor = new BaseColor(0xFF, 0x00, 0x00);
            document.Add(rect);

            PdfIndirectObject streamObject = null;
            using (FileStream fs =
              new FileStream(RESOURCE, FileMode.Open, FileAccess.Read))
            {
              PdfStream stream3D = new PdfStream(fs, writer);

              stream3D.Put(PdfName.TYPE, new PdfName("3D"));
              stream3D.Put(PdfName.SUBTYPE, new PdfName("U3D"));
              stream3D.FlateCompress();
              streamObject = writer.AddToBody(stream3D);
              stream3D.WriteLength();
            }

            PdfDictionary dict3D = new PdfDictionary();
            dict3D.Put(PdfName.TYPE, new PdfName("3DView"));
            dict3D.Put(new PdfName("XN"), new PdfString("Default"));
            dict3D.Put(new PdfName("IN"), new PdfString("Unnamed"));
            dict3D.Put(new PdfName("MS"), PdfName.M);
            dict3D.Put(
              new PdfName("C2W"),
              new PdfArray(
            new float[] { 1, 0, 0, 0, 0, -1, 0, 1, 0, 3, -235, 28 }
              )
            );
            dict3D.Put(PdfName.CO, new PdfNumber(235));

            PdfIndirectObject dictObject = writer.AddToBody(dict3D);

            PdfAnnotation annot = new PdfAnnotation(writer, rect);
            annot.Put(PdfName.CONTENTS, new PdfString("3D Model"));
            annot.Put(PdfName.SUBTYPE, new PdfName("3D"));
            annot.Put(PdfName.TYPE, PdfName.ANNOT);
            annot.Put(new PdfName("3DD"), streamObject.IndirectReference);
            annot.Put(new PdfName("3DV"), dictObject.IndirectReference);
            PdfAppearance ap = writer.DirectContent.CreateAppearance(
              rect.Width, rect.Height
            );
            annot.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, ap);
            annot.SetPage();

            writer.AddAnnotation(annot);
              }
        }
開發者ID:kuujinbo,項目名稱:iTextInAction2Ed,代碼行數:59,代碼來源:Pdf3D.cs

示例3: ManipulatePdf

// ---------------------------------------------------------------------------     
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
      // the font file
      byte[] fontfile = null;
      using (FileStream fs = new FileStream(
        FONT, FileMode.Open, FileAccess.Read)) 
      {
        fontfile = new byte[fs.Length];
        fs.Read(fontfile, 0, (int) fs.Length);
      }
      // create a new stream for the font file
      PdfStream stream = new PdfStream(fontfile);
      stream.FlateCompress();
      stream.Put(PdfName.LENGTH1, new PdfNumber(fontfile.Length));
      // create a reader object
      PdfReader reader = new PdfReader(src);
      int n = reader.XrefSize;
      PdfDictionary font;
      using (MemoryStream ms = new MemoryStream()) {      
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          PdfName fontname = new PdfName(FONTNAME);
          for (int i = 0; i < n; i++) {
            PdfObject objectPdf = reader.GetPdfObject(i);
            if (objectPdf == null || !objectPdf.IsDictionary()) {
              continue;
            }
            font = (PdfDictionary)objectPdf;
            if (PdfName.FONTDESCRIPTOR.Equals(font.Get(PdfName.TYPE))
                && fontname.Equals(font.Get(PdfName.FONTNAME))) 
            {
              PdfIndirectObject objref = stamper.Writer.AddToBody(stream);
              font.Put(PdfName.FONTFILE2, objref.IndirectReference);
            }
          }
        }
        return ms.ToArray();
      }
    } 
開發者ID:,項目名稱:,代碼行數:42,代碼來源:

示例4: WriteCrossReferenceTable

 /**
 * Returns the CrossReferenceTable of the <CODE>Body</CODE>.
 * @param os
 * @param root
 * @param info
 * @param encryption
 * @param fileID
 * @param prevxref
 * @throws IOException
 */
 virtual public void WriteCrossReferenceTable(Stream os, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, long prevxref) {
     int refNumber = 0;
     if (writer.FullCompression) {
         FlushObjStm();
         refNumber = IndirectReferenceNumber;
         xrefs[new PdfCrossReference(refNumber, position)] = null;
     }
     int first = ((PdfCrossReference)xrefs.GetMinKey()).Refnum;
     int len = 0;
     List<int> sections = new List<int>();
     foreach (PdfCrossReference entry in xrefs.Keys) {
         if (first + len == entry.Refnum)
             ++len;
         else {
             sections.Add(first);
             sections.Add(len);
             first = entry.Refnum;
             len = 1;
         }
     }
     sections.Add(first);
     sections.Add(len);
     if (writer.FullCompression) {
         int mid = 5;
         long mask = 0xff00000000L;
         for (; mid > 1; --mid) {
             if ((mask & position) != 0)
                 break;
             mask >>= 8;
         }
         ByteBuffer buf = new ByteBuffer();
         
         foreach (PdfCrossReference entry in xrefs.Keys) {
             entry.ToPdf(mid, buf);
         }
         PdfStream xr = new PdfStream(buf.ToByteArray());
         buf = null;
         xr.FlateCompress(writer.CompressionLevel);
         xr.Put(PdfName.SIZE, new PdfNumber(Size));
         xr.Put(PdfName.ROOT, root);
         if (info != null) {
             xr.Put(PdfName.INFO, info);
         }
         if (encryption != null)
             xr.Put(PdfName.ENCRYPT, encryption);
         if (fileID != null)
             xr.Put(PdfName.ID, fileID);
         xr.Put(PdfName.W, new PdfArray(new int[]{1, mid, 2}));
         xr.Put(PdfName.TYPE, PdfName.XREF);
         PdfArray idx = new PdfArray();
         for (int k = 0; k < sections.Count; ++k)
             idx.Add(new PdfNumber(sections[k]));
         xr.Put(PdfName.INDEX, idx);
         if (prevxref > 0)
             xr.Put(PdfName.PREV, new PdfNumber(prevxref));
         PdfEncryption enc = writer.crypto;
         writer.crypto = null;
         PdfIndirectObject indirect = new PdfIndirectObject(refNumber, xr, writer);
         indirect.WriteTo(writer.Os);
         writer.crypto = enc;
     }
     else {
         byte[] tmp = GetISOBytes("xref\n");
         os.Write(tmp, 0, tmp.Length);
         System.Collections.IEnumerator i = xrefs.Keys;
         i.MoveNext();
         for (int k = 0; k < sections.Count; k += 2) {
             first = sections[k];
             len = sections[k + 1];
             tmp = GetISOBytes(first.ToString());
             os.Write(tmp, 0, tmp.Length);
             os.WriteByte((byte)' ');
             tmp = GetISOBytes(len.ToString());
             os.Write(tmp, 0, tmp.Length);
             os.WriteByte((byte)'\n');
             while (len-- > 0) {
                 ((PdfCrossReference)i.Current).ToPdf(os);
                 i.MoveNext();
             }
         }
     }
 }
開發者ID:,項目名稱:,代碼行數:92,代碼來源:

示例5: FlushObjStm

 virtual public void FlushObjStm() {
     if (numObj == 0)
         return;
     int first = index.Size;
     index.Append(streamObjects);
     PdfStream stream = new PdfStream(index.ToByteArray());
     stream.FlateCompress(writer.CompressionLevel);
     stream.Put(PdfName.TYPE, PdfName.OBJSTM);
     stream.Put(PdfName.N, new PdfNumber(numObj));
     stream.Put(PdfName.FIRST, new PdfNumber(first));
     Add(stream, currentObjNum);
     index = null;
     streamObjects = null;
     numObj = 0;
 }
開發者ID:,項目名稱:,代碼行數:15,代碼來源:

示例6: Close

        /**
        * Signals that the <CODE>Document</CODE> was closed and that no other
        * <CODE>Elements</CODE> will be added.
        * <P>
        * The pages-tree is built and written to the outputstream.
        * A Catalog is constructed, as well as an Info-object,
        * the referencetable is composed and everything is written
        * to the outputstream embedded in a Trailer.
        */
        public override void Close() {
            if (open) {
                if ((currentPageNumber - 1) != pageReferences.Count)
                    throw new Exception("The page " + pageReferences.Count +
                    " was requested but the document has only " + (currentPageNumber - 1) + " pages.");
                pdf.Close();
                AddSharedObjectsToBody();
                foreach (IPdfOCG layer in documentOCG.Keys) {
                    AddToBody(layer.PdfObject, layer.Ref);
                }
                // add the root to the body
                PdfIndirectReference rootRef = root.WritePageTree();
                // make the catalog-object and add it to the body
                PdfDictionary catalog = GetCatalog(rootRef);
                // [C9] if there is XMP data to add: add it
                if (xmpMetadata != null) {
                    PdfStream xmp = new PdfStream(xmpMetadata);
                    xmp.Put(PdfName.TYPE, PdfName.METADATA);
                    xmp.Put(PdfName.SUBTYPE, PdfName.XML);
                    if (crypto != null && !crypto.IsMetadataEncrypted()) {
                        PdfArray ar = new PdfArray();
                        ar.Add(PdfName.CRYPT);
                        xmp.Put(PdfName.FILTER, ar);
                    }
                    catalog.Put(PdfName.METADATA, body.Add(xmp).IndirectReference);
                }
                // [C10] make pdfx conformant
                if (IsPdfX()) {
                    CompleteInfoDictionary(Info);
                    CompleteExtraCatalog(ExtraCatalog);
                }
                // [C11] Output Intents
                if (extraCatalog != null) {
                    catalog.MergeDifferent(extraCatalog);
                }
                
                WriteOutlines(catalog, false);

                // add the Catalog to the body
                PdfIndirectObject indirectCatalog = AddToBody(catalog, false);
                // add the info-object to the body
                PdfIndirectObject infoObj = AddToBody(Info, false);

                // [F1] encryption
                PdfIndirectReference encryption = null;
                PdfObject fileID = null;
                body.FlushObjStm();
                if (crypto != null) {
                    PdfIndirectObject encryptionObject = AddToBody(crypto.GetEncryptionDictionary(), false);
                    encryption = encryptionObject.IndirectReference;
                    fileID = crypto.FileID;
                }
                else
                    fileID = PdfEncryption.CreateInfoId(PdfEncryption.CreateDocumentId());
                
                // write the cross-reference table of the body
                body.WriteCrossReferenceTable(os, indirectCatalog.IndirectReference,
                    infoObj.IndirectReference, encryption,  fileID, prevxref);

                // make the trailer
                // [F2] full compression
                if (fullCompression) {
                    WriteKeyInfo(os);
                    byte[] tmp = GetISOBytes("startxref\n");
                    os.Write(tmp, 0, tmp.Length);
                    tmp = GetISOBytes(body.Offset.ToString());
                    os.Write(tmp, 0, tmp.Length);
                    tmp = GetISOBytes("\n%%EOF\n");
                    os.Write(tmp, 0, tmp.Length);
                }
                else {
                    PdfTrailer trailer = new PdfTrailer(body.Size,
                    body.Offset,
                    indirectCatalog.IndirectReference,
                    infoObj.IndirectReference,
                    encryption,
                    fileID, prevxref);
                    trailer.ToPdf(this, os);
                }
                base.Close();
            }
        }
開發者ID:,項目名稱:,代碼行數:91,代碼來源:

示例7: Close

 internal void Close(Hashtable moreInfo)
 {
     if (closed)
         return;
     if (useVp) {
         reader.SetViewerPreferences(viewerPreferences);
         MarkUsed(reader.Trailer.Get(PdfName.ROOT));
     }
     if (flat)
         FlatFields();
     if (flatFreeText)
         FlatFreeTextFields();
     AddFieldResources();
     PdfDictionary acroForm = (PdfDictionary)PdfReader.GetPdfObject(reader.Catalog.Get(PdfName.ACROFORM), reader.Catalog);
     if (acroFields != null && acroFields.Xfa.Changed) {
         MarkUsed(acroForm);
         if (!flat)
             acroFields.Xfa.SetXfa(this);
     }
     if (sigFlags != 0) {
         if (acroForm != null) {
             acroForm.Put(PdfName.SIGFLAGS, new PdfNumber(sigFlags));
             MarkUsed(acroForm);
         }
     }
     closed = true;
     AddSharedObjectsToBody();
     SetOutlines();
     SetJavaScript();
     AddFileAttachments();
     PdfDictionary catalog = reader.Catalog;
     if (openAction != null) {
         catalog.Put(PdfName.OPENACTION, openAction);
     }
     byte[] altMetadata = xmpMetadata;
     if (altMetadata == null) {
         PdfObject xmpo = PdfReader.GetPdfObject(catalog.Get(PdfName.METADATA));
         if (xmpo != null && xmpo.IsStream()) {
             altMetadata = PdfReader.GetStreamBytesRaw((PRStream)xmpo);
             PdfReader.KillIndirect(xmpo);
         }
     }
     // if there is XMP data to add: add it
     if (altMetadata != null) {
         PdfStream xmp = new PdfStream(altMetadata);
         xmp.Put(PdfName.TYPE, PdfName.METADATA);
         xmp.Put(PdfName.SUBTYPE, PdfName.XML);
         if (crypto != null && !crypto.IsMetadataEncrypted()) {
             PdfArray ar = new PdfArray();
             ar.Add(PdfName.CRYPT);
             xmp.Put(PdfName.FILTER, ar);
         }
         catalog.Put(PdfName.METADATA, body.Add(xmp).IndirectReference);
         MarkUsed(catalog);
     }
     PRIndirectReference iInfo = null;
     try {
         file.ReOpen();
         AlterContents();
         iInfo = (PRIndirectReference)reader.trailer.Get(PdfName.INFO);
         int skip = -1;
         if (iInfo != null)
             skip = iInfo.Number;
         int rootN = ((PRIndirectReference)reader.trailer.Get(PdfName.ROOT)).Number;
         if (append) {
             int[] keys = marked.GetKeys();
             for (int k = 0; k < keys.Length; ++k) {
                 int j = keys[k];
                 PdfObject obj = reader.GetPdfObjectRelease(j);
                 if (obj != null && skip != j && j < initialXrefSize) {
                     AddToBody(obj, j, j != rootN);
                 }
             }
             for (int k = initialXrefSize; k < reader.XrefSize; ++k) {
                 PdfObject obj = reader.GetPdfObject(k);
                 if (obj != null) {
                     AddToBody(obj, GetNewObjectNumber(reader, k, 0));
                 }
             }
         }
         else {
             for (int k = 1; k < reader.XrefSize; ++k) {
                 PdfObject obj = reader.GetPdfObjectRelease(k);
                 if (obj != null && skip != k) {
                     AddToBody(obj, GetNewObjectNumber(reader, k, 0), k != rootN);
                 }
             }
         }
     }
     finally {
         try {
             file.Close();
         }
         catch  {
             // empty on purpose
         }
     }
     PdfIndirectReference encryption = null;
     PdfObject fileID = null;
     if (crypto != null) {
//.........這裏部分代碼省略.........
開發者ID:hjgode,項目名稱:iTextSharpCF,代碼行數:101,代碼來源:PdfStamperImp.cs

示例8: Close

 protected internal virtual void Close(IDictionary<String, String> moreInfo)
 {
     if (closed)
         return;
     if (useVp) {
         SetViewerPreferences();
     }
     if (flat)
         FlatFields();
     if (flatFreeText)
         FlatFreeTextFields();
     AddFieldResources();
     PdfDictionary catalog = reader.Catalog;
     PdfDictionary acroForm = (PdfDictionary)PdfReader.GetPdfObject(catalog.Get(PdfName.ACROFORM), reader.Catalog);
     if (acroFields != null && acroFields.Xfa.Changed) {
         MarkUsed(acroForm);
         if (!flat)
             acroFields.Xfa.SetXfa(this);
     }
     if (sigFlags != 0) {
         if (acroForm != null) {
             acroForm.Put(PdfName.SIGFLAGS, new PdfNumber(sigFlags));
             MarkUsed(acroForm);
             MarkUsed(catalog);
         }
     }
     closed = true;
     AddSharedObjectsToBody();
     SetOutlines();
     SetJavaScript();
     AddFileAttachments();
     if (openAction != null) {
         catalog.Put(PdfName.OPENACTION, openAction);
     }
     if (pdf.pageLabels != null)
         catalog.Put(PdfName.PAGELABELS, pdf.pageLabels.GetDictionary(this));
     // OCG
     if (documentOCG.Count > 0) {
         FillOCProperties(false);
         PdfDictionary ocdict = catalog.GetAsDict(PdfName.OCPROPERTIES);
         if (ocdict == null) {
             reader.Catalog.Put(PdfName.OCPROPERTIES, OCProperties);
         }
         else {
             ocdict.Put(PdfName.OCGS, OCProperties.Get(PdfName.OCGS));
             PdfDictionary ddict = ocdict.GetAsDict(PdfName.D);
             if (ddict == null) {
                 ddict = new PdfDictionary();
                 ocdict.Put(PdfName.D, ddict);
             }
             ddict.Put(PdfName.ORDER, OCProperties.GetAsDict(PdfName.D).Get(PdfName.ORDER));
             ddict.Put(PdfName.RBGROUPS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.RBGROUPS));
             ddict.Put(PdfName.OFF, OCProperties.GetAsDict(PdfName.D).Get(PdfName.OFF));
             ddict.Put(PdfName.AS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.AS));
         }
     }
     // metadata
     int skipInfo = -1;
     PdfObject oInfo = reader.Trailer.Get(PdfName.INFO);
     PRIndirectReference iInfo = null;
     PdfDictionary oldInfo = null;
     if (oInfo is PRIndirectReference)
         iInfo = (PRIndirectReference)oInfo;
     if (iInfo != null)
         oldInfo = (PdfDictionary)PdfReader.GetPdfObject(iInfo);
     else if (oInfo is PdfDictionary)
         oldInfo = (PdfDictionary)oInfo;
     String producer = null;
     if (iInfo != null)
         skipInfo = iInfo.Number;
     if (oldInfo != null && oldInfo.Get(PdfName.PRODUCER) != null)
         producer = oldInfo.GetAsString(PdfName.PRODUCER).ToUnicodeString();
     Version version = Version.GetInstance();
     if (producer == null) {
         producer = version.GetVersion;
     }
     else if (producer.IndexOf(version.Product) == -1) {
         StringBuilder buf = new StringBuilder(producer);
         buf.Append("; modified using ");
         buf.Append(version.GetVersion);
         producer = buf.ToString();
     }
     PdfIndirectReference info = null;
     PdfDictionary newInfo = new PdfDictionary();
     if (oldInfo != null) {
         foreach (PdfName key in oldInfo.Keys) {
             PdfObject value = PdfReader.GetPdfObject(oldInfo.Get(key));
             newInfo.Put(key, value);
         }
     }
     if (moreInfo != null) {
         foreach (KeyValuePair<string,string> entry in moreInfo) {
             PdfName keyName = new PdfName(entry.Key);
             String value = entry.Value;
             if (value == null)
                 newInfo.Remove(keyName);
             else
                 newInfo.Put(keyName, new PdfString(value, PdfObject.TEXT_UNICODE));
         }
     }
//.........這裏部分代碼省略.........
開發者ID:mapo80,項目名稱:iTextSharp-Monotouch,代碼行數:101,代碼來源:PdfStamperImp.cs

示例9: Close

 internal void Close(IDictionary<String, String> moreInfo)
 {
     if (closed)
         return;
     if (useVp) {
         reader.SetViewerPreferences(viewerPreferences);
         MarkUsed(reader.Trailer.Get(PdfName.ROOT));
     }
     if (flat)
         FlatFields();
     if (flatFreeText)
         FlatFreeTextFields();
     AddFieldResources();
     PdfDictionary catalog = reader.Catalog;
     PdfDictionary pages = (PdfDictionary)PdfReader.GetPdfObject(catalog.Get(PdfName.PAGES));
     pages.Put(PdfName.ITXT, new PdfString(Document.Release));
     MarkUsed(pages);
     PdfDictionary acroForm = (PdfDictionary)PdfReader.GetPdfObject(catalog.Get(PdfName.ACROFORM), reader.Catalog);
     if (acroFields != null && acroFields.Xfa.Changed) {
         MarkUsed(acroForm);
         if (!flat)
             acroFields.Xfa.SetXfa(this);
     }
     if (sigFlags != 0) {
         if (acroForm != null) {
             acroForm.Put(PdfName.SIGFLAGS, new PdfNumber(sigFlags));
             MarkUsed(acroForm);
             MarkUsed(catalog);
         }
     }
     closed = true;
     AddSharedObjectsToBody();
     SetOutlines();
     SetJavaScript();
     AddFileAttachments();
     if (openAction != null) {
         catalog.Put(PdfName.OPENACTION, openAction);
     }
     if (pdf.pageLabels != null)
         catalog.Put(PdfName.PAGELABELS, pdf.pageLabels.GetDictionary(this));
     // OCG
     if (documentOCG.Count > 0) {
         FillOCProperties(false);
         PdfDictionary ocdict = catalog.GetAsDict(PdfName.OCPROPERTIES);
         if (ocdict == null) {
             reader.Catalog.Put(PdfName.OCPROPERTIES, OCProperties);
         }
         else {
             ocdict.Put(PdfName.OCGS, OCProperties.Get(PdfName.OCGS));
             PdfDictionary ddict = ocdict.GetAsDict(PdfName.D);
             if (ddict == null) {
                 ddict = new PdfDictionary();
                 ocdict.Put(PdfName.D, ddict);
             }
             ddict.Put(PdfName.ORDER, OCProperties.GetAsDict(PdfName.D).Get(PdfName.ORDER));
             ddict.Put(PdfName.RBGROUPS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.RBGROUPS));
             ddict.Put(PdfName.OFF, OCProperties.GetAsDict(PdfName.D).Get(PdfName.OFF));
             ddict.Put(PdfName.AS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.AS));
         }
     }
     // metadata
     int skipInfo = -1;
     PdfObject oInfo = reader.Trailer.Get(PdfName.INFO);
     PRIndirectReference iInfo = null;
     PdfDictionary oldInfo = null;
     if (oInfo is PRIndirectReference)
         iInfo = (PRIndirectReference)oInfo;
     if (iInfo != null)
         oldInfo = (PdfDictionary)PdfReader.GetPdfObject(iInfo);
     else if (oInfo is PdfDictionary)
         oldInfo = (PdfDictionary)oInfo;
     String producer = null;
     if (iInfo != null)
         skipInfo = iInfo.Number;
     if (oldInfo != null && oldInfo.Get(PdfName.PRODUCER) != null)
         producer = oldInfo.GetAsString(PdfName.PRODUCER).ToUnicodeString();
     if (producer == null) {
         producer = Document.Version;
     }
     else if (producer.IndexOf(Document.Product) == -1) {
         StringBuilder buf = new StringBuilder(producer);
         buf.Append("; modified using ");
         buf.Append(Document.Version);
         producer = buf.ToString();
     }
     PdfIndirectReference info = null;
     PdfDictionary newInfo = new PdfDictionary();
     if (oldInfo != null) {
         foreach (PdfName key in oldInfo.Keys) {
             PdfObject value = PdfReader.GetPdfObject(oldInfo.Get(key));
             newInfo.Put(key, value);
         }
     }
     if (moreInfo != null) {
         foreach (KeyValuePair<string,string> entry in moreInfo) {
             PdfName keyName = new PdfName(entry.Key);
             String value = entry.Value;
             if (value == null)
                 newInfo.Remove(keyName);
             else
//.........這裏部分代碼省略.........
開發者ID:boecko,項目名稱:iTextSharp,代碼行數:101,代碼來源:PdfStamperImp.cs

示例10: WriteCrossReferenceTable

            /**
            * Returns the CrossReferenceTable of the <CODE>Body</CODE>.
            * @param os
            * @param root
            * @param info
            * @param encryption
            * @param fileID
            * @param prevxref
            * @throws IOException
            */
            internal void WriteCrossReferenceTable(Stream os, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, int prevxref)
            {
                int refNumber = 0;
                if (writer.FullCompression) {
                    FlushObjStm();
                    refNumber = IndirectReferenceNumber;
                    xrefs[new PdfCrossReference(refNumber, position)] = null;
                }
                PdfCrossReference entry = (PdfCrossReference)((DictionaryEntry)xrefs.Begin.Current).Key;
                int first = entry.Refnum;
                int len = 0;
                ArrayList sections = new ArrayList();
                for (k_Iterator i = xrefs.Begin.Clone(); i != xrefs.End; i.Next()) {
                    entry = (PdfCrossReference)((DictionaryEntry)i.Current).Key;
                    if (first + len == entry.Refnum)
                        ++len;
                    else {
                        sections.Add(first);
                        sections.Add(len);
                        first = entry.Refnum;
                        len = 1;
                    }
                }
                sections.Add(first);
                sections.Add(len);
                if (writer.FullCompression) {
                    int mid = 4;
                    uint mask = 0xff000000;
                    for (; mid > 1; --mid) {
                        if ((mask & position) != 0)
                            break;
                        mask >>= 8;
                    }
                    ByteBuffer buf = new ByteBuffer();

                    for (k_Iterator i = xrefs.Begin.Clone(); i != xrefs.End; i.Next()) {
                        entry = (PdfCrossReference)((DictionaryEntry)i.Current).Key;
                        entry.ToPdf(mid, buf);
                    }
                    PdfStream xr = new PdfStream(buf.ToByteArray());
                    buf = null;
                    xr.FlateCompress();
                    xr.Put(PdfName.SIZE, new PdfNumber(Size));
                    xr.Put(PdfName.ROOT, root);
                    if (info != null) {
                        xr.Put(PdfName.INFO, info);
                    }
                    if (encryption != null)
                        xr.Put(PdfName.ENCRYPT, encryption);
                    if (fileID != null)
                        xr.Put(PdfName.ID, fileID);
                    xr.Put(PdfName.W, new PdfArray(new int[]{1, mid, 2}));
                    xr.Put(PdfName.TYPE, PdfName.XREF);
                    PdfArray idx = new PdfArray();
                    for (int k = 0; k < sections.Count; ++k)
                        idx.Add(new PdfNumber((int)sections[k]));
                    xr.Put(PdfName.INDEX, idx);
                    if (prevxref > 0)
                        xr.Put(PdfName.PREV, new PdfNumber(prevxref));
                    PdfEncryption enc = writer.crypto;
                    writer.crypto = null;
                    PdfIndirectObject indirect = new PdfIndirectObject(refNumber, xr, writer);
                    indirect.WriteTo(writer.Os);
                    writer.crypto = enc;
                }
                else {
                    byte[] tmp = GetISOBytes("xref\n");
                    os.Write(tmp, 0, tmp.Length);
                    k_Iterator i = xrefs.Begin.Clone();
                    for (int k = 0; k < sections.Count; k += 2) {
                        first = (int)sections[k];
                        len = (int)sections[k + 1];
                        tmp = GetISOBytes(first.ToString());
                        os.Write(tmp, 0, tmp.Length);
                        os.WriteByte((byte)' ');
                        tmp = GetISOBytes(len.ToString());
                        os.Write(tmp, 0, tmp.Length);
                        os.WriteByte((byte)'\n');
                        while (len-- > 0) {
                            entry = (PdfCrossReference)((DictionaryEntry)i.Current).Key;
                            entry.ToPdf(os);
                            i.Next();
                        }
                    }
                }
            }
開發者ID:hjgode,項目名稱:iTextSharpCF,代碼行數:96,代碼來源:PdfWriter.cs

示例11: NewPage

        /**
        * Makes a new page and sends it to the <CODE>PdfWriter</CODE>.
        *
        * @return a <CODE>bool</CODE>
        * @throws DocumentException on error
        */
        public override bool NewPage() {
            lastElementType = -1;
            if (PageEmpty) {
                SetNewPageSizeAndMargins();
                return false;
            }
            if (!open || close) {
                throw new Exception(MessageLocalization.GetComposedMessage("the.document.is.not.open"));
            }
            IPdfPageEvent pageEvent = writer.PageEvent;
            if (pageEvent != null)
                pageEvent.OnEndPage(writer, this);
            
            //Added to inform any listeners that we are moving to a new page (added by David Freels)
            base.NewPage();
            
            // the following 2 lines were added by Pelikan Stephan
            indentation.imageIndentLeft = 0;
            indentation.imageIndentRight = 0;
            
            // we flush the arraylist with recently written lines
            FlushLines();
            // we prepare the elements of the page dictionary
            
            // [U1] page size and rotation
            int rotation = pageSize.Rotation;
            
            // [C10]
            if (writer.IsPdfX()) {
                if (thisBoxSize.ContainsKey("art") && thisBoxSize.ContainsKey("trim"))
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("only.one.of.artbox.or.trimbox.can.exist.in.the.page"));
                if (!thisBoxSize.ContainsKey("art") && !thisBoxSize.ContainsKey("trim")) {
                    if (thisBoxSize.ContainsKey("crop"))
                        thisBoxSize["trim"] = thisBoxSize["crop"];
                    else
                        thisBoxSize["trim"] = new PdfRectangle(pageSize, pageSize.Rotation);
                }
            }
            
            // [M1]
            pageResources.AddDefaultColorDiff(writer.DefaultColorspace);        
            if (writer.RgbTransparencyBlending) {
                PdfDictionary dcs = new PdfDictionary();
                dcs.Put(PdfName.CS, PdfName.DEVICERGB);
                pageResources.AddDefaultColorDiff(dcs);
            }
            PdfDictionary resources = pageResources.Resources;
            
            // we create the page dictionary
            
            PdfPage page = new PdfPage(new PdfRectangle(pageSize, rotation), thisBoxSize, resources, rotation);
            page.Put(PdfName.TABS, writer.Tabs);

            // we complete the page dictionary
            
            // [C9] if there is XMP data to add: add it
            if (xmpMetadata != null) {
                PdfStream xmp = new PdfStream(xmpMetadata);
                xmp.Put(PdfName.TYPE, PdfName.METADATA);
                xmp.Put(PdfName.SUBTYPE, PdfName.XML);
                PdfEncryption crypto = writer.Encryption;
                if (crypto != null && !crypto.IsMetadataEncrypted()) {
                    PdfArray ar = new PdfArray();
                    ar.Add(PdfName.CRYPT);
                    xmp.Put(PdfName.FILTER, ar);
                }
                page.Put(PdfName.METADATA, writer.AddToBody(xmp).IndirectReference);
            }
            
            // [U3] page actions: transition, duration, additional actions
            if (this.transition!=null) {
                page.Put(PdfName.TRANS, this.transition.TransitionDictionary);
                transition = null;
            }
            if (this.duration>0) {
                page.Put(PdfName.DUR,new PdfNumber(this.duration));
                duration = 0;
            }
            if (pageAA != null) {
                page.Put(PdfName.AA, writer.AddToBody(pageAA).IndirectReference);
                pageAA = null;
            }
            
            // [U4] we add the thumbs
            if (thumb != null) {
                page.Put(PdfName.THUMB, thumb);
                thumb = null;
            }
            
            // [U8] we check if the userunit is defined
            if (writer.Userunit > 0f) {
                page.Put(PdfName.USERUNIT, new PdfNumber(writer.Userunit));
            }
            
//.........這裏部分代碼省略.........
開發者ID:pusp,項目名稱:o2platform,代碼行數:101,代碼來源:PdfDocument.cs


注:本文中的iTextSharp.text.pdf.PdfStream.Put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。