Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

SharpPDF PDF runtime generator

Discussion in 'External Tools' started by aesparza, Nov 22, 2016.

  1. aesparza

    aesparza

    Joined:
    Apr 4, 2016
    Posts:
    28
    Hi!
    I am using SharpPDF to runtime PDF generation. I'm using it on Windows. I found two problems:

    • I need to put an scaled image on a page. I'm using addImage.
    It doesn't scale the image but it cuts the image starting from upper-left corner with the size I would like to scale it to.
    How can I solve this? In MAC doesn't happen that.
    • I have a problem adding images to a PDF file with WINDOWS. The PDF doesnt show the images well (they are grated) when I open it with ADOBE READER. But, if I open it with another pdf reader, the images are well. How can I solve this problem? On the contrary, if I use SharpPDF in MAC, this problem doesnt exist, I need to use it on Windows.
    I have post both questions in the page of the lib inside SourceForge but I didn't get any answer.

    Could anybody help me with this please?
     
  2. burcinpak

    burcinpak

    Joined:
    Mar 6, 2018
    Posts:
    1
    Did you find a solution to this? I have the same problem. If I open it with another viewer and save as pdf again, acrobat opens it fine.
     
  3. aciusa

    aciusa

    Joined:
    Apr 19, 2016
    Posts:
    4
    if you are using the public unity conversion of sharp PDF then you need to make use of the new height field on Windows, in imageElement. This is read in getText when the PDF encoding takes place.


    internal imageElement(Byte[] myImage, int newCoordX, int newCoordY, int imageHeight, int imageWidth, int newImageHeight, int newImageWidth) //added newImg H/W to constructor
    {

    try
    {
    //_content = new byte[myImage.Length];
    _content = myImage;
    _height = imageHeight;
    _width = imageWidth;
    _newHeight = newImageHeight; //new code
    _newWidth = newImageWidth; //new code
    _coordX = newCoordX;
    _coordY = newCoordY;
    }
    catch (System.IO.FileNotFoundException ex)
    {
    throw new pdfImageNotFoundException("Immagine non trovata!", ex);
    }
    catch (System.IO.IOException ex)
    {
    throw new pdfImageIOException("Errore generale di IO sull'immagine ", ex);
    } finally {
    // if (tmpContent != null) {
    // tmpContent.Dispose();
    // tmpContent = null;
    // }
    // if (outStream != null) {
    // outStream.Close();
    // outStream = null;
    // }
    }
    }
     
  4. MerkSim

    MerkSim

    Joined:
    Mar 1, 2018
    Posts:
    9
    Great, Exactly what I was looking for!
    But where do you get the 2 extra values that you pass as arguments?
    thanks!
     
  5. aciusa

    aciusa

    Joined:
    Apr 19, 2016
    Posts:
    4
    The imageHeight and imageWidth are the pixel height and width of the source image, newImageHeight and newImageWidth are the target height of the image. The standard for relative size is 72 pixels per inch, so a standard sheet of paper is 612 X 792 (8.5* 72 X 11 * 72). Say you wanted the image to take up exactly 1/4 of the page, you would set newImageHeight to 396 (11/2*72) and newImageWidth to 306 (8.5/2*72). Sharp PDF does not account for margins, so I recommend calculating a 54 pixel margin (3/4 inch) when you are creating the algorithm to position your export elements.
     
    Last edited: Sep 14, 2018
  6. MerkSim

    MerkSim

    Joined:
    Mar 1, 2018
    Posts:
    9
    I used the same i.e imageHeight=newImageHeight , imageWidth=newImageWidth, because I wanted to have a high PPI (400) A4 page end result , so my image is 3072 by 3072. The result is the same as before: it still only opens in edge, while in chrome its completely blank and in acrobat reader it says "There was an error while reading this Stream"