internal PdfReaderInstance(PdfReader reader, PdfWriter writer)
 {
     this.reader = reader;
     this.writer = writer;
     file = reader.SafeFile;
     myXref = new int[reader.XrefSize];
 }
 internal PdfPatternPainter(PdfWriter wr, Color defaultColor)
     : this(wr)
 {
     stencil = true;
     if (defaultColor == null)
         this.defaultColor = new Color(System.Drawing.Color.Gray);
     else
         this.defaultColor = defaultColor;
 }
Example #3
0
 internal PdfImportedPage(PdfReaderInstance readerInstance, PdfWriter writer, int pageNumber)
 {
     this.readerInstance = readerInstance;
     this.pageNumber = pageNumber;
     this.writer = writer;
     bBox = readerInstance.Reader.GetPageSize(pageNumber);
     SetMatrix(1, 0, 0, 1, -bBox.Left, -bBox.Bottom);
     type = TYPE_IMPORTED;
 }
Example #4
0
 internal Type3Glyph(PdfWriter writer, PageResources pageResources, float wx, float llx, float lly, float urx, float ury, bool colorized)
     : base(writer)
 {
     this.pageResources = pageResources;
     this.colorized = colorized;
     if (colorized) {
         content.Append(wx).Append(" 0 d0\n");
     }
     else {
         content.Append(wx).Append(" 0 ").Append(llx).Append(' ').Append(lly).Append(' ').Append(urx).Append(' ').Append(ury).Append(" d1\n");
     }
 }
Example #5
0
 protected virtual void SuperToPdf(PdfWriter writer, Stream os)
 {
     base.ToPdf(writer, os);
 }
Example #6
0
 /**
  * Creates an efficient stream. No temporary array is ever created. The <CODE>InputStream</CODE>
  * is totally consumed but is not closed. The general usage is:
  * <p>
  * <pre>
  * InputStream in = ...;
  * PdfStream stream = new PdfStream(in, writer);
  * stream.FlateCompress();
  * writer.AddToBody(stream);
  * stream.WriteLength();
  * in.Close();
  * </pre>
  * @param inputStream the data to write to this stream
  * @param writer the <CODE>PdfWriter</CODE> for this stream
  */
 public PdfStream(Stream inputStream, PdfWriter writer)
 {
     type = STREAM;
     this.inputStream = inputStream;
     this.writer = writer;
     iref = writer.PdfIndirectReference;
     Put(PdfName.LENGTH, iref);
 }
Example #7
0
 /** Creates new PdfAcroForm */
 public PdfAcroForm(PdfWriter writer)
     : base()
 {
     this.writer = writer;
 }
Example #8
0
 /**
 * Creates a name tree.
 * @param items the item of the name tree. The key is a <CODE>String</CODE>
 * and the value is a <CODE>PdfObject</CODE>. Note that although the
 * keys are strings only the lower byte is used and no check is made for chars
 * with the same lower byte and different upper byte. This will generate a wrong
 * tree name.
 * @param writer the writer
 * @throws IOException on error
 * @return the dictionary with the name tree. This dictionary is the one
 * generally pointed to by the key /Dests, for example
 */
 public static PdfDictionary WriteTree(Hashtable items, PdfWriter writer)
 {
     if (items.Count == 0)
         return null;
     String[] names = new String[items.Count];
     items.Keys.CopyTo(names, 0);
     Array.Sort(names);
     if (names.Length <= leafSize) {
         PdfDictionary dic = new PdfDictionary();
         PdfArray ar = new PdfArray();
         for (int k = 0; k < names.Length; ++k) {
             ar.Add(new PdfString(names[k], null));
             ar.Add((PdfObject)items[names[k]]);
         }
         dic.Put(PdfName.NAMES, ar);
         return dic;
     }
     int skip = leafSize;
     PdfIndirectReference[] kids = new PdfIndirectReference[(names.Length + leafSize - 1) / leafSize];
     for (int k = 0; k < kids.Length; ++k) {
         int offset = k * leafSize;
         int end = Math.Min(offset + leafSize, names.Length);
         PdfDictionary dic = new PdfDictionary();
         PdfArray arr = new PdfArray();
         arr.Add(new PdfString(names[offset], null));
         arr.Add(new PdfString(names[end - 1], null));
         dic.Put(PdfName.LIMITS, arr);
         arr = new PdfArray();
         for (; offset < end; ++offset) {
             arr.Add(new PdfString(names[offset], null));
             arr.Add((PdfObject)items[names[offset]]);
         }
         dic.Put(PdfName.NAMES, arr);
         kids[k] = writer.AddToBody(dic).IndirectReference;
     }
     int top = kids.Length;
     while (true) {
         if (top <= leafSize) {
             PdfArray arr = new PdfArray();
             for (int k = 0; k < top; ++k)
                 arr.Add(kids[k]);
             PdfDictionary dic = new PdfDictionary();
             dic.Put(PdfName.KIDS, arr);
             return dic;
         }
         skip *= leafSize;
         int tt = (names.Length + skip - 1 )/ skip;
         for (int k = 0; k < tt; ++k) {
             int offset = k * leafSize;
             int end = Math.Min(offset + leafSize, top);
             PdfDictionary dic = new PdfDictionary();
             PdfArray arr = new PdfArray();
             arr.Add(new PdfString(names[k * skip], null));
             arr.Add(new PdfString(names[Math.Min((k + 1) * skip, names.Length) - 1], null));
             dic.Put(PdfName.LIMITS, arr);
             arr = new PdfArray();
             for (; offset < end; ++offset) {
                 arr.Add(kids[offset]);
             }
             dic.Put(PdfName.KIDS, arr);
             kids[k] = writer.AddToBody(dic).IndirectReference;
         }
         top = tt;
     }
 }
 /**
  * Called when a Chapter is written.
  * <P>
  * <CODE>position</CODE> will hold the height at which the
  * chapter will be written to.
  *
  * @param writer            the <CODE>PdfWriter</CODE> for this document
  * @param document          the document
  * @param paragraphPosition the position the chapter will be written to
  * @param title             the title of the Chapter
  */
 public virtual void OnChapter(PdfWriter writer,Document document,float paragraphPosition,Paragraph title)
 {
 }
 /**
  * Called when a Section is written.
  * <P>
  * <CODE>position</CODE> will hold the height at which the
  * section will be written to.
  *
  * @param writer            the <CODE>PdfWriter</CODE> for this document
  * @param document          the document
  * @param paragraphPosition the position the chapter will be written to
  * @param title             the title of the Chapter
  */
 public virtual void OnSection(PdfWriter writer,Document document,float paragraphPosition,int depth,Paragraph title)
 {
 }
Example #11
0
 /** Gets the page label dictionary to insert into the document.
  * @return the page label dictionary
  */
 internal PdfDictionary GetDictionary(PdfWriter writer)
 {
     return PdfNumberTree.WriteTree(map, writer);
 }
Example #12
0
 /**
 * Sets the XFA key from the instance data. The old XFA is erased.
 * @param writer the writer
 * @throws java.io.IOException on error
 */
 public void SetXfa(PdfWriter writer)
 {
     SetXfa(this, reader, writer);
 }
Example #13
0
 /**
 * Sets the XFA key from a byte array. The old XFA is erased.
 * @param form the data
 * @param reader the reader
 * @param writer the writer
 * @throws java.io.IOException on error
 */
 public static void SetXfa(XfaForm form, PdfReader reader, PdfWriter writer)
 {
     PdfDictionary af = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));
     if (af == null) {
         return;
     }
     PdfObject xfa = GetXfaObject(reader);
     if (xfa.IsArray()) {
         PdfArray ar = (PdfArray)xfa;
         int t = -1;
         int d = -1;
         for (int k = 0; k < ar.Size; k += 2) {
             PdfString s = ar.GetAsString(k);
             if ("template".Equals(s.ToString())) {
                 t = k + 1;
             }
             if ("datasets".Equals(s.ToString())) {
                 d = k + 1;
             }
         }
         if (t > -1 && d > -1) {
             reader.KillXref(ar.GetAsIndirectObject(t));
             reader.KillXref(ar.GetAsIndirectObject(d));
             PdfStream tStream = new PdfStream(SerializeDoc(form.templateNode));
             tStream.FlateCompress(writer.CompressionLevel);
             ar[t] = writer.AddToBody(tStream).IndirectReference;
             PdfStream dStream = new PdfStream(SerializeDoc(form.datasetsNode));
             dStream.FlateCompress(writer.CompressionLevel);
             ar[d] = writer.AddToBody(dStream).IndirectReference;
             af.Put(PdfName.XFA, new PdfArray(ar));
             return;
         }
     }
     reader.KillXref(af.Get(PdfName.XFA));
     PdfStream str = new PdfStream(SerializeDoc(form.domDocument));
     str.FlateCompress(writer.CompressionLevel);
     PdfIndirectReference refe = writer.AddToBody(str).IndirectReference;
     af.Put(PdfName.XFA, refe);
 }
Example #14
0
 internal AcroFields(PdfReader reader, PdfWriter writer)
 {
     this.reader = reader;
     this.writer = writer;
     xfa = new XfaForm(reader);
     if (writer is PdfStamperImp) {
         append = ((PdfStamperImp)writer).append;
     }
     Fill();
 }
Example #15
0
 /** Creates a new <CODE>TextField</CODE>.
 * @param writer the document <CODE>PdfWriter</CODE>
 * @param box the field location and dimensions
 * @param fieldName the field name. If <CODE>null</CODE> only the widget keys
 * will be included in the field allowing it to be used as a kid field.
 */
 public TextField(PdfWriter writer, Rectangle box, String fieldName)
     : base(writer, box, fieldName)
 {
 }
 /**
                                  * Called when the document is opened.
                                  *
                                  * @param writer the <CODE>PdfWriter</CODE> for this document
                                  * @param document the document
                                  */
 public virtual void OnOpenDocument(PdfWriter writer,Document document)
 {
 }
 /**
  * Called when a Paragraph is written.
  * <P>
  * <CODE>paragraphPosition</CODE> will hold the height of the end of the paragraph.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  * @param paragraphPosition the position of the end of the paragraph
  */
 public virtual void OnParagraphEnd(PdfWriter writer,Document document,float paragraphPosition)
 {
 }
Example #18
0
 public static PdfAnnotation ConvertAnnotation(PdfWriter writer, Annotation annot, Rectangle defaultRect)
 {
     switch (annot.AnnotationType) {
         case Annotation.URL_NET:
             return new PdfAnnotation(writer, annot.GetLlx(), annot.GetLly(), annot.GetUrx(), annot.GetUry(), new PdfAction((Uri) annot.Attributes[Annotation.URL]));
         case Annotation.URL_AS_STRING:
             return new PdfAnnotation(writer, annot.GetLlx(), annot.GetLly(), annot.GetUrx(), annot.GetUry(), new PdfAction((String) annot.Attributes[Annotation.FILE]));
         case Annotation.FILE_DEST:
             return new PdfAnnotation(writer, annot.GetLlx(), annot.GetLly(), annot.GetUrx(), annot.GetUry(), new PdfAction((String) annot.Attributes[Annotation.FILE], (String) annot.Attributes[Annotation.DESTINATION]));
         case Annotation.SCREEN:
             bool[] sparams = (bool[])annot.Attributes[Annotation.PARAMETERS];
             String fname = (String) annot.Attributes[Annotation.FILE];
             String mimetype = (String) annot.Attributes[Annotation.MIMETYPE];
             PdfFileSpecification fs;
             if (sparams[0])
                 fs = PdfFileSpecification.FileEmbedded(writer, fname, fname, null);
             else
                 fs = PdfFileSpecification.FileExtern(writer, fname);
             PdfAnnotation ann = PdfAnnotation.CreateScreen(writer, new Rectangle(annot.GetLlx(), annot.GetLly(), annot.GetUrx(), annot.GetUry()),
                     fname, fs, mimetype, sparams[1]);
             return ann;
         case Annotation.FILE_PAGE:
             return new PdfAnnotation(writer, annot.GetLlx(), annot.GetLly(), annot.GetUrx(), annot.GetUry(), new PdfAction((String) annot.Attributes[Annotation.FILE], (int)annot.Attributes[Annotation.PAGE]));
         case Annotation.NAMED_DEST:
             return new PdfAnnotation(writer, annot.GetLlx(), annot.GetLly(), annot.GetUrx(), annot.GetUry(), new PdfAction((int) annot.Attributes[Annotation.NAMED]));
         case Annotation.LAUNCH:
             return new PdfAnnotation(writer, annot.GetLlx(), annot.GetLly(), annot.GetUrx(), annot.GetUry(), new PdfAction((String) annot.Attributes[Annotation.APPLICATION],(String) annot.Attributes[Annotation.PARAMETERS],(String) annot.Attributes[Annotation.OPERATION],(String) annot.Attributes[Annotation.DEFAULTDIR]));
         default:
             return new PdfAnnotation(writer, defaultRect.Left, defaultRect.Bottom, defaultRect.Right, defaultRect.Top, new PdfString(annot.Title, PdfObject.TEXT_UNICODE), new PdfString(annot.Content, PdfObject.TEXT_UNICODE));
     }
 }
 /**
  * Called when a page is initialized.
  * <P>
  * Note that if even if a page is not written this method is still
  * called. It is preferable to use <CODE>onEndPage</CODE> to avoid
  * infinite loops.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  */
 public virtual void OnStartPage(PdfWriter writer,Document document)
 {
 }
Example #20
0
 public PdfArray RotateAnnotations(PdfWriter writer, Rectangle pageSize)
 {
     PdfArray array = new PdfArray();
     int rotation = pageSize.Rotation % 360;
     int currentPage = writer.CurrentPageNumber;
     for (int k = 0; k < annotations.Count; ++k) {
         PdfAnnotation dic = (PdfAnnotation)annotations[k];
         int page = dic.PlaceInPage;
         if (page > currentPage) {
             delayedAnnotations.Add(dic);
             continue;
         }
         if (dic.IsForm()) {
             if (!dic.IsUsed()) {
                 Hashtable templates = dic.Templates;
                 if (templates != null)
                     acroForm.AddFieldTemplates(templates);
             }
             PdfFormField field = (PdfFormField)dic;
             if (field.Parent == null)
                 acroForm.AddDocumentField(field.IndirectReference);
         }
         if (dic.IsAnnotation()) {
             array.Add(dic.IndirectReference);
             if (!dic.IsUsed()) {
                 PdfRectangle rect = (PdfRectangle)dic.Get(PdfName.RECT);
                 if (rect != null) {
                     switch (rotation) {
                         case 90:
                             dic.Put(PdfName.RECT, new PdfRectangle(
                                     pageSize.Top - rect.Bottom,
                                     rect.Left,
                                     pageSize.Top - rect.Top,
                                     rect.Right));
                             break;
                         case 180:
                             dic.Put(PdfName.RECT, new PdfRectangle(
                                     pageSize.Right - rect.Left,
                                     pageSize.Top - rect.Bottom,
                                     pageSize.Right - rect.Right,
                                     pageSize.Top - rect.Top));
                             break;
                         case 270:
                             dic.Put(PdfName.RECT, new PdfRectangle(
                                     rect.Bottom,
                                     pageSize.Right - rect.Left,
                                     rect.Top,
                                     pageSize.Right - rect.Right));
                             break;
                     }
                 }
             }
         }
         if (!dic.IsUsed()) {
             dic.SetUsed();
             writer.AddToBody(dic, dic.IndirectReference);
         }
     }
     return array;
 }
 /**
  * Called when the end of a Chapter is reached.
  * <P>
  * <CODE>position</CODE> will hold the height of the end of the chapter.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  * @param position the position of the end of the chapter.
  */
 public virtual void OnChapterEnd(PdfWriter writer,Document document,float position)
 {
 }
Example #22
0
 public PdfAnnotationsImp(PdfWriter writer)
 {
     acroForm = new PdfAcroForm(writer);
 }
Example #23
0
 /** Writes the font definition to the document.
  * @param writer the <CODE>PdfWriter</CODE> of this document
  */
 internal void WriteFont(PdfWriter writer)
 {
     switch (fontType) {
         case BaseFont.FONT_TYPE_T3:
             baseFont.WriteFont(writer, indirectReference, null);
             break;
         case BaseFont.FONT_TYPE_T1:
         case BaseFont.FONT_TYPE_TT: {
             int firstChar;
             int lastChar;
             for (firstChar = 0; firstChar < 256; ++firstChar) {
                 if (shortTag[firstChar] != 0)
                     break;
             }
             for (lastChar = 255; lastChar >= firstChar; --lastChar) {
                 if (shortTag[lastChar] != 0)
                     break;
             }
             if (firstChar > 255) {
                 firstChar = 255;
                 lastChar = 255;
             }
             baseFont.WriteFont(writer, indirectReference, new Object[]{firstChar, lastChar, shortTag, subset});
             break;
         }
         case BaseFont.FONT_TYPE_CJK:
             baseFont.WriteFont(writer, indirectReference, new Object[]{cjkTag});
             break;
         case BaseFont.FONT_TYPE_TTUNI:
             baseFont.WriteFont(writer, indirectReference, new Object[]{longTag, subset});
             break;
     }
 }
Example #24
0
 internal override void WriteFont(PdfWriter writer, PdfIndirectReference piref, Object[] parms)
 {
     IntHashtable cjkTag = (IntHashtable)parms[0];
     PdfIndirectReference ind_font = null;
     PdfObject pobj = null;
     PdfIndirectObject obj = null;
     pobj = GetFontDescriptor();
     if (pobj != null){
     obj = writer.AddToBody(pobj);
     ind_font = obj.IndirectReference;
     }
     pobj = GetCIDFont(ind_font, cjkTag);
     if (pobj != null){
     obj = writer.AddToBody(pobj);
     ind_font = obj.IndirectReference;
     }
     pobj = GetFontBaseType(ind_font);
     writer.AddToBody(pobj, piref);
 }
Example #25
0
 /**
 * Creates a new instance of PushbuttonField
 * @param writer the document <CODE>PdfWriter</CODE>
 * @param box the field location and dimensions
 * @param fieldName the field name. If <CODE>null</CODE> only the widget keys
 * will be included in the field allowing it to be used as a kid field.
 */
 public PushbuttonField(PdfWriter writer, Rectangle box, String fieldName)
     : base(writer, box, fieldName)
 {
 }
 /**
  * Called when the document is closed.
  * <P>
  * Note that this method is called with the page number equal
  * to the last page plus one.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  */
 public virtual void OnCloseDocument(PdfWriter writer,Document document)
 {
 }
Example #27
0
        public override void ToPdf(PdfWriter writer, Stream os)
        {
            if (inputStream != null && compressed)
                Put(PdfName.FILTER, PdfName.FLATEDECODE);
            PdfEncryption crypto = null;
            if (writer != null)
                crypto = writer.Encryption;
            if (crypto != null) {
                PdfObject filter = Get(PdfName.FILTER);
                if (filter != null) {
                    if (PdfName.CRYPT.Equals(filter))
                        crypto = null;
                    else if (filter.IsArray()) {
                        PdfArray a = ((PdfArray)filter);
                        if (a.Size > 0 && PdfName.CRYPT.Equals(a[0]))
                            crypto = null;
                    }
                }
            }
            PdfObject nn = Get(PdfName.LENGTH);
            if (crypto != null && nn != null && nn.IsNumber()) {
                int sz = ((PdfNumber)nn).IntValue;
                Put(PdfName.LENGTH, new PdfNumber(crypto.CalculateStreamSize(sz)));
                SuperToPdf(writer, os);
                Put(PdfName.LENGTH, nn);
            }
            else
                SuperToPdf(writer, os);
            os.Write(STARTSTREAM, 0, STARTSTREAM.Length);
            if (inputStream != null) {
                rawLength = 0;
                ZDeflaterOutputStream def = null;
                OutputStreamCounter osc = new OutputStreamCounter(os);
                OutputStreamEncryption ose = null;
                Stream fout = osc;
                if (crypto != null && !crypto.IsEmbeddedFilesOnly())
                    fout = ose = crypto.GetEncryptionStream(fout);
                if (compressed)
                    fout = def = new ZDeflaterOutputStream(fout, compressionLevel);

                byte[] buf = new byte[4192];
                while (true) {
                    int n = inputStream.Read(buf, 0, buf.Length);
                    if (n <= 0)
                        break;
                    fout.Write(buf, 0, n);
                    rawLength += n;
                }
                if (def != null)
                    def.Finish();
                if (ose != null)
                    ose.Finish();
                inputStreamLength = osc.Counter;
            }
            else {
                if (crypto != null && !crypto.IsEmbeddedFilesOnly()) {
                    byte[] b;
                    if (streamBytes != null) {
                        b = crypto.EncryptByteArray(streamBytes.ToArray());
                    }
                    else {
                        b = crypto.EncryptByteArray(bytes);
                    }
                    os.Write(b, 0, b.Length);
                }
                else {
                    if (streamBytes != null)
                        streamBytes.WriteTo(os);
                    else
                        os.Write(bytes, 0, bytes.Length);
                }
            }
            os.Write(ENDSTREAM, 0, ENDSTREAM.Length);
        }
 /**
  * Called when a page is finished, just before being written to the document.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  */
 public virtual void OnEndPage(PdfWriter writer,Document document)
 {
 }
Example #29
0
 public override void ToPdf(PdfWriter writer, Stream os)
 {
     if (os is OutputStreamCounter)
         position = ((OutputStreamCounter)os).Counter;
     base.ToPdf(writer, os);
 }
 /**
  * Called when a <CODE>Chunk</CODE> with a generic tag is written.
  * <P>
  * It is usefull to pinpoint the <CODE>Chunk</CODE> location to generate
  * bookmarks, for example.
  *
  * @param writer the <CODE>PdfWriter</CODE> for this document
  * @param document the document
  * @param rect the <CODE>Rectangle</CODE> containing the <CODE>Chunk</CODE>
  * @param text the text of the tag
  */
 public virtual void OnGenericTag(PdfWriter writer,Document document,Rectangle rect,string text)
 {
 }