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 Jul 17, 2015 7:38 am

First i am not good at english so there might be some mistake in my toic
And my post seem to be very simple, but i need your help.

i just use this program because of my lab subject.
i have to change html file to pdf file exactly same size.(there are some chart and picture and unit is millimeter)

i tried program and made test pdf file but they they were cut some part.
i think it's because page size is A4. how can i change page size? and how rotate page?(width is bigger than height )
And how can i save picture and chart exactly same size by millimeter

there is c# code i used.

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Pdf;
using System.Threading;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            String fromUrl = "C:/Users/Administrator/Desktop/html/test1.htm";
            String toPath = @"C:\Users\Administrator\Desktop\html\test.pdf";
           
            PdfDocument doc = new PdfDocument();

            Thread thread = new Thread(()
            =>
            {
                doc.LoadFromHTML(fromUrl, false, true, true);
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
            doc.SaveToFile(toPath);
            doc.Close();
        }
    }
}

bomboom
 
Posts: 15
Joined: Fri Jul 17, 2015 7:08 am

Fri Jul 17, 2015 10:08 am

Hello,

Thanks for your inquiry.
Here is the sample code for your reference.
Code: Select all
PdfDocument doc = new PdfDocument();
            PdfPageSettings page = new PdfPageSettings
            {
                Height = 1000, //set the page size height
                Width = 1000,  //set the page size width
                Rotate = PdfPageRotateAngle.RotateAngle90   //rotate page
            };
            String url = "http://www.e-iceblue.com";
            Thread thread = new Thread(() =>
            {
                doc.LoadFromHTML(url, false, true, true, page);
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();       
            doc.SaveToFile("result4.pdf");

Here is the tutorial about how to Extract Image From PDF in C#.
http://www.e-iceblue.com/Knowledgebase/Spire.PDF/Spire.PDF-Program-Guide/How-to-Extract-Image-From-PDF-in-C.html
Sorry that our product doesn't support extracting chart in pdf.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Jul 20, 2015 8:51 am

Hello,

Has your issue been resolved?
Thanks for your feedback.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Thu Jul 23, 2015 10:04 am

Ur code helps me alot
but i have more Q

1.can i rotate page by negative direction? when i rotate 90 or 270 then i can't print top side or left side of paper

2. i think your program default page size is A4. in your code i understand you resize page by pixel. can i resize page
by cm or mm?

help me more plz :!: :!:

bomboom
 
Posts: 15
Joined: Fri Jul 17, 2015 7:08 am

Fri Jul 24, 2015 2:41 am

Hello,

Thanks for your reply.
1)I think Rotating page by negative direction and positive direction have the same effect. For example, if you want to rotate 90 by negative direction, you can achieve this by using below code.
Code: Select all
Rotate=PdfPageRotateAngle.RotateAngle270

In addition, I recommend you to increase the size in the PdfPageSettings. Then you've got everything it contains.
If you still have issue, please offer us your sample file. It would be helpful to replicate the issue and work out the solution for you ASAP.
Please kindly note that firstly you need to compress it and upload.
2) You can resize page by cm or mm. Here is the code for your reference.
Code: Select all
    PdfDocument doc = new PdfDocument();
            Spire.Pdf.Graphics.PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfPageSettings page = new PdfPageSettings
            {
               Height= unitCvtr.ConvertUnits(40f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point),
               Width = unitCvtr.ConvertUnits(400f, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point),                                     
            };


Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Mon Jul 27, 2015 1:43 am

thanks for your help i think it's almost done

but i have one more problem in print pdf file

i have to print page same size but when i print pdf , it cut off edge side so i want to insert margin
so i tied using your sample code in 'PageSetup' but i couldn't

help me more plz :roll:

bomboom
 
Posts: 15
Joined: Fri Jul 17, 2015 7:08 am

Mon Jul 27, 2015 5:55 am

Hello,

Thanks for your reply.
Please try to use below setting.
Code: Select all
doc.PageScaling = PdfPrintPageScaling.FitSize;

Here is the full code.
Code: Select all
doc.LoadFromFile("result7.pdf");
            doc.PageScaling = PdfPrintPageScaling.FitSize;
            doc.PrintDocument.Print();

If you still have issue, please offer us your sample file. It would be helpful to replicate the issue and work out the solution for you ASAP.
Please kindly note that firstly you need to compress it and upload.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Tue Jul 28, 2015 3:03 am

i upload my sample file and description('read me' file)

help me plz

bomboom
 
Posts: 15
Joined: Fri Jul 17, 2015 7:08 am

Tue Jul 28, 2015 7:09 am

Hello,

Thanks for your information.
Please try the below code.
Code: Select all
PdfDocument doc = new PdfDocument();
            PdfPageSettings page = new PdfPageSettings
            {
                Orientation = PdfPageOrientation.Landscape,
            };
            String url = @"D:\testfile\html\help me\sample.htm";
            Thread thread = new Thread(() =>
            {
                doc.LoadFromHTML(url, false, true, true, page);
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
            doc.SaveToFile("result.pdf");
            doc.LoadFromFile("result.pdf");
            doc.PageScaling = PdfPrintPageScaling.FitSize;
            doc.PrintDocument.Print();

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Tue Jul 28, 2015 8:21 am

thanks for your reply
you recommend me 'doc.PageScaling = PdfPrintPageScaling.FitSize;'
it makes not to cut off picture but makes picture small
as i said i need exactly same size picture print so i said i want have margin in page setting,

I hate to bother you, but could you fix code to have margin in page?

bomboom
 
Posts: 15
Joined: Fri Jul 17, 2015 7:08 am

Wed Jul 29, 2015 6:53 am

Hello,

Thanks for your reply.
Here is the code about how to set margin in the your generated pdf file.
Code: Select all
  PdfDocument doc = new PdfDocument();
             doc.PageSettings.Margins.Left = 16;
             doc.PageSettings.Margins.Right = 16;
             doc.PageSettings.Margins.Top = 20;
             doc.PageSettings.Margins.Bottom= 20;
            PdfDocument original = new PdfDocument();
            original.LoadFromFile(@"D:\testfile\Pdf\Result.pdf");
            PdfPageBase page = null;
            foreach (PdfPageBase origianlPage in original.Pages)
            {
                page = doc.Pages.Add(new SizeF(origianlPage.Size.Width, origianlPage.Size.Height));
                origianlPage.CreateTemplate().Draw(page, 0, 0);
            }
            doc.SaveToFile("output1.pdf");


Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Fri Aug 07, 2015 6:21 am

thanks for your reply
i think all about page size problem is done but a problem comes up in table.
i want to fix width of table then pictures are projected from table.
but in pdf, pictures are cut off.
i upload my html code and result pdf. i want to make my pdf like 'table.jpg' in uploaded file.

bomboom
 
Posts: 15
Joined: Fri Jul 17, 2015 7:08 am

Fri Aug 07, 2015 7:20 am

Hello,

Thanks for your response.
Please use the new method in our website.
http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-with-New-Plugin.html
Note that you need to copy the folder "plugins" under the same folder of Spire.Pdf.dll.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Wed Aug 12, 2015 5:17 am

thanks for your kind reply and new method,
i think all problems are solved :)
if i get another problem, back again

bomboom
 
Posts: 15
Joined: Fri Jul 17, 2015 7:08 am

Wed Aug 12, 2015 6:17 am

Hello,

Please feel free to contact us, if you have any questions or needs. We are here for help.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.PDF

cron