We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Create Pdf file with different left margins for its pages

Thread ID:

Created:

Updated:

Platform:

Replies:

123720 Apr 13,2016 07:32 PM Apr 14,2016 05:25 AM ASP.NET Web Forms 1
loading
Tags: PDF
Vanna Le
Asked On April 13, 2016 07:32 PM

Hi,

  I create a Pdf file that has the first page with left margin having image embedded so the wording content of the page needs to have certain left margin.  On the second page onward, the content then needs not to have that left margin any more.
When I create the file, for the first page, I need to do 2 drawing, one is the wording content of the page and the second drawing is to put the left margin image onto the page.  However, my left margin image gets cut off on the left and the text seems to be obscured possibly because of the margin.
  Any thoughts on how should I set the pages for my Pdf file so that I can have the first page with left margin image and the second page onward does not have left margin at all.

Here is how I create my Pdf file in vb.net:

Dim letterStr As String = "............."    'content of the file that spans few pages in the Pdf file

If Not String.IsNullOrEmpty(letterStr) Then
                Dim section As IWSection
                Dim letterDoc As WordDocument = Nothing
                Dim converter As New DocToPDFConverter()
                Dim pdfLetter As Syncfusion.Pdf.PdfDocument = New Syncfusion.Pdf.PdfDocument()
                pdfLetter.PageSettings.Margins.Top = -3
                pdfLetter.PageSettings.Margins.Left = 0
                letterDoc = New WordDocument()
                section = letterDoc.AddSection()
              
                letterDoc.XHTMLValidateOption = XHTMLValidationType.None
                section.Body.InsertXHTML(letterStr)              
                pdfLetter = converter.ConvertToPDF(letterDoc)

                If Not IsNothing(pdfLetter) Then
                         Dim dataPath As String = HttpContext.Current.Server.MapPath("~/App_Data/LetterHeader.pdf")        'THIS IS THE LETTER HEAD TEMPLATE THAT CREATES THE LEFT MARGIN IMAGE AND HEADER, FOOTER
                         Dim letterHeadFS As Stream = New FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read)
                         Dim letterHeadDoc As New Syncfusion.Pdf.Parsing.PdfLoadedDocument(letterHeadFS)

                         For i As Integer = 0 To pdfLetter.Pages.Count - 1
                                Dim section As PdfSection = doc.Sections.Add
                                If i = 0 Then
                                        section.PageSettings.Margins.Left = 70
                                Else
                                         section.PageSettings.Margins.Left = 0
                                 End If

                                  Dim page As Syncfusion.Pdf.PdfPage = doc.Pages.Add
                                  Dim g As PdfGraphics = page.Graphics
                                  Dim lpage As PdfPageBase = pdfLetter.Pages(i)
                                  Dim template As Syncfusion.Pdf.Graphics.PdfTemplate = lpage.CreateTemplate
                                  g.DrawPdfTemplate(template, PointF.Empty, page.GetClientSize)

                                  If i = 0 Then
                                         section.PageSettings.Margins.Left = -40                  
                                         lpage = letterHeadDoc.Pages(0)
                                         template = lpage.CreateTemplate
                                         g.DrawPdfTemplate(template, New PointF(-100, 0), page.GetClientSize)
                                  End If
                       End If
 End If

Thank you.

Vanna Le

Abirami Selvan [Syncfusion]
Replied On April 14, 2016 05:25 AM

Hi Vanna,
Thank you for contacting Syncfusion support.
We can set the different margins for first page and second page  using PdfSection class and we can draw the image outside bounds of the margin using PdfTemplate class.
 Please refer to the following code example to set different margins:

//Create a document

PdfDocument doc = new PdfDocument();

//Add the section

PdfSection section = doc.Sections.Add();

//Add the page to the section

PdfPage page = section.Pages.Add();

//set margin

section.PageSettings.Margins.Left = 40;


//Add different margin for another section

section = doc.Sections.Add();

//set margin
section.PageSettings.Margins.Left = 0;
Please refer to the following link to draw the contents(image , text) in outside of margins:
https://www.syncfusion.com/kb/3732/how-to-draw-the-header-and-footer-outside-the-bounds-of-the-margin
Please refer to the following sample link:
http://www.syncfusion.com/downloads/support/forum/123720/ze/PdfSample1280587424
Please try this and  let us know if you need any further assistance.
Regards,
Abirami.


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;