Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I have creaed a pdf form to print to a check using web application.The form prints correctly on an A4 sise paper.But while printing the form to a cheque of 20*10cm (width*height) the full alignment changes.I have set the papersize but while printing the papersize changes.
Can anyone help me please.Any help will really appreciated.Thanks in advance

What I have tried:

PdfDocument pdf = new PdfDocument();
               PdfPage pdfPage = pdf.AddPage();

               pdfPage.TrimMargins.Top = 0;
               pdfPage.TrimMargins.Right = 0;
               pdfPage.TrimMargins.Bottom = 0;
               pdfPage.TrimMargins.Left = 0;
               pdfPage.Width = XUnit.FromInch(8);
               pdfPage.Height= XUnit.FromInch(4);
               pdfPage.Orientation = PageOrientation.Portrait;
               XGraphics graph = XGraphics.FromPdfPage(pdfPage);
               XFont font = new XFont("Verdana", 10, XFontStyle.Regular);

               graph.DrawString(date1, font, XBrushes.Black,
               new XRect(6.259843 * 72, 0.590551 * 72, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

               graph.DrawString(provider, font, XBrushes.Black,
               new XRect(1.69291 * 72, 1.22047 * 72, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

               graph.DrawString("***" + premium + "***", font, XBrushes.Black,
              new XRect(6.181102 * 72, 2.08661 * 72, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

               if (countSpaces >= 9)
               {
                   var firstSpaceIndex = PremiumInWords.IndexOf(" ", PremiumInWords.IndexOf(" ", PremiumInWords.IndexOf(" ", PremiumInWords.IndexOf(" ", PremiumInWords.IndexOf(" ", PremiumInWords.IndexOf(" ", PremiumInWords.IndexOf(" ", PremiumInWords.IndexOf(" ") + 1) + 1) + 1) + 1) + 1) + 1) + 1);
                   var firstString = PremiumInWords.Substring(0, firstSpaceIndex);
                   var secondString = PremiumInWords.Substring(firstSpaceIndex + 1);
                   graph.DrawString("***" + firstString, font, XBrushes.Black,
              new XRect(0.984252 * 72, 1.73228 * 72, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);
                   graph.DrawString(secondString + "***", font, XBrushes.Black,
             new XRect(0.590551 * 72, 2.16535 * 72, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);


               }
               else
               {

                   graph.DrawString("***" + PremiumInWords + "***", font, XBrushes.Black,
                  new XRect(0.984252 * 72, 1.73228 * 72, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft);

               }
               MemoryStream stream = new MemoryStream();
               pdf.Save(stream, false);
               Response.Clear();
               Response.ContentType = "application/pdf";
               Response.AddHeader("Content-Disposition", string.Format("inline;filename=Schedule-{0}.pdf", No));
               Response.BinaryWrite(stream.ToArray());
               Response.Flush();
               stream.Close();
                Response.End();

           }
Posted
Comments
Peter_in_2780 14-Nov-17 0:28am    
Isn't your 20x10 check a LANDSCAPE orientation, not PORTRAIT?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900