예제 #1
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;
 }
예제 #2
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;
 }
예제 #3
0
        /**
         * convenience method. Given an importedpage, set our "globals"
         */
        protected int SetFromIPage(PdfImportedPage iPage)
        {
            int pageNum            = iPage.PageNumber;
            PdfReaderInstance inst = currentPdfReaderInstance = iPage.PdfReaderInstance;

            reader = inst.Reader;
            SetFromReader(reader);
            return(pageNum);
        }
예제 #4
0
        /**
         * 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)
            {
                PdfReaderInstance ri = currentPdfReaderInstance;
                pdf.Close();
                base.Close();
                if (ri != null)
                {
                    try {
                        ri.Reader.Close();
                        ri.ReaderFile.Close();
                    }
                    catch (IOException) {
                        // empty on purpose
                    }
                }
            }
        }
예제 #5
0
        protected void AddSharedObjectsToBody()
        {
            // add the fonts
            foreach (FontDetails details in documentFonts.Values) {
                details.WriteFont(this);
            }
            // add the form XObjects
            foreach (Object[] objs in formXObjects.Values) {
                PdfTemplate template = (PdfTemplate)objs[1];
                if (template != null && template.IndirectReference is PRIndirectReference)
                    continue;
                if (template != null && template.Type == PdfTemplate.TYPE_TEMPLATE) {
                    AddToBody(template.GetFormXObject(compressionLevel), template.IndirectReference);
                }
            }
            // add all the dependencies in the imported pages
            foreach (PdfReaderInstance rd in importedPages.Values) {
                currentPdfReaderInstance = rd;
                currentPdfReaderInstance.WriteAllPages();
            }
            currentPdfReaderInstance = null;
            // add the color
            foreach (ColorDetails color in documentColors.Values) {
                AddToBody(color.GetSpotColor(this), color.IndirectReference);
            }
            // add the pattern
            foreach (PdfPatternPainter pat in documentPatterns.Keys) {
                AddToBody(pat.GetPattern(compressionLevel), pat.IndirectReference);
            }
            // add the shading patterns
            foreach (PdfShadingPattern shadingPattern in documentShadingPatterns.Keys) {
                shadingPattern.AddToBody();
            }
            // add the shadings
            foreach (PdfShading shading in documentShadings.Keys) {
                shading.AddToBody();
            }
            // add the extgstate
            foreach (DictionaryEntry entry in documentExtGState) {
                PdfDictionary gstate = (PdfDictionary)entry.Key;
                PdfObject[] obj = (PdfObject[])entry.Value;
                AddToBody(gstate, (PdfIndirectReference)obj[1]);
            }

            // add the properties
            foreach (DictionaryEntry entry in documentProperties) {
                Object prop = entry.Key;
                PdfObject[] obj = (PdfObject[])entry.Value;
                if (prop is PdfLayerMembership){
                    PdfLayerMembership layer = (PdfLayerMembership)prop;
                    AddToBody(layer.PdfObject, layer.Ref);
                }
                else if ((prop is PdfDictionary) && !(prop is PdfLayer)){
                    AddToBody((PdfDictionary)prop, (PdfIndirectReference)obj[1]);
                }
            }
            foreach (IPdfOCG layer in documentOCG.Keys) {
                AddToBody(layer.PdfObject, layer.Ref);
            }
        }
예제 #6
0
 /** Writes the reader to the document and frees the memory used by it.
 * The main use is when concatenating multiple documents to keep the
 * memory usage restricted to the current appending document.
 * @param reader the <CODE>PdfReader</CODE> to free
 * @throws IOException on error
 */
 public virtual void FreeReader(PdfReader reader)
 {
     currentPdfReaderInstance = (PdfReaderInstance)importedPages[reader];
     if (currentPdfReaderInstance == null)
         return;
     currentPdfReaderInstance.WriteAllPages();
     currentPdfReaderInstance = null;
     importedPages.Remove(reader);
 }