Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML tags removed #177

Open
dupuisdavid opened this issue Jun 8, 2023 · 1 comment
Open

HTML tags removed #177

dupuisdavid opened this issue Jun 8, 2023 · 1 comment

Comments

@dupuisdavid
Copy link

dupuisdavid commented Jun 8, 2023

Hi,

I notice that after several generations of pdf from a file picker, the generated PDF loses all HTML formatting.
The table layout is completely skipped...
Here is my C# code :

`try {

StorageFile htmlFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/index.html"));

            var converter = new BasicConverter(new PdfTools());
            var htmlContent = File.ReadAllText(htmlFile.Path);

            var doc = new HtmlToPdfDocument()
            {
                GlobalSettings = {
                    ColorMode = ColorMode.Color,
                    Orientation = Orientation.Portrait,
                    PaperSize = PaperKind.A4
                },
                Objects = {
                    new ObjectSettings() {
                        PagesCount = true,
                        HtmlContent = htmlContent,
                        WebSettings = { DefaultEncoding = "utf-8"}
                    }
                }
            };

            var savePicker = new Windows.Storage.Pickers.FileSavePicker();
            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.ComputerFolder;
            savePicker.FileTypeChoices.Add("PDF Files", new List<string> { ".pdf", ".PDF" });
            savePicker.SuggestedFileName = "Devis.pdf";

            StorageFile newFile = await savePicker.PickSaveFileAsync();

            byte[] bytes = converter.Convert(doc);
            await FileManager.WriteFileAsync(newFile.Path, bytes);

            doc = null;
        }
        catch (Exception e)
        {
            Debug.WriteLine(e);
        }`

Here is my HTML file :

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>CodePen - Zigzag Table</title><style type="text/css">h1{color:#c00;font-family:sans-serif;font-size:2em;margin-bottom:0}table{width: 100%; font-family:sans-serif}table td,table th{padding:.25em .5em;text-align:left}table td:nth-child(2),table th:nth-child(2){text-align:right}table td{background-color:#eee}table th{background-color:#009;color:#fff}.zigzag{border-collapse:separate;border-spacing:.25em 1em}.zigzag tbody tr:nth-child(odd){transform:rotate(2deg)}.zigzag tbody tr:nth-child(even),.zigzag thead tr{transform:rotate(-2deg)}</style></head><body><h1>Top England Goal Scorers AAA</h1><table class="zigzag"><thead><tr><th class="header">Player</th><th class="header">Goals</th><th class="header">First</th><th class="header">Latest</th></tr></thead><tbody><tr><td>Wayne Rooney</td><td>53</td><td>06 Sep 2003</td><td>27 Jun 2016</td></tr><tr><td>Bobby Charlton</td><td>49</td><td>19 Apr 1958</td><td>20 May 1970</td></tr><tr><td>Gary Lineker</td><td>48</td><td>26 Mar 1985</td><td>29 Apr 1992</td></tr><tr><td>Jimmy Greaves</td><td>44</td><td>17 May 1959</td><td>24 May 1967</td></tr><tr><td>Michael Owen</td><td>40</td><td>27 May 1998</td><td>12 Sep 2007</td></tr><tr><td>Alan Shearer</td><td>30</td><td>19 Feb 1992</td><td>20 Jun 2000</td></tr><tr><td>Tom Finney</td><td>30</td><td>28 Sep 1946</td><td>04 Oct 1958</td></tr><tr><td>Nat Lofthouse</td><td>30</td><td>22 Nov 1950</td><td>22 Oct 1958</td></tr><tr><td>Vivian Woodward</td><td>29</td><td>14 Feb 1903</td><td>13 Mar 1911</td></tr><tr><td>Frank Lampard</td><td>29</td><td>20 Aug 2003</td><td>29 May 2013</td></tr></tbody></table></body></html>

Thanks

@dupuisdavid
Copy link
Author

Please note that I used the lib in an UWP app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant