Free Support Forum - aspose.com

Pdf printing automatic vertical or horizontal

Hi

NoData.pdf (57.1 KB) document printing with sample code. Document is horizontal but is printing vertically. How to make automatic vertical or horizontal selection.Because Adobe Reader can do it automatically.

Code:

FileStream fs = new FileStream(_filePath, System.IO.FileMode.Open);
Byte[] buffer = new Byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);

            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(fs);
            int copies = 1;
            if (_metod.GetParameterValue(265) == "E")
                copies = _nusha;
            QDMSGlobal.AsposeLicence.SetAsposeLicence();
            Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
            viewer.BindPdf(doc);
            var prtdoc = new PrintDocument();
            System.Drawing.Printing.PrinterSettings printerSetttings = new System.Drawing.Printing.PrinterSettings();
            printerSetttings.Copies = Convert.ToInt16(copies);
            printerSetttings.PrinterName = prtdoc.PrinterSettings.PrinterName;
            printerSetttings.PrintToFile = true;
           
            viewer.UseIntermidiateImage = true;
            viewer.PrintPageDialog = false;
            viewer.PrintDocumentWithSettings(printerSetttings);
            viewer.Close();

@srmbimser

Thank you for contacting support.

We would like to share with you that you can set auto rotation of a file to true or false by setting AutoRotate property, as in the line of code below:

//Do not print the file with adjusted rotation
viewer.AutoRotate = false;

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Hi

The problem has not improved. I added printed pageserror.jpeg (131.2 KB)

@srmbimser

Thank you for elaborating it further.

It appears to be a problem with resizing of contents, please set AutoResize property, as in the line of code below, in combination with setting AutoRotate property.

//print the file with adjusted size
viewer.AutoResize = true;

We hope this will be helpful. Please share your kind feedback with us after testing suggested changes in your environment.

Hi,

We have added the following code. But the result has not changed.
Thanks

            Aspose.Pdf.Document doc = new Aspose.Pdf.Document(fs);
            int copies = 1;
            if (_metod.GetParameterValue(265) == "E")
                copies = _nusha;
            AsposeLicence.SetAsposeLicence();
            Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
            viewer.BindPdf(doc);
            var prtdoc = new PrintDocument();
            System.Drawing.Printing.PrinterSettings printerSetttings = new 
            System.Drawing.Printing.PrinterSettings();
            printerSetttings.Copies = Convert.ToInt16(copies);
            printerSetttings.PrinterName = prtdoc.PrinterSettings.PrinterName;
            printerSetttings.PrintToFile = true;
            viewer.UseIntermidiateImage = true;
            viewer.PrintPageDialog = false;


            viewer.AutoResize = false;
            viewer.AutoRotate = true;   


            viewer.PrintDocumentWithSettings(printerSetttings);
            viewer.Close();
        viewer.AutoResize = true;
        viewer.AutoRotate = false;   

We tested in the above case.

@srmbimser

We have updated the code snippet and UseIntermidiateImage property is now set to false. The file is printed fine. Please try using below code in your environment and then share your kind feedback with us.

        Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "NoData.pdf");
        int copies = 1;
        if (_metod.GetParameterValue(265) == "E")
            copies = _nusha;
        AsposeLicence.SetAsposeLicence();
        Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
        viewer.BindPdf(doc);
        var prtdoc = new System.Drawing.Printing.PrintDocument();
        System.Drawing.Printing.PrinterSettings printerSetttings = new System.Drawing.Printing.PrinterSettings();
        printerSetttings.Copies = Convert.ToInt16(copies);
        printerSetttings.PrinterName = prtdoc.PrinterSettings.PrinterName;
        printerSetttings.PrintToFile = true;
        viewer.UseIntermidiateImage = false;
        viewer.PrintPageDialog = false;
        viewer.AutoResize = true;
        viewer.AutoRotate = false;
        viewer.PrintDocumentWithSettings(printerSetttings);
        viewer.Close();

Our original word file is landscape orientation . when we convert it pdf with Aspose pdf Pdf file again has landscape orientation.So Pdf file is correct. but when we send it printer with Aspose printer settings(without print dialog) output file is become Portait Orientation

CAPTURE.jpg (83.8 KB)

@srmbimser

We are glad to notice that page contents are not cropped incorrectly anymore. However, we have modified the code snippet to keep the page orientation as Landscape. Please try using below code snippet in your environment and then share your kind feedback with us.

    Aspose.Pdf.Document doc = new Aspose.Pdf.Document(dataDir + "NoData.pdf");
    int copies = 1;
        if (_metod.GetParameterValue(265) == "E")
            copies = _nusha;
        AsposeLicence.SetAsposeLicence();
    Aspose.Pdf.Facades.PdfViewer viewer = new Aspose.Pdf.Facades.PdfViewer();
    viewer.BindPdf(doc);
    var prtdoc = new System.Drawing.Printing.PrintDocument();
    System.Drawing.Printing.PrinterSettings printerSetttings = new System.Drawing.Printing.PrinterSettings();
    System.Drawing.Printing.PageSettings pageSettings = new System.Drawing.Printing.PageSettings();
    pageSettings.Landscape = true;
    //set PageMargins
    pageSettings.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

    printerSetttings.Copies = Convert.ToInt16(copies);
    printerSetttings.PrinterName = prtdoc.PrinterSettings.PrinterName;
    printerSetttings.PrintToFile = true;
    viewer.UseIntermidiateImage = false;
    viewer.PrintPageDialog = false;
    viewer.AutoResize = true;
    viewer.AutoRotate = false;
    viewer.PrintDocumentWithSettings(pageSettings, printerSetttings);
    viewer.Close();

In case this does not satisfy your requirements, please share a PDF file as expected output so that we may investigate further to help you out.

Hi, For this example our file result is correct but we don’t know if file is Landscape Orientation or Portrait Orientation. You can set orientation directly when you convert word file to pdf file. But when you send this pdf file to printer(without print dialog) pdf file orientation only became Lanscape or Portrait. if Pdf file has Landscape Orientation we want to print Landscape Orientation ,if Pdf file has Portrait Orientation we want to print Portrait Orientation. But we dont know if it is Landscape or Portrait. Only we want to protect file’s orientation

Hi,
Is an improvement present?

Thanks

@srmbimser

We would like to share with you that we can check orientation of page in source file, before specifying it for the output file, as in the code snippet below. But the property, IsLandscape is not working as expected. Therefore, a ticket with ID PDFNET-44619 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

if (doc.PageInfo.IsLandscape)
{
    pageSettings.Landscape = true;
}

We are sorry for the inconvenience.

Our pdf file has more than one page. One page is Landscape and the other one is Portrait. How can we print all pages correctly

@srmbimser

Please share a sample PDF file with us, so that we may investigate and guide you accordingly.

Hi

atik_yonetim_plani.pdf (106.7 KB) is sample PDF

@srmbimser

Thank you for sharing requested data.

We have updated the sample PDF file in respective ticket. We will share our findings with you as soon as the ticket will be investigated in our environment. Please be patient and spare us little time.