Spire.PDFViewer is a powerful PDF Viewer component for .NET. It allows developers to load PDF document from stream, file and byte array.

Tue Oct 17, 2017 3:04 pm

Hi,

I'm evaluating Spire PDFViewer using the FreeSpire.PDFViewer component, in conjunction with SSRS Reporting. The FreeSpire.PDFViewer version is 2.4.35 (the latest available via NuGet).

SSRS is correctly rendering a PDF file, which I am able to view in a form that contains the FreeSpire.PDFViewer control. This PDF renders correctly on the screen.

When I add a printing function however, all that is printed is blank pages.

Is this expected behaviour?

Code:

Code: Select all
    public partial class PDFViewer : Form
    {
        private string _currentPDF = string.Empty;
        private PdfDocumentViewer _pdfViewer = null;

        public PDFViewer()
        {
            InitializeComponent();

            _pdfViewer = new PdfDocumentViewer();
            _pdfViewer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right;
            _pdfViewer.Dock = DockStyle.Fill;

            panPDFContainer.Controls.Add(_pdfViewer);

            this.FormClosing += PDFViewer_FormClosing;
        }

        private void PDFViewer_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!string.IsNullOrEmpty(_currentPDF))
            {
                if (File.Exists(_currentPDF))
                {
                    try
                    {
                        File.Delete(_currentPDF);
                    }
                    catch (Exception exception)
                    {
                    }
                }
            }
        }

        public void LoadPDF(string pdfPath, ReportSetting reportSettings)
        {
            _currentPDF = pdfPath;

            _pdfViewer.SetViewerMode(PdfViewerMode.Auto);
            _pdfViewer.LoadFromFile(pdfPath);

            SetPageAndPrinterSettings(reportSettings);
        }

        private void SetPageAndPrinterSettings(ReportSetting settings)
        {
            System.Drawing.Printing.PrinterSettings printSettings = new System.Drawing.Printing.PrinterSettings();

            IEnumerable<PaperSize> paperSizes = printSettings.PaperSizes.Cast<PaperSize>();
            PaperSize sizeA4 = null;

            if (paperSizes.Count<PaperSize>(size => size.Kind == PaperKind.A4) > 0)
            {
                sizeA4 = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.A4); // setting paper size to A4 size
            }
            else
            {
                // Do nothing for now...
            }

            if (string.IsNullOrEmpty(settings.PrinterName))
            {
                System.Drawing.Printing.PrinterSettings defaultPrinter = Utility.Utilities.GetDefaultPrinter();

                if (defaultPrinter != null)
                {
                    settings.PrinterName = defaultPrinter.PrinterName;
                }

                printSettings.PrinterName = settings.PrinterName;
            }

            printSettings.DefaultPageSettings.Landscape = settings.PrintOrientation == Business.Reporting.ReportDocument.Orientation.Landscape;
            printSettings.DefaultPageSettings.Color = settings.PrintInColor;

            if (sizeA4 != null)
            {
                printSettings.DefaultPageSettings.PaperSize = sizeA4;
            }

            printSettings.DefaultPageSettings.Margins = new Margins(settings.LeftMargin, settings.RightMargin, settings.TopMargin, settings.BottomMargin);

            PageSettings pageSettings = new PageSettings();
            pageSettings.PrinterSettings = printSettings;
            pageSettings.Landscape = settings.PrintOrientation == Reporting.ReportDocument.Orientation.Landscape;
            pageSettings.Color = settings.PrintInColor;
            pageSettings.PaperSize = sizeA4;
            pageSettings.Margins = new Margins(settings.LeftMargin, settings.RightMargin, settings.TopMargin, settings.BottomMargin);

            _pdfViewer.PrintDocument.PrinterSettings = printSettings;
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            PrintDocument printDoc = _pdfViewer.PrintDocument;
            printDoc.Print();
        }


NOTE: the ReportSetting class is a database class that allows the user to manipulate printers/trays for direct printing without preview.

VorTechS
 
Posts: 3
Joined: Tue Oct 17, 2017 2:56 pm

Wed Oct 18, 2017 2:27 am

Hello VorTechS,

Thnaks for your inquiry.
That should not be expected behaviour. I suggest you first trying the latest commercial version Spire.PDFViewer Pack(Hotfix) Version:2.12.34. If the issue still exists, please send your sample pdf file to us via email(support@e-iceblue.com).

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Oct 18, 2017 8:33 am

Jane,

Many thanks for the quick response.

I can confirm that the HotFix does indeed resolve the printing issue.

Will this fix therefore be replicated in the Free PDFViewer component?

The HotFix does however itself have a bug, images with transparent backgrounds are not rendered (or printed) correctly:

Invoice-LogoIssue.png


Regards.

VorTechS
 
Posts: 3
Joined: Tue Oct 17, 2017 2:56 pm

Wed Oct 18, 2017 9:20 am

Hi VorTechS,

Thanks for your feedback.
Kindly note that have no plan to update the free version and all the fixes and new features are implemented in commercial version.
Besides, could you send your sample pdf file to us(support@e-iceblue.com) so that our dev team can have a better investigation and solve the issue?
Looking forward to your reply.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Oct 18, 2017 10:35 am

Jane,

It's very much a shame that you do not plan to fix the free component of this issue, as it may have been of interest for me with future freeware projects.

As it happens, I was using the component (in conjunction with others) to solve a problem I had with SSRS and 'merging' copies of a report into a single file... which I have solved within SSRS itself, so I now no longer have a requirement to use the component.

I appreciate the support that you have given me however, so thank you.

VorTechS
 
Posts: 3
Joined: Tue Oct 17, 2017 2:56 pm

Thu Oct 19, 2017 1:42 am

Dear VorTechS,

Thanks for your feedback.
If there is any question while using our products in the future, please feel free to contact us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDFViewer