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.

Tue Oct 08, 2019 3:20 pm

I have an application where they scan from a copier and it saves it to file. The application then loops through that file and creates several splits into individual documents. The original PDF is in portrait. However, the new document gets switched to landscape and cuts off the bottom of the page.

In my last line of code here, the image saved is cut off. I use a particular area of this image and use an OCR to determine a document number. I've attached the original PDF as well as the new document (pdfToSave).

This only happens from one scanner, but I cannot figure out how to make it correct.

PdfDocument original = new PdfDocument();
PdfDocument pdfToSave = new PdfDocument();

//original.LoadFromFile(e.FullPath);
original.LoadFromFile(f.FullPath, FileFormat.PDF);
original.PageSettings.Orientation = PdfPageOrientation.Portrait;

//Log file received file and size
EventLog.WriteEntry(source , f.Name + " received, " + original.Pages.Count + " pages."
, EventLogEntryType.Information);


//Loop thu each page
for (int i = 1; i <= original.Pages.Count; i++)
{
PdfDocument pageTemp = new PdfDocument();
PdfPageBase page;

string pageId = i.ToString();

string pathHeader = tempPath + @"\" + f.Name + "-" + pageId + "-Header.bmp";
string pathBarcode = tempPath + @"\" + f.Name + "-" + pageId + "-BarCode.bmp";
string pathBarcode2 = tempPath + @"\" + f.Name + "-" + pageId + "-BarCode2.bmp";
string pathPage = tempPath + @"\" + f.Name + "-" + pageId + ".bmp";

pageTemp.PageSettings.Orientation = PdfPageOrientation.Portrait;

page = pageTemp.Pages.Add(original.Pages[i - 1].Size, new Spire.Pdf.Graphics.PdfMargins(0));
original.Pages[i - 1].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
Image image = pageTemp.SaveAsImage(0);
image.Save(pathPage);

//Other logic that does not modify pdfToSave...

pdfToSave.InsertPage(pageTemp, page);

pdfToSave.SaveToFile(outputPdfPath + @"\" + strWO + ".pdf");

MCIA
 
Posts: 1
Joined: Fri Aug 31, 2018 7:18 pm

Wed Oct 09, 2019 3:02 am

Hi,

Thanks for your inquiry.
I made an initial test with the latest Spire.PDF(Spire.PDF Pack(Hot Fix) Version:5.9.16) but didn't reproduce your issue. If you were using the old version, I suggest you use the latest one and try again.
If the issue still exists, since I didn't find the attached Pdf files here, could you please upload them here again or send to us([email protected]) via email so that we could solve your issue quickly?

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Thu Oct 10, 2019 6:09 am

Hi,

Thanks for your information via email.
I have reproduced your issue and logged it into our bug tacking system. Once there is any progress, we will inform you.
Sorry for the inconvenience caused.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Tue Oct 22, 2019 3:09 am

Hi,

Hope you are doing well.
After further investigation, we found that if you exchange the page height and page width while creating the page template, the result could just be the one you want. I have attached the result Pdf file and image here, please check them. And below is my code for your reference.

Code: Select all
            PdfDocument original = new PdfDocument();
            PdfDocument pdfToSave = new PdfDocument();

            original.LoadFromFile(@"……\Feeder.pdf", FileFormat.PDF);

            for (int i = 1; i <= original.Pages.Count; i++)
            {
                PdfDocument pageTemp = new PdfDocument();
                PdfPageBase page;

                string pageId = i.ToString();
                string pathPage = @"image" + pageId + ".bmp";

                //Exchange the page height and page width while creating the template.
                page = pageTemp.Pages.Add(new SizeF(original.Pages[i - 1].Size.Height,original.Pages[i - 1].Size.Width), new PdfMargins(0));

                original.Pages[i - 1].CreateTemplate().Draw(page, new PointF(0, 0));
                Image image = pageTemp.SaveAsImage(0);
                image.Save(pathPage, ImageFormat.Bmp);
                pdfToSave.InsertPage(pageTemp, page);
            }
            pdfToSave.SaveToFile("result.pdf");


Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.PDF

cron