Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Friday, July 10, 2020 10:41:05 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


I have a PDF document and Web Annotations XML file. I'm burning that XML to the PDF file and saving that using raster codecs. This is working fine. However If I rotate the PDF file by 90 degree and rotate the annotation container by 90 degree and burn XML file to PDF. It is not getting rendered. Here is the code I used.

Code:

using RasterCodecs rotcodecs = new RasterCodecs();
rotcodecs.Options.Load.Name = $"anything.pdf";
var rotoriginalImage = rotcodecs.Load(files[0]);
var rotinfo = rotcodecs.GetInformation(files[0], true);

RasterImage rotfullFileImage = null;

var rotannCodecs = new AnnCodecs();
var rotannContainer = new AnnContainer();
var renderingEngine = new AnnDrawRenderingEngine();
for (int j = 1; j <= rotoriginalImage.PageCount; j++)
{
    RasterImage image = rotcodecs.Load(files[0], rotinfo.BitsPerPixel, CodecsLoadByteOrder.BgrOrGrayOrRomm, j, j);
    rotannContainer = rotannCodecs.Load(annotationFile, j);

    if (rotfullFileImage is null)
    {
        rotfullFileImage = rotannContainer is null ? image : renderingEngine.RenderOnImage(rotannContainer, image);
    }
    else
    {
        rotfullFileImage.AddPage(rotannContainer is null ? image : renderingEngine.RenderOnImage(rotannContainer, image));
    }
}

rotcodecs.Save(rotfullFileImage ?? rotoriginalImage, @$"{currentPath}\Image To Pdf\beforerotate.pdf", RasterImageFormat.RasPdfLzw, 0, 1, rotoriginalImage.PageCount, 1, CodecsSavePageMode.Append);

rotfullFileImage = null;

for (int j = 1; j <= rotoriginalImage.PageCount; j++)
{
    RasterImage image = rotcodecs.Load(files[0], rotinfo.BitsPerPixel, CodecsLoadByteOrder.BgrOrGrayOrRomm, j, j);

    // Rotate the image by 90 degrees 
    RotateCommand lowcommand = new RotateCommand();
    lowcommand.Angle = 90 * 100;
    lowcommand.FillColor = new RasterColor(255, 255, 255);
    lowcommand.Flags = RotateCommandFlags.Resize | RotateCommandFlags.Bicubic;
    lowcommand.Run(image);

    if (rotfullFileImage is null)
    {
        rotfullFileImage = image;
    }
    else
    {
        rotfullFileImage.AddPage(image);
    }
}

rotcodecs.Save(rotfullFileImage ?? rotoriginalImage, @$"{currentPath}\Image To Pdf\afterrotate.pdf", RasterImageFormat.RasPdfLzw, 0, 1, rotoriginalImage.PageCount, 1, CodecsSavePageMode.Append);

rotannContainer.Rotate(90);
rotannCodecs.Save(@$"{currentPath}\Image To Pdf\4-42-90.xml", rotannContainer, AnnFormat.Annotations, 1);

rotfullFileImage = null;

for (int j = 1; j <= rotoriginalImage.PageCount; j++)
{
    RasterImage image = rotcodecs.Load(@$"{currentPath}\Image To Pdf\afterrotate.pdf", rotinfo.BitsPerPixel, CodecsLoadByteOrder.BgrOrGrayOrRomm, j, j);
    rotannContainer = rotannCodecs.Load(@$"{currentPath}\Image To Pdf\4-42-90.xml", j);

    if (rotfullFileImage is null)
    {
        rotfullFileImage = rotannContainer is null ? image : renderingEngine.RenderOnImage(rotannContainer, image);
    }
    else
    {
        rotfullFileImage.AddPage(rotannContainer is null ? image : renderingEngine.RenderOnImage(rotannContainer, image));
    }
}

rotcodecs.Save(rotfullFileImage ?? rotoriginalImage, @$"{currentPath}\Image To Pdf\afterrotatewithann.pdf", RasterImageFormat.RasPdfLzw, 0, 1, rotoriginalImage.PageCount, 1, CodecsSavePageMode.Append);



Note that I have done that in three steps in this example. Since my web app process it in three steps.

1. Document will be loaded in viewer with annotations xml.
2. Document rotate will be triggered in viewer and server will rotate the document and also annotations by given angle. And both will be stored separately.
3. Now if the rotated document is loaded in viewer with rotated annotation, it is loading in viewer.
4. Now I'm printing the document with annotation. Server will burn the rotated annotation with rotated document. Here annotation is not shown position is mismatched.

Please assist on what I'm doing wrong.

File Attachment(s):
4-42.txt (5kb) downloaded 14 time(s).
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Friday, July 10, 2020 12:40:29 PM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


I figured out the issue. It got resolved after adding the below code:

Code:

var height = image.ImageHeight * (720 / (double)image.YResolution);
var width = image.ImageWidth * (720 / (double)image.XResolution);
annContainer.Size = new LeadSizeD(width, height);
annContainer.Mapper.MapResolutions(image.XResolution, image.YResolution, image.XResolution, image.YResolution);


 
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.077 seconds.