PdfFileEditor.TryResizeContents

TryResizeContents(string, int[], ContentsResizeParameters, HttpResponse)

Resizes contents of pages in document. If page is shrinked blank margins are added around the page. Result is stored into HttpResponse object.

public bool TryResizeContents(string source, int[] pages, ContentsResizeParameters parameters, 
    HttpResponse response)
ParameterTypeDescription
sourceStringPath to source file.
pagesInt32[]Array of pages to be resized.
parametersContentsResizeParametersResize parameters.
responseHttpResponseHttpResponse object where result is saved.

Return Value

true if operation completed successfully; otherwise, false.

Remarks

The TryResizeContents method is like the ResizeContents method, except the TryResizeContents method does not throw an exception if the operation fails.

See Also


TryResizeContents(Stream, int[], ContentsResizeParameters, HttpResponse)

Resizes contents of pages in document. If page is shrinked blank margins are added around the page. Result is stored into HttpResponse object.

public bool TryResizeContents(Stream source, int[] pages, ContentsResizeParameters parameters, 
    HttpResponse response)
ParameterTypeDescription
sourceStreamStream of source file.
pagesInt32[]Array of pages to be resized.
parametersContentsResizeParametersResize parameters.
responseHttpResponseHttpResponse object where result is saved.

Return Value

true if operation completed successfully; otherwise, false.

Remarks

The TryResizeContents method is like the ResizeContents method, except the TryResizeContents method does not throw an exception if the operation fails.

See Also


TryResizeContents(Stream, Stream, int[], ContentsResizeParameters)

Resizes contents of pages of the document.

public bool TryResizeContents(Stream source, Stream destination, int[] pages, 
    ContentsResizeParameters parameters)
ParameterTypeDescription
sourceStreamStream with source document.
destinationStreamStream with the destination document.
pagesInt32[]Array of page indexes.
parametersContentsResizeParametersResize parameters.

Return Value

Returns true if success.

Remarks

The TryResizeContents method is like the ResizeContents method, except the TryResizeContents method does not throw an exception if the operation fails.

Examples

PdfFileEditor fileEditor = new PdfFileEditor();
Stream src = new Stream("input.pdf", FileMode.Open);
Stream dest = new Stream("output.pdf", FileMode.Create);
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
    //left margin = 10% of page width
    PdfFileEditor.ContentsResizeValue.Percents(10),
    //new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
    null,
    //right margin is 10% of page 
    PdfFileEditor.ContentsResizeValue.Percents(10),
    //top margin = 10% of height
    PdfFileEditor.ContentsResizeValue.Percents(10),
    //new contents height is calculated automatically (similar to width)
    null,
    //bottom margin is 10%
    PdfFileEditor.ContentsResizeValue.Percents(10)
       );
bool result = fileEditor.TryResizeContents(src, dest, new int[] { 1, 2, 3 }, parameters);
dest.Close();

See Also


TryResizeContents(Stream, Stream, int[], double, double)

Resizes contents of document pages. Shrinks contents of page and adds margins. New size of contents is specified in default space units.

public bool TryResizeContents(Stream source, Stream destination, int[] pages, double newWidth, 
    double newHeight)
ParameterTypeDescription
sourceStreamStream which contains source document.
destinationStreamStream where resultant document will be saved.
pagesInt32[]Array of page indexes. If null then all document pages will be processed.
newWidthDoubleNew width of page contents in default space units.
newHeightDoubleNew height of page contents in default space units.

Return Value

true if operation completed successfully; otherwise, false.

Remarks

The TryResizeContents method is like the ResizeContents method, except the TryResizeContents method does not throw an exception if the operation fails.

Examples

PdfFileEditor fileEditor = new PdfFileEditor();
Stream src = new Stream("input.pdf", FileMode.Open);
Stream dest = new Stream("output.pdf", FileMode.Create);
bool result = fileEditor.TryResizeContents(src, dest, 
//resize all pages of document
null, 
//new contents width = 200
200, 
//new contents height = 300
300);
// rest area of page will be empty

See Also


TryResizeContents(string, string, int[], ContentsResizeParameters)

Resizes contents of pages in document. If page is shrinked blank margins are added around the page.

public bool TryResizeContents(string source, string destination, int[] pages, 
    ContentsResizeParameters parameters)
ParameterTypeDescription
sourceStringSource document path.
destinationStringDestination document path.
pagesInt32[]Array of page indexes (page index starts from 1).
parametersContentsResizeParametersParameters of page resize.

Return Value

true if resize was successful.

Remarks

The TryResizeContents method is like the ResizeContents method, except the TryResizeContents method does not throw an exception if the operation fails.

Examples

PdfFileEditor fileEditor = new PdfFileEditor();
PdfFileEditor.ContentsResizeParameters parameters = new PdfFileEditor.ContentsResizeParameters(
    //left margin = 10% of page width
    PdfFileEditor.ContentsResizeValue.Percents(10),
    //new contents width calculated automatically as width - left margin - right margin (100% - 10% - 10% = 80%)
    null,
    //right margin is 10% of page 
    PdfFileEditor.ContentsResizeValue.Percents(10),
    //top margin = 10% of height
    PdfFileEditor.ContentsResizeValue.Percents(10),
    //new contents height is calculated automatically (similar to width)
    null,
    //bottom margin is 10%
    PdfFileEditor.ContentsResizeValue.Percents(10)
       );
bool result = fileEditor.TryResizeContents("input.pdf", "output.pdf", new int[] { 1, 2, 3}, parameters);

See Also