Problems with creating PDF file

With the following code I create a PDF document from a grouping control.
For orientation I have set Landscape.
Without header and footer this works.
If I want to work with header (pdfConverter.ShowHeader = true;) only portrait is created and the rest is cut off.
Also, the first page is an empty page (with header). Also between the pages one or more empty pages (with header only) are created.

What can I do?

Translated with www.DeepL.com/Translator (free version)

Here my code:

private static string Caption = string.Empty;
        private static string formName = string.Empty;
        private static GridPDFConverter pdfConverter = null;

        public static void ReportToPDF(GridControlBase grdAnzeige, Form form, string caption, bool landscape = false)
        {
            Caption = caption;
            formName = form.Name;

            SaveFileDialog dlgSave = new SaveFileDialog();

            dlgSave.Filter = "PDF-Dokumente|*.pdf";
            dlgSave.AddExtension = true;
            dlgSave.DefaultExt = ".pdf"; // Default file extension
            dlgSave.Title = "Speichern als PDF-Datei";
            dlgSave.FileName = "Untitled";

            form.Invalidate();
            Application.DoEvents();

            if (dlgSave.ShowDialog() != DialogResult.Cancel)
            {
                form.Cursor = Cursors.WaitCursor;

                pdfConverter = new GridPDFConverter();
                PdfDocument pdfdoc = new PdfDocument();
                PdfLayoutFormat format = new PdfLayoutFormat();

                if (landscape)
                    pdfdoc.PageSettings.Orientation = PdfPageOrientation.Landscape;
                else
                    pdfdoc.PageSettings.Orientation = PdfPageOrientation.Portrait;

                pdfConverter.Exporting += new GridPDFConverter.PDFExportingEventHandler(pdfConverter_Exporting);
                pdfConverter.DrawPDFHeader += new GridPDFConverter.DrawPDFHeaderFooterEventHandler(pdfConverter_DrawPDFHeader);
                pdfConverter.DrawPDFFooter += new GridPDFConverter.DrawPDFHeaderFooterEventHandler(pdfConverter_DrawPDFFooter);

                //pdfConverter.ShowFooter = true;
                pdfConverter.ShowHeader = true;
                format.Layout = PdfLayoutType.OnePage;

                pdfConverter.ExportToPdf(dlgSave.FileName, grdAnzeige);

                System.Diagnostics.Process.Start(dlgSave.FileName);                //Launching the PDF file using the default Application.[Acrobat Reader]

                pdfConverter.Exporting -= new GridPDFConverter.PDFExportingEventHandler(pdfConverter_Exporting);
                pdfConverter.DrawPDFHeader -= new GridPDFConverter.DrawPDFHeaderFooterEventHandler(pdfConverter_DrawPDFHeader);
                pdfConverter.DrawPDFFooter -= new GridPDFConverter.DrawPDFHeaderFooterEventHandler(pdfConverter_DrawPDFFooter);
            }
        }

        private static void pdfConverter_Exporting(object sender, PDFExportingEventArgs e)
        {
            if (e.PdfDocument.PageSettings.Orientation == PdfPageOrientation.Landscape)
                e.PdfDocument.PageSettings.Width = 870;
            //else
            //    e.PdfDocument.PageSettings.Width = 700;
        }

        //create the pdf header
        private static void pdfConverter_DrawPDFHeader(object sender, PDFHeaderFooterEventArgs e)
        {
            PdfPageTemplateElement header = e.HeaderFooterTemplate;

            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 24);
            float doubleHeight = font.Height * 2;
            Color activeColor = Color.FromArgb(44, 71, 120);
            SizeF imageSize = new SizeF(110f, 35f);

            PdfSolidBrush brush = new PdfSolidBrush(activeColor);

            PdfPen pen = new PdfPen(Color.Black, 3f);
            font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold);

            //Set formattings for the text
            PdfStringFormat format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Middle;

            //Draw title
            header.Graphics.DrawString(Caption, font, brush, new RectangleF(0, 0, header.Width, header.Height), format);
            brush = new PdfSolidBrush(Color.Gray);
            font = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold);

            format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Left;
            format.LineAlignment = PdfVerticalAlignment.Bottom;

            //Draw some lines in the header
            pen = new PdfPen(Color.Black, 0.7f);
            header.Graphics.DrawLine(pen, 0, 0, header.Width, 0);
            pen = new PdfPen(Color.Black, 2f);
            header.Graphics.DrawLine(pen, 0, 03, header.Width + 3, 03);
            pen = new PdfPen(Color.Black, 2f);
            header.Graphics.DrawLine(pen, 0, header.Height - 3, header.Width, header.Height - 3);
            header.Graphics.DrawLine(pen, 0, header.Height, header.Width, header.Height);
        }

        private static void pdfConverter_DrawPDFFooter(object sender, PDFHeaderFooterEventArgs e)
        {
            PdfPageTemplateElement footer = e.HeaderFooterTemplate;
            PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 18, PdfFontStyle.Bold);
            PdfStringFormat format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Center;
            format.LineAlignment = PdfVerticalAlignment.Bottom;
            footer.Graphics.DrawString(DateTime.Now.ToShortDateString(), font, brush, new RectangleF(40, footer.Height - 20, footer.Width, footer.Height), format);

            format = new PdfStringFormat();
            format.Alignment = PdfTextAlignment.Right;
            format.LineAlignment = PdfVerticalAlignment.Bottom;

            //Create page number field
            PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush);

            //Create page count field
            PdfPageCountField count = new PdfPageCountField(font, brush);

            string page = Localization.GetTranslation(formName, "Seite");
            string from = Localization.GetTranslation(formName, "von");
            string temp = string.Format("{0} {1} {2} {3}", page, pageNumber, from, count);
            PdfCompositeField compositeField = new PdfCompositeField(font, brush, temp);

            compositeField.Bounds = footer.Bounds;
            compositeField.Draw(footer.Graphics, new PointF(400, footer.Height - 20));
        }

9 Replies 1 reply marked as answer

SL Sowmiya Loganathan Syncfusion Team June 22, 2020 12:24 PM UTC

Hi Bernhard,  

Thank you for contacting Syncfusion support.  

Currently we are working on this and will update the further details on June 23, 2020.  

Regards, 
Sowmiya Loganathan 



AR Arulpriya Ramalingam Syncfusion Team June 24, 2020 02:35 AM UTC

Hi Bernhard, 
 
Sorry for the inconvenience. 
 
We have forwarded the query to our development team and our team is work on this with high priority. We will update you with proper details on 25th June 2020 and appreciate your patience till then. 
 
Regards, 
Arulpriya 



AR Arulpriya Ramalingam Syncfusion Team June 26, 2020 01:27 AM UTC

Hi Bernhard, 
 
Thank you for your patience. 
 
We have tested the reported case that the pdf document have extra blank pages when it has ShowHeader as true and the documents are exported properly without adding any pages. So, we suspect that the issue might be occurred due to some other settings of GridGroupingControl or the product version. So, please refer to the below sample and let us know, if we missed anything from the sample to reproduce the issue. If the below sample reproduces the issue at your end, please confirm your product version which will be helpful for us to assist you further. 
 
 
Regards, 
Arulpriya 



BH Bernhard Höhn June 28, 2020 03:08 PM UTC

Hello,

i have updated to version 18.1460.0.52, but i have the same problem here too.
I made a small test project with the corresponding data.
I have attached this as a zip-file, as well as the generated PDF-file.

Attachment: TestPDF_8c31284f.zip


AR Arulpriya Ramalingam Syncfusion Team June 29, 2020 05:31 PM UTC

Hi Bernhard, 
 
Thank you for the update. 
 
We could reproduce the issue that the GridGroupingControl adds additional empty pages when exporting it to pdf at our end and forwarded the query to our development team for further validation and update you with proper details on 01st July 2020. We appreciate your patience till then. 
 
Regards, 
Arulpriya 



AR Arulpriya Ramalingam Syncfusion Team July 1, 2020 05:17 PM UTC

Hi Bernhard, 
 
Sorry for the inconvenience. 
 
The reported issue is reproduced in the provided sample alone and not in a simple sample. So, we are validating with properties and setting of grid which causes the issue at our end with high priority and we need some more time to validate further and update you with further details on 03rd July 2020. 
 
We appreciate your patience till then. 
 
Regards, 
Arulpriya 



AR Arulpriya Ramalingam Syncfusion Team July 6, 2020 03:14 AM UTC

Hi Bernhard, 
 
Thank you for your patience. 
 
We have analyzed the sample completely and the reported scenario that the new page is added in pdf document is occurred due to the column width of the parent columns are updated with some higher value than the width of GridGroupingControl. In pdf document, the columns widths are updated based on the grid’s column width. In order to overcome this use case, we would suggest that you to set the column width for parent table with some lower values. We have modified the samples as per your requirement and please make use of the modified sample. 
 
 
Please get back to us, if you need any further assistance. 
 
Regards, 
Arulpriya 


Marked as answer

BH Bernhard Höhn July 7, 2020 11:55 AM UTC

Hello,

it works.
Thank you

Kind regards
Bernhard Höhn


AR Arulpriya Ramalingam Syncfusion Team July 8, 2020 05:23 AM UTC

Hi Bernhard, 
 
Thank you for the update. 
 
We are glad that the reported scenario with extra page added while exporting the grid to pdf is resolved at your end with the solution. 
 
Please get back to us, if you need any further assistance. 
 
Regards, 
Arulpriya 


Loader.
Up arrow icon