Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sun Feb 02, 2020 8:45 pm

Hello
I'm using spire.doc v8.1.10
I would like to do this :
In a A.docx, I draw a simple shape, say S0, a line.
In a B.docx, I want to put a clone of S0, say S1
It works fine, even with SaveTo B.docx as in SaveTo B.pdf

But My goal is to refine position and size of this cloned shape S1.
For example, S1.Width *= 5 executes correctly, is effective in docx, but not in PDF, where the line keeps the same width as S0

Furthermore, .Left et .Name are protected properties and I cannot read or modify them.

How can I know the Name of S0 (I have actually many shapes in A.docx and I wish to distinguish them by their names) ?
How can I modify Location of S1 in docx and pdf result ?
How can I modify Size of S1 in pdf result ?

my testing code that executes correctly, but does'nt set the desired size in PDF saving.
Code: Select all
            ShapeObject line1 = line.Clone() as ShapeObject;
            line1.Width *= 5;
            paragraph.ChildObjects.Add(line1);

danielhalte1
 
Posts: 23
Joined: Sat Dec 14, 2019 12:50 am

Mon Feb 03, 2020 8:04 am

Hi,

Thanks for your inquiry.
I have simulated your case with the latest Spire.Doc Pack(hot fix) Version:8.1.10. Here is my testing code:
Code: Select all
            Document DocA = new Document(FilePath + "20397 A.docx");
            Section section = DocA.Sections[0];
            Paragraph para = section.Paragraphs[0];
            ShapeObject line1 = para.ChildObjects[1] as ShapeObject;
            line1.Width *= 5;
            //Change the position of the line
            line1.HorizontalPosition = 50;
            line1.HorizontalOrigin = HorizontalOrigin.Page;
            line1.VerticalPosition = 60;
            line1.VerticalOrigin = VerticalOrigin.Page;
            Document DocB = new Document(FilePath + "20397 B.docx");
            Paragraph paragraph = DocB.Sections[0].Paragraphs[0];
            paragraph.ChildObjects.Add(line1.Clone());
            DocB.SaveToFile("20397.docx",FileFormat.Docx);
            DocB.SaveToFile("20397.pdf",FileFormat.PDF);

1) Do you set the title of shape in MS Word and the title is the Name you want? Could you please provide your input file and describe your issue in detail for further investigation.

2) Please refer to above code to change the location of S1 in Word and PDF file.

3) The size both in Word and PDF result is correct on my side. Please check the files in the attachment.

If you still have the issues, please share your input file, the code you were using and desired file for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Feb 03, 2020 9:16 am

Hello
Thank you for your reply
I have tried HorizontalPosition and it works for me, in docx and PDF.
My wish : that your API documentation be improved to explain us what is each exposed property/method for !

I have attached :
A.docx with one horizontal line
a screenshot to show you the properties of it (size and name)
B.docx with the resized clone of this line
B.pdf that shows that the resized line is not resized

the line.Name cannot be used in code but is visible in debugger spy, obviously tagged as protected

Code: Select all
    internal void DoTest1()
    {
      string inputFilename = Path.Combine(Application.StartupPath, "A.docx");
      Document inputDoc = new Document(inputFilename);
      string outputFilename = Path.Combine(Application.StartupPath, "B.docx");
      string outputPDF = Path.Combine(Application.StartupPath, "B.pdf");
      if (File.Exists(outputFilename))
      {
        File.Delete(outputFilename);
      }
      Document outputDoc = new Document();
      ShapeObject line = GetFirstShape(inputDoc.Sections[0].Paragraphs[0]);
      Debug.Print($"{line.Width}, {line.Height}");
      ShapeObject line1 = line.Clone() as ShapeObject;
      line1.Width *= 5;
      Debug.Print($"{line1.Width}, {line1.Height}");
      Section section = outputDoc.AddSection();
      Paragraph paragraph = section.AddParagraph();
      paragraph.Text = $"{DateTime.Now:HH:mm:ss}";
      paragraph.ChildObjects.Add(line1);
      outputDoc.SaveToFile(outputFilename, FileFormat.Docx);
      Process.Start(outputFilename);
      outputDoc.SaveToFile(outputPDF, FileFormat.PDF);
      Process.Start(outputPDF);
    }
    private ShapeObject GetFirstShape(Paragraph template)
    {
      foreach (var item in template.ChildObjects)
      {
        if (item is ShapeObject)
        {
          return item as ShapeObject;
        }
      }
      return null;
    }


danielhalte1
 
Posts: 23
Joined: Sat Dec 14, 2019 12:50 am

Mon Feb 03, 2020 9:54 am

Hi,

Thanks for your information.
Sorry for the inconvenience caused by the API documentation. We will add the explanation for the property HorizontalPosition and improve the documentation step by step.
As for line.Name property, I have noticed it is protected and posted it to our Dev team for publishing it.
As for the line size in PDF, with your document and code I reproduced the issue and logged it in our bug tracking system.
We will let you know the process of the two issues above. Apologize for the inconvenience caused.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Fri Feb 07, 2020 10:49 am

Hello
Other PDF formatting issues have been resolved by an alternative method that you suggested (see extract bellow), but not the resizing of a horizontal line shape.

Code: Select all
      ToPdfParameterList ps = new ToPdfParameterList();
      ps.UsePSCoversion = true;
      document.SaveToFile(outputPDFFilename, ps);


I hope that a next corrective version will be delivered to us soon
(don't forget access to the name of the shapes)

danielhalte1
 
Posts: 23
Joined: Sat Dec 14, 2019 12:50 am

Mon Feb 10, 2020 3:42 am

Hi,

Thanks for your information.
Yes, the PS method doesn't solve the line size issue in PDF. And our Dev team has fixed the part of this issue. We will let you know when the two issues( size issue and shape name issue) are fixed.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc

cron