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.

Thu Nov 07, 2019 11:44 am

Hello every one...

I am using free spire.pdf...I converted my xps file to a pdf file which is being done fine...But then i want to have my pdf in A4 size..After loading pdf file and changing the size everything becomes soo small and does not seem A4 size....Is there any way to fix it?Thanksss in advance..

dfDocument newPdf = new PdfDocument();
PdfDocument spiredoc1 = new PdfDocument();
spiredoc1.LoadFromFile("spire.pdf",FileFormat.PDF);

foreach (PdfPageBase page in spiredoc1.Pages)
{
PdfPageBase newPage = newPdf.Pages.Add(PdfPageSize.A4, new PdfMargins(0), 0, PdfPageOrientation.Portrait);
PdfTextLayout loLayout = new PdfTextLayout();
loLayout.Layout = PdfLayoutType.OnePage;
page.CreateTemplate().Draw(newPage, new PointF(0, 0), loLayout);
}


newPdf.SaveToFile("spire1.pdf",FileFormat.PDF);

sobhgoli
 
Posts: 3
Joined: Thu Nov 07, 2019 9:27 am

Fri Nov 08, 2019 2:12 am

Hi,

Thanks for your inquiry.
I firstly suggest you try to use the latest Spire.PDF Pack(Hot Fix) Version:5.11.2 which has more improvements than old version.

If the issue still happens, please provide following information for further investigation.
1. The input and output files.
2. The desired result.
3. The OS and Region information, e.g. Win7 64bit, China/Chinese.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Fri Nov 15, 2019 9:58 am

Hii...
Thanks for yourreply...i changed the component to what you suggested...the problem is still there...The thing is that i want to convert my xps to pdf..But it must be in A4...Therefor,at first i convert my xps file to pdf and then i loaded that pdf and tried to change the format to A4...I am not sure if it is a correct way...

I am using win10/64 bit...And i will attach my xps file and final pdf files to this email


Thankss in advance



Spire.Pdf.PdfDocument spiredoc = new Spire.Pdf.PdfDocument();
spiredoc.LoadFromFile("temp" + ".xps",FileFormat.XPS);
spiredoc.SaveToFile("spire.pdf", FileFormat.PDF);
//System.Diagnostics.Process.Start("spire.pdf");
spiredoc.Close();
Spire.Pdf.PdfDocument newPdf = new Spire.Pdf.PdfDocument();
Spire.Pdf.PdfDocument spiredoc1 = new Spire.Pdf.PdfDocument();
spiredoc1.LoadFromFile("spire.pdf");

foreach (PdfPageBase page in spiredoc1.Pages)
{
PdfPageBase newPage = newPdf.Pages.Add(PdfPageSize.A4, new PdfMargins(0), 0, PdfPageOrientation.Portrait);
PdfTextLayout loLayout = new PdfTextLayout();
loLayout.Layout = PdfLayoutType.OnePage;
page.CreateTemplate().Draw(newPage, new PointF(0, 0), loLayout);
}


newPdf.SaveToFile("spire1.pdf",FileFormat.PDF);

sobhgoli
 
Posts: 3
Joined: Thu Nov 07, 2019 9:27 am

Fri Nov 15, 2019 11:26 am

Hi,

Thanks for your information.
There is no need to save to PDF firstly then reload PDF and change the size. You could directly change the size when converting XPS to PDF. Note the code "loLayout.Layout = PdfLayoutType.OnePage" could scale the content according to the size, the result you got is correct. But from your information, I think you want to just remove the white space without scaling, please refer to following code:
Code: Select all
            Spire.Pdf.PdfDocument spiredoc = new Spire.Pdf.PdfDocument();
            spiredoc.LoadFromFile(FilePath + "temp19513.xps", FileFormat.XPS);

            PdfDocument newPdf = new PdfDocument();
            foreach (PdfPageBase page in spiredoc.Pages)
            {
                PdfPageBase newPage = newPdf.Pages.Add(PdfPageSize.A4, new PdfMargins(0), 0, PdfPageOrientation.Portrait);
                //PdfTextLayout loLayout = new PdfTextLayout();
                //loLayout.Layout = PdfLayoutType.OnePage;
                //page.CreateTemplate().Draw(newPage, new PointF(0, 0), loLayout);
                page.CreateTemplate().Draw(newPage, new PointF(0, 0));
            }

            newPdf.SaveToFile("T19513.pdf", FileFormat.PDF);


Attached is my result file for checking. If there is not what you want, please share your desired file.

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Fri Nov 15, 2019 11:41 am

Thankss so much..Yeah..your code solved my problem...
My last question is that is it possible to not load xps content from a file?I have FlowDocReader in wpf..I want to get the content from it which can be xps...

Thanksss in advance


MemoryStream lMemoryStream = new MemoryStream();
Package package = Package.Open(lMemoryStream, FileMode.Create);
XpsDocument doc = new XpsDocument(package);
System.Windows.Xps.XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
DocumentPaginator paginator = ((IDocumentPaginatorSource)(FlowDocReader.Document)).DocumentPaginator;
writer.Write(paginator);
//rsm.SaveAsXaml(paginator);
doc.Close();
package.Close();


I tried to use loadstream but it did not work...

spiredoc.LoadFromStream(lMemoryStream );

sobhgoli
 
Posts: 3
Joined: Thu Nov 07, 2019 9:27 am

Mon Nov 18, 2019 6:24 am

Hi,

Sorry for late reply as weekend.
Please use LoadFromXPS method.
Code: Select all
            spiredoc.LoadFromXPS(stream);


Sincerely,
Betsy
E-iceblue support team
User avatar

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

Tue Dec 10, 2019 7:17 am

Hi,

Greetings from E-iceblue.
Has your issue been resolved? Could you please give us some feedback at your convenience?

Sincerely,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.PDF