pub fn write_to<W>(&mut self, writer: W) -> io::Result<()> where W: Write {
        let mut out = Counter::new(writer);
        out.write_all(b"%PDF-1.7\n%\xB5\xED\xAE\xFB\n")?;
        
        if !self.page_buffer.is_empty() {
            self.end_page();
        }

        // Write out each object
        for (idx, obj) in self.objects.iter_mut().enumerate().skip(2) {
            obj.offset = Some(out.pos());
            write!(out, "{} 0 obj\n", idx+1)?;
            out.write_all(&obj.contents)?;
            out.write_all(b"endobj\n")?;
        }

        // Write out the page tree object
        self.objects[1].offset = Some(out.pos());
        out.write_all(b"2 0 obj\n")?;
        out.write_all(b"<< /Type /Pages\n")?;
        write!(out,
            "/Count {}\n",
            self.objects.iter().filter(|o| o.is_page).count()
        )?;
        out.write_all(b"/Kids [")?;
        for (idx, _obj) in self.objects.iter().enumerate().filter(|&(_, obj)| obj.is_page) {
            write!(out, "{} 0 R ", idx + 1)?;
        }
        out.write_all(b"] >>\nendobj\n")?;

        // Write out the catalog dictionary object
        self.objects[0].offset = Some(out.pos());
        out.write_all(b"1 0 obj\n<< /Type /Catalog\n/Pages 2 0 R >>\nendobj\n")?;

        // Write the cross-reference table
        let startxref = out.pos() + 1; // NOTE: apparently there's some 1-based indexing??
        out.write_all(b"xref\n")?;
        write!(out, "0 {}\n", self.objects.len() + 1)?;
        out.write_all(b"0000000000 65535 f \n")?;

        for obj in &self.objects {
            write!(out, "{:010} 00000 f \n", obj.offset.unwrap())?;
        }

        // Write the document trailer
        out.write_all(b"trailer\n")?;
        write!(out, "<< /Size {}\n", self.objects.len())?;
        out.write_all(b"/Root 1 0 R >>\n")?;

        // Write the offset to the xref table
        write!(out, "startxref\n{}\n", startxref)?;

        // Write the PDF EOF
        out.write_all(b"%%EOF")?;
        
        Ok(())
    }
/// Write the in-memory PDF representation to disk
Write the in-memory PDF representation to disk
Write the in - memory PDF representation to disk
pub fn write_to<W>(&mut self, writer: W) -> io::Result<()> where W: Write {
        let mut out = Counter::new(writer);
        out.write_all(b"%PDF-1.7\n%\xB5\xED\xAE\xFB\n")?;
        if !self.page_buffer.is_empty() {
            self.end_page();
        }
        // Write out each object
        for (idx, obj) in self.objects.iter_mut().enumerate().skip(2) {
            obj.offset = Some(out.pos());
            write!(out, "{} 0 obj\n", idx+1)?;
            out.write_all(&obj.contents)?;
            out.write_all(b"endobj\n")?;
        }
        // Write out the page tree object
        self.objects[1].offset = Some(out.pos());
        out.write_all(b"2 0 obj\n")?;
        out.write_all(b"<< /Type /Pages\n")?;
        write!(out,
            "/Count {}\n",
            self.objects.iter().filter(|o| o.is_page).count()
        )?;
        out.write_all(b"/Kids [")?;
        for (idx, _obj) in self.objects.iter().enumerate().filter(|&(_, obj)| obj.is_page) {
            write!(out, "{} 0 R ", idx + 1)?;
        }
        out.write_all(b"] >>\nendobj\n")?;
        // Write out the catalog dictionary object
        self.objects[0].offset = Some(out.pos());
        out.write_all(b"1 0 obj\n<< /Type /Catalog\n/Pages 2 0 R >>\nendobj\n")?;
        // Write the cross-reference table
        let startxref = out.pos() + 1; // NOTE: apparently there's some 1-based indexing??
        out.write_all(b"xref\n")?;
        write!(out, "0 {}\n", self.objects.len() + 1)?;
        out.write_all(b"0000000000 65535 f \n")?;
        for obj in &self.objects {
            write!(out, "{:010} 00000 f \n", obj.offset.unwrap())?;
        }
        // Write the document trailer
        out.write_all(b"trailer\n")?;
        write!(out, "<< /Size {}\n", self.objects.len())?;
        out.write_all(b"/Root 1 0 R >>\n")?;
        // Write the offset to the xref table
        write!(out, "startxref\n{}\n", startxref)?;
        // Write the PDF EOF
        out.write_all(b"%%EOF")?;
        Ok(())
    }
pub fn write_to < W > ( & mut self , writer : W ) -> io :: Result < ( ) > where W : Write { let mut out = Counter :: new ( writer ) ; out . write_all ( b" \n \xB5 \xED \xAE \xFB \n " ) ? ; if ! self . page_buffer . is_empty ( ) { self . end_page ( ) ; } // Write out each object for ( idx , obj ) in self . objects . iter_mut ( ) . enumerate ( ) . skip ( 2 ) { obj . offset = Some ( out . pos ( ) ) ; write ! ( out " \n " idx 1 ) ? ; out . write_all ( & obj . contents ) ? ; out . write_all ( b" \n " ) ? ; } // Write out the page tree object self . objects [ 1 ] . offset = Some ( out . pos ( ) ) ; out . write_all ( b" \n " ) ? ; out . write_all ( b" \n " ) ? ; write ! ( out " \n " self objects iter ( ) filter ( o o is_page ) count ( ) ) ? ; out . write_all ( b" " ) ? ; for ( idx , _obj ) in self . objects . iter ( ) . enumerate ( ) . filter ( | & ( _ , obj ) | obj . is_page ) { write ! ( out " " idx 1 ) ? ; } out . write_all ( b" \n \n " ) ? ; // Write out the catalog dictionary object self . objects [ 0 ] . offset = Some ( out . pos ( ) ) ; out . write_all ( b" \n \n \n \n " ) ? ; // Write the cross-reference table let startxref = out . pos ( ) + 1 ; // NOTE: apparently there's some 1-based indexing?? out . write_all ( b" \n " ) ? ; write ! ( out " \n " self objects len ( ) 1 ) ? ; out . write_all ( b" \n " ) ? ; for obj in & self . objects { write ! ( out " \n " obj offset unwrap ( ) ) ? ; } // Write the document trailer out . write_all ( b" \n " ) ? ; write ! ( out " \n " self objects len ( ) ) ? ; out . write_all ( b" \n " ) ? ; // Write the offset to the xref table write ! ( out " \n \n " startxref ) ? ; // Write the PDF EOF out . write_all ( b" " ) ? ; Ok ( ( ) ) }
Write the in-memory PDF representation to disk
Write the in - memory PDF representation to disk
&mut self
writer
W