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.

Mon Aug 09, 2021 1:25 pm

We have an application which we have changed to use Spire.pdf for wcf C# and it is working great.
But when we have a document which is normally in landscape mode and we add a page to the start of the document, it has been reported that it is printing out in portrait mode.

What is the correct way to load an existing pdf into a new instance of the document for manipulation following code has been extracted from the program;
Code: Select all
 PdfDocument documentDrawing = new PdfDocument();
 PdfDocument origionalDrawing = new PdfDocument();
 origionalDrawing.LoadFromFile(Properties.Settings.Default.WOPrintDrawings + PartNo + ".pdf");
 PdfPageBase documentDrawingPage = documentDrawing.Pages.Insert(1, origionalDrawing.Pages[0].Size);
 documentDrawing.InsertPage(origionalDrawing, 0);
 documentWorksOrder.InsertPage(origionalWorksOrder, 0);
 PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
 PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
 PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 13f);
 PdfGraphicsState state = documentDrawingPage.Canvas.Save();
 string datastring = @"Stock No : " + PartNo + @" Account No : " + AccountNo + @" Works Order No : " + WOrderNo;
 SizeF size = font.MeasureString(datastring, format);
 documentDrawingPage.Canvas.DrawString(Properties.Settings.Default.WOrderSpindleDrawing, font, brush, 55, 0, format);
 documentDrawingPage.Canvas.DrawString(datastring, font, brush, 55, 20, format);
 documentDrawingPage.Canvas.Restore(state);
 documentDrawing.SaveToFile(Properties.Settings.Default.WOWorkingFolder + out2);


Thanks in advance

alntechnology
 
Posts: 4
Joined: Fri Jul 09, 2021 3:56 pm

Tue Aug 10, 2021 9:22 am

Hello,

Thank you for your inquiry.
I simulated a PDF file and tested it with your code, but didn't found your issue. The version I used is the latest version(Spire.PDF Pack(Hot Fix) Version:7.8.2). If you were not using the latest version, please first give it a try. If the issue still exists after trying, please provide your PDF sample file as well as your resultant PDF for further investigation. You could attach them here or send to us via email ([email protected]). Thanks in advance.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Tue Aug 10, 2021 3:55 pm

WE use the free version of the spire.pdf-FE document program which is showing as 7.2 in the systems add/remove programs

alntechnology
 
Posts: 4
Joined: Fri Jul 09, 2021 3:56 pm

Wed Aug 11, 2021 10:01 am

Hello,

Thanks for your feedback.
I tested again with the Free Spire.PDF for .NET Version:7.2, but still didn't find any issue. Here I uploaded my testing demo including my input and output files for your reference. If there is any difference, please feel free to write back.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Aug 12, 2021 9:16 am

Thanks for the update.

Have had some feed back from the end user and they what to see the inserted blank page in portrait mode and the original document in its original mode which is landscape.

have been checking out the Insert page method I am using but cannot figure out what need to change on it, need to insert an A4 portrait page as the first page.

alntechnology
 
Posts: 4
Joined: Fri Jul 09, 2021 3:56 pm

Thu Aug 12, 2021 9:58 am

Hi,

Thank you for your clarification.
I understand your meaning now. Please correct your code as below to insert a A4 page in portrait mode.
Code: Select all
...
//the default page size is A4, orientation is portrait
PdfPageBase documentDrawingPage = documentDrawing.Pages.Insert(1);
documentDrawing.InsertPage(origionalDrawing, 0)
...

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Thu Aug 12, 2021 12:46 pm

thanks, that work

alntechnology
 
Posts: 4
Joined: Fri Jul 09, 2021 3:56 pm

Fri Aug 13, 2021 5:43 am

Hi,

You're welcome.
If you have other questions about using Spire.PDF in the future, please feel free to contact us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.PDF