@@ -199,12 +199,12 @@ pub use self::object::{
199199 TypedDict , Writer ,
200200} ;
201201
202+ use self :: writers:: * ;
203+ use crate :: chunk:: WriteSettings ;
202204use std:: fmt:: { self , Debug , Formatter } ;
203205use std:: io:: Write ;
204206use std:: ops:: { Deref , DerefMut } ;
205207
206- use self :: writers:: * ;
207-
208208/// A builder for a PDF file.
209209///
210210/// This type constructs a PDF file in-memory. Aside from a few specific
@@ -227,6 +227,14 @@ impl Pdf {
227227 Self :: with_capacity ( 8 * 1024 )
228228 }
229229
230+ /// Create a new PDF with the given write settings.
231+ pub fn new_with ( write_settings : WriteSettings ) -> Self {
232+ let mut pdf = Self :: new ( ) ;
233+ pdf. write_settings = write_settings;
234+
235+ pdf
236+ }
237+
230238 /// Create a new PDF with the specified initial buffer capacity.
231239 pub fn with_capacity ( capacity : usize ) -> Self {
232240 let mut chunk = Chunk :: with_capacity ( capacity) ;
@@ -412,11 +420,11 @@ mod tests {
412420 }
413421
414422 /// Return the slice of bytes written during the execution of `f`.
415- pub fn slice < F > ( f : F ) -> Vec < u8 >
423+ pub fn slice < F > ( f : F , write_settings : WriteSettings ) -> Vec < u8 >
416424 where
417425 F : FnOnce ( & mut Pdf ) ,
418426 {
419- let mut w = Pdf :: new ( ) ;
427+ let mut w = Pdf :: new_with ( write_settings ) ;
420428 let start = w. len ( ) ;
421429 f ( & mut w) ;
422430 let end = w. len ( ) ;
@@ -425,12 +433,16 @@ mod tests {
425433 }
426434
427435 /// Return the slice of bytes written for an object.
428- pub fn slice_obj < F > ( f : F ) -> Vec < u8 >
436+ pub fn slice_obj < F > ( f : F , write_settings : WriteSettings ) -> Vec < u8 >
429437 where
430438 F : FnOnce ( Obj < ' _ > ) ,
431439 {
432- let buf = slice ( |w| f ( w. indirect ( Ref :: new ( 1 ) ) ) ) ;
433- buf[ 8 ..buf. len ( ) - 9 ] . to_vec ( )
440+ let buf = slice ( |w| f ( w. indirect ( Ref :: new ( 1 ) ) ) , write_settings) ;
441+ if write_settings. pretty {
442+ buf[ 8 ..buf. len ( ) - 9 ] . to_vec ( )
443+ } else {
444+ buf[ 8 ..buf. len ( ) - 8 ] . to_vec ( )
445+ }
434446 }
435447
436448 #[ test]
0 commit comments