Page Rotation

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Page Rotation

Post by glima » Mon Nov 06, 2017 3:38 pm

Is there an easy way to correct a document or page that has been rotated?

Some of our client get PDF’s scanned landscape but the page rotation has been set to R270. This cause errors in gathering coordinate information and adding text to the document

In this particular case the file is 11.0 x 8.5 rotated 270. For proper manipulation we would need 8.5 x 11.0 rotated 0.

User avatar
Sasha - Tracker Dev Team
User
Posts: 4888
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Page Rotation

Post by Sasha - Tracker Dev Team » Mon Nov 06, 2017 3:57 pm

Hello glima,

You can get/set the document pages' rotation values with this property:
http://sdkhelp.tracker-software.com/vie ... e_Rotation

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Re: Page Rotation

Post by glima » Mon Nov 06, 2017 5:21 pm

This function sets the page rotation but does not orient the data on the page. Now when we view the file, the data is rotated.

We can use the printer driver to print the document and the orientation is correct but this takes a long time

User avatar
Sasha - Tracker Dev Team
User
Posts: 4888
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Page Rotation

Post by Sasha - Tracker Dev Team » Tue Nov 07, 2017 8:07 am

Hello glima,

It's still not very clear what you are doing and what do you want to achieve - please describe more thoroughly and then we will advice further.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Re: Page Rotation

Post by glima » Tue Nov 07, 2017 2:33 pm

Some our clients get documents scanned on a scanner that feeds the paper on the 11.0" side. These documents are then saved in the PDF with a page size of 11.0 x 8.5. They also set the rotation to 270 degrees. When printed or displayed the document is in the correct orientation 8.5 x 11.0. The issue is that when we add text or images to that document the coordinates are based on the 11.0 x 8.5.

Setting the Page rotation to 0 just makes the document display in its 11.0 x 8.5

I am attaching several documents outlining the issue

Test Doc - Original - This is the original document. It is 11.0 x 8.5 with a page rotation of 270
Test Doc - Stamped - This is the original document stamped with text watermarks.
Test Doc - Printed then Stamped - We print the original document using Viewer where we draw the to an image and then Draw the image to PDF Printer using our own controller. By printing the document the orientation is correct so the stamp is in the proper place (Top Left Corner)
Test Doc - Page Rotation 0 - This document show what happens when we set the page rotation to zero (0) and then stamp the document.

The "Test Doc - Printed and Stamped" is what we need. The printing takes about 6 seconds for a 4 pages document (on a VERY fast development machine) and creates a a document about 4 times the size.

1. Is there an easy way to print a PDF (We have PDF-XChange Pro)
2. Is there a way to fix these documents so the rotation is 0
Attachments
Test Doc - Original.pdf
(321.69 KiB) Downloaded 50 times
Test Doc - Stamped.PDF
(488.1 KiB) Downloaded 54 times
Test Doc - Printed then Stamped.PDF
(1.66 MiB) Downloaded 51 times
Test Doc - Page Rotation 0.PDF
(488.1 KiB) Downloaded 51 times

User avatar
Sasha - Tracker Dev Team
User
Posts: 4888
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Page Rotation

Post by Sasha - Tracker Dev Team » Tue Nov 07, 2017 2:41 pm

Hello glima,

Do you plan of using Core API or something else?

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Re: Page Rotation

Post by glima » Tue Nov 07, 2017 3:21 pm

We are currently using the Core API in a .NET environment but are open to other solutions.

I have played around with TransformPage function (we use this to scale documents if the customer wants) but can't get matrix correct for the rotation and change the document to be 8.5 x 11.0

User avatar
Sasha - Tracker Dev Team
User
Posts: 4888
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Page Rotation

Post by Sasha - Tracker Dev Team » Tue Nov 07, 2017 3:38 pm

Hello glima,

What are you using to add that "text stamps"? You have to specify a correct matrix if you are using Content Creator.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Re: Page Rotation

Post by glima » Tue Nov 07, 2017 4:00 pm

We are using both text and image watermarks based on the item being stamped. In the example we are using only text watermarks

User avatar
Sasha - Tracker Dev Team
User
Posts: 4888
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Page Rotation

Post by Sasha - Tracker Dev Team » Wed Nov 08, 2017 7:37 am

Hello glima,

These are not watermarks - please provide a code snippet on how you are adding them with the Core API.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Re: Page Rotation

Post by glima » Wed Nov 08, 2017 1:18 pm

I have a PDFWatermark Class that does different watermarking to PDF files. The SetLocation function sets the upper left point of the object we are stamping. Each item in the stamp is then placed based on the offset passed to the function


public void TextWatermark(string text, int page, Color color, Font font, double xoffset, double yoffset)
{
int[] wmRange = { 1, 1 };
GCHandle handle = GCHandle.Alloc(wmRange, GCHandleType.Pinned);
try
{
PDFXCp_Funcs.PXC_Watermark wm = new PDFXCp_Funcs.PXC_Watermark();

SizeF sz = GetPageSize(page);
sz.Width *= 72;
sz.Height *= 72;

SetLocation(page);

wm.m_XOffset = loc.XPos;
wm.m_YOffset = loc.YPos;
wm.m_XOffset += (xoffset * 72);
wm.m_YOffset += (yoffset * 72);

wm.m_Angle = loc.angle;
wm.m_Opacity = 255;

wm.m_FColor = SetColor(color);
wm.m_Text = new short[256];
PDFXCp_Funcs.StringToShortArr(text, wm.m_Text);

wm.m_FontName = new short[64];
PDFXCp_Funcs.StringToShortArr(font.Name, wm.m_FontName);
wm.m_FontSize = System.Convert.ToInt32(font.Size);
if (font.Bold)
wm.m_FontWeight = System.Convert.ToInt32(700);
else
wm.m_FontWeight = System.Convert.ToInt32(400);

if (font.Italic)
wm.m_bItalic = 1;
else
wm.m_bItalic = 0;

wm.m_LineWidth = System.Convert.ToInt32(1000);
wm.m_Size = (int)System.Runtime.InteropServices.Marshal.SizeOf(wm);
wm.m_Mode = PDFXCp_Funcs.PXC_TextRenderingMode.TextRenderingMode_Fill;
wm.m_Type = PDFXCp_Funcs.PXC_WaterType.WaterType_Text;
wm.m_PlaceOrder = PDFXCp_Funcs.PXC_WaterPlaceOrder.PlaceOrder_Foreground;
wm.m_PlaceType = PDFXCp_Funcs.PXC_WaterPlaceType.PlaceType_Range;

wm.m_NumRanges = 1;
wmRange[0] = page;
wmRange[1] = page;
wm.m_Range = handle.AddrOfPinnedObject();

int res = PDFXCp_Funcs.PXCp_AddWatermark(this.PDFHandle, ref wm);
}

catch (Exception ex)
{
MessageBox.Show(ex.Message, "Bates Page Watermark Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

finally
{
if (handle.IsAllocated)
handle.Free();
}
}


I found a solution that works with itextsharp but don't want to license the product for just this functionality. We have been using your products since 2004 and are very familiar with the functionality

public bool Rotate(string inputFile, string outputFile)
{
bool retval = false;
PdfReader reader = new PdfReader(inputFile);
int pageCount = reader.NumberOfPages;

// Check first page only for performance reasons. These rotated files are typically from scanners that scan on the long side of a page.
if (pageCount > 0 && reader.GetPageRotation(1) != 0)
{
Document inputDoc = new Document(reader.GetPageSizeWithRotation(1));
retval = true;
using (FileStream fs = new FileStream(outputFile, FileMode.Create))
{
PdfWriter writer = PdfWriter.GetInstance(inputDoc, fs);
inputDoc.Open();
PdfContentByte cb = writer.DirectContent;
Rectangle newPageSize = null;
for (int i = 1; i <= pageCount; i++)
{
PdfImportedPage page = writer.GetImportedPage(reader, i);
var pageSize = reader.GetPageSizeWithRotation(i);
switch (pageSize.Rotation)
{
case 0:
newPageSize = new Rectangle(pageSize.Height, pageSize.Width, 0);
inputDoc.SetPageSize(newPageSize);
inputDoc.NewPage();
cb.AddTemplate(page, 1f, 0, 0, 1f, 0, 0);
break;

case 90:
newPageSize = new Rectangle(pageSize.Width, pageSize.Height, 0);
inputDoc.SetPageSize(newPageSize);
inputDoc.NewPage();
cb.AddTemplate(page, 0, -1f, 1f, 0, 0, newPageSize.Height);
break;

case 180:
newPageSize = new Rectangle(pageSize.Height, pageSize.Width, 0);
inputDoc.SetPageSize(newPageSize);
inputDoc.NewPage();
cb.AddTemplate(page, -1f, 0, 0, -1f, newPageSize.Width, newPageSize.Height);
break;

case 270:
newPageSize = new Rectangle(pageSize.Width, pageSize.Height, 0);
inputDoc.SetPageSize(newPageSize);
inputDoc.NewPage();
cb.AddTemplate(page, 0, 1f, -1f, 0, newPageSize.Width, 0);
break;

default:
reader.Close();
inputDoc.Close();
return (false);
}
}
inputDoc.Close();
}
}
reader.Close();
return (retval);
}

User avatar
Sasha - Tracker Dev Team
User
Posts: 4888
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Page Rotation

Post by Sasha - Tracker Dev Team » Thu Nov 09, 2017 10:31 am

Hello glima,

This code is deprecated and is not Core API related. If you would use the Core API functionality to output the text on page then you can use the IPXC_Document::PlaceWatermark method. Or the ShowTextBlock/Line methods with needed matrices specified for the ContentCreator.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

glima
User
Posts: 84
Joined: Mon Sep 20, 2004 4:27 pm
Location: Phoenix, AZ

Re: Page Rotation

Post by glima » Thu Nov 16, 2017 5:10 pm

I am using C# and have created wrappers, since there is was not a Core API at the time. Is there any documentation for the Core API in a C# environment? Are there any examples?

User avatar
Sasha - Tracker Dev Team
User
Posts: 4888
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Page Rotation

Post by Sasha - Tracker Dev Team » Sat Nov 18, 2017 6:46 am

Hello glima,

You can find some samples here:
https://github.com/tracker-software
Also, check out the SDK help wiki:
http://sdkhelp.tracker-software.com
And the biggest sample storage are these forums, both Core API and Editor SDK (as the Editor SDK also often uses the IPXC level). So use forum search and I'm sure that you will find what you need.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply