Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Mar 28, 2014 7:06 am

Hello,

I want to add header and footer in existing pdf document in c#. Header contains logo, some text and Hyperlink, but while I am adding it using code given in example, I found one issue. Header is overlapped on Content of the Page.

My Requirement is while user upload any PDF file in Web Application then we need to add header, footer and watermark in PDF file which is uploaded by User.

Can you please suggest me how can I achieve this functionality using Spire.Doc.

Thanks,

Jignesh Chauhan

tatvasoft
 
Posts: 9
Joined: Tue Mar 25, 2014 9:56 am

Fri Mar 28, 2014 9:02 am

Hello,

Thanks for your inquiry.
If the content of the header you want to add is bigger than the top white space of the existing Pdf, it will cover the content. Do you want to scroll down content of the PDF as the header or the header is under the content of the PDF. If convenient, could you please provide us your files?
Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Mar 28, 2014 9:32 am

Dear Gray Zhang

Thanks for reply.

Yes In case of White space of the PDF document is less than header height than I want to scroll down content. After scrolling content if Content is not fit in same then we also want to move remaining content to next page.

Thanks,

Jignesh Chauhan

tatvasoft
 
Posts: 9
Joined: Tue Mar 25, 2014 9:56 am

Fri Mar 28, 2014 9:52 am

Hello,

Thanks for your quick reply.
There is a demo for your reference, which is provided for other customer who has the same issue with you. If there is still issue, you could provide us your files, and we provide you the correct demo.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Mar 28, 2014 11:06 am

Dear Gray Zhang

Thanks for sharing code.

I gone through demo provided by you, and it is working as What I want, but still having one issue in it. Why it is not retain same margin (Left and Right) in newly generated file as per my original document. and also top margin is too much. Please find attached image file in which I describe the Original file, newly generated file and what is my expectation.

Please suggest.

Thanks,

Jignesh Chauhan

tatvasoft
 
Posts: 9
Joined: Tue Mar 25, 2014 9:56 am

Mon Mar 31, 2014 5:17 am

Hello,

Can any one please help me regarding my above query.

Please reply ASAP.

Thanks,

Jignesh Chauhan

tatvasoft
 
Posts: 9
Joined: Tue Mar 25, 2014 9:56 am

Mon Mar 31, 2014 5:57 am

Hello,

Sorry for that as weekend. We are working on the issue now, once there is any update, we will let you know immediately.

Regards,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Apr 01, 2014 6:50 am

Hello,

Sorry for inconvenience. You need to adjust the position, and there are some code for your reference.
Code: Select all
class Program
    {
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.PageSettings.Margins.All = 0;

            SetDocumentTemplate(doc, PdfPageSize.A4, 40);

            PdfDocument original = new PdfDocument();

            original.LoadFromFile(@"..\..\Sample.pdf");

            PdfPageBase page = null;

            foreach (PdfPageBase origianlPage in original.Pages)
            {
                page = doc.Pages.Add(new SizeF(origianlPage.Size.Width, origianlPage.Size.Height + 40));//add the TopSpace height
                origianlPage.CreateTemplate().Draw(page, 0, 0);

            }
            doc.PageSettings.Margins.Top = 40;
            doc.PageSettings.Margins.Left = 90;
            doc.SaveToFile("output.pdf");
            System.Diagnostics.Process.Start("output.pdf");
        }
        private static void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, float height)//height, is the topSpace height depends on the added content
        {
            PdfPageTemplateElement topSpace = new PdfPageTemplateElement(pageSize.Width, height);
            topSpace.Foreground = true;
            doc.Template.Top = topSpace;

            //draw header label
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 20f));
            String label = "This is header for test";
            SizeF size1 = font1.MeasureString(label);
            float x = 0;
            float y = 0;
            topSpace.Graphics.DrawString(label, font1, PdfBrushes.PaleVioletRed, x, y);

            label = "Hello Word";
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f));
            y = y + size1.Height;
            topSpace.Graphics.DrawString(label, font2, PdfBrushes.Blue, x, y);
        }


    }

If there are any questions, welcome to get it back to us.
Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Apr 01, 2014 7:25 am

Hello,

Thanks for the sharing code. I check it and it looks good as per previously. I need to know two more things regarding PDF.

1. How to read content of PDF and display in Editor as same format as in PDF. (I think for that we need to convert PDF to HTML) so is it possible using Spire.PDF?

2. Adding watermark text in document.

Please reply ASAP.

Thanks,

Jignesh Chauahan

tatvasoft
 
Posts: 9
Joined: Tue Mar 25, 2014 9:56 am

Tue Apr 01, 2014 8:22 am

Hello,

Thanks for your quick reply.
1. How to read content of PDF and display in Editor as same format as in PDF. (I think for that we need to convert PDF to HTML) so is it possible using Spire.PDF?

Sorry that our product doesn't support the feature at present.
2. Adding watermark text in document.

Code: Select all
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"..\..\Sample.pdf");
PdfPageBase page = doc.Pages[0];
PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
brush.Graphics.SetTransparency(0.3f);
brush.Graphics.Save();
brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
brush.Graphics.RotateTransform(-45);
brush.Graphics.DrawString("Spire.Pdf Demo", new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
brush.Graphics.Restore();
brush.Graphics.SetTransparency(1);
page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
doc.SaveToFile("TextWaterMark.pdf"); 

If there are any questisons, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Apr 04, 2014 9:42 am

Hi,
Have you tried the code to add watermark text in document ? How did it work?
Thanks for your feedback.

Best regards,
Lisa
E-iceblue support team
User avatar

lisa.chen
 
Posts: 21
Joined: Thu Mar 20, 2014 2:31 am

Mon Apr 07, 2014 4:40 am

Hello lisa,

I tried with sample code for adding watermark in PDF, It works perfectly, But need some more time to check with different scenario.

And also is there any way to get the content of PDF file along with same layout and display in web application (Editor)?

Thanks,

Jignesh Chauhan

tatvasoft
 
Posts: 9
Joined: Tue Mar 25, 2014 9:56 am

Mon Apr 07, 2014 5:41 am

Hello,

Thanks for the reply.
Don't make sure what you need, but there is Spire.PdfViewer product you can try, which is a totally independent .NET library which designed for viewing PDF files from .NET application.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Tue Apr 08, 2014 8:01 am

Hello,

I have one more requirement regarding PDF Document. Before saving Pdf document I want to replace all email addresses & Phone Numbers (In specific format) in Pdf document with xxxxx. How can I do this using Spire.Pdf.

Please let me know using Spire.Pdf I can able to do this. Also please provide some sample code for the same

Thanks,

Jignesh Chauhan

tatvasoft
 
Posts: 9
Joined: Tue Mar 25, 2014 9:56 am

Tue Apr 08, 2014 8:45 am

Hello,

Thanks for your inquiry.
Could you please provide us a template pdf document for testing if convenience?

Thanks,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.PDF